LCOV - code coverage report
Current view: top level - svl/source/items - slstitm.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 45 120 37.5 %
Date: 2012-08-25 Functions: 15 26 57.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 170 14.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include <svl/slstitm.hxx>
      22                 :            : #include <svl/poolitem.hxx>
      23                 :            : #include <com/sun/star/uno/Any.hxx>
      24                 :            : #include <com/sun/star/uno/Sequence.hxx>
      25                 :            : #include <tools/stream.hxx>
      26                 :            : 
      27                 :            : // STATIC DATA -----------------------------------------------------------
      28                 :            : 
      29                 :            : DBG_NAME(SfxStringListItem)
      30                 :            : 
      31                 :            : // -----------------------------------------------------------------------
      32                 :            : 
      33 [ -  + ][ -  + ]:       4867 : TYPEINIT1_AUTOFACTORY(SfxStringListItem, SfxPoolItem);
                 [ #  # ]
      34                 :            : 
      35                 :            : class SfxImpStringList
      36                 :            : {
      37                 :            : public:
      38                 :            :     sal_uInt16  nRefCount;
      39                 :            :     std::vector<String> aList;
      40                 :            : 
      41                 :        598 :             SfxImpStringList() { nRefCount = 1; }
      42                 :            :             ~SfxImpStringList();
      43                 :            : };
      44                 :            : 
      45                 :            : //------------------------------------------------------------------------
      46                 :            : 
      47                 :        598 : SfxImpStringList::~SfxImpStringList()
      48                 :            : {
      49                 :            :     DBG_ASSERT(nRefCount!=0xffff,"ImpList already deleted");
      50                 :        598 :     nRefCount = 0xffff;
      51                 :        598 : }
      52                 :            : 
      53                 :            : // class SfxStringListItem -----------------------------------------------
      54                 :            : 
      55                 :          0 : SfxStringListItem::SfxStringListItem() :
      56                 :          0 :     pImp(NULL)
      57                 :            : {
      58                 :          0 : }
      59                 :            : 
      60                 :            : //------------------------------------------------------------------------
      61                 :            : 
      62                 :        598 : SfxStringListItem::SfxStringListItem( sal_uInt16 which, const std::vector<String>* pList ) :
      63                 :            :     SfxPoolItem( which ),
      64                 :        598 :     pImp(NULL)
      65                 :            : {
      66                 :            :     // PB: das Putten einer leeren Liste funktionierte nicht,
      67                 :            :     // deshalb habe ich hier die Abfrage nach dem Count auskommentiert
      68         [ -  + ]:        598 :     if( pList /*!!! && pList->Count() */ )
      69                 :            :     {
      70 [ #  # ][ #  # ]:          0 :         pImp = new SfxImpStringList;
      71                 :            : 
      72         [ #  # ]:          0 :         if (pImp)
      73         [ #  # ]:          0 :             pImp->aList = *pList;
      74                 :            :     }
      75                 :        598 : }
      76                 :            : 
      77                 :            : //------------------------------------------------------------------------
      78                 :            : 
      79                 :          0 : SfxStringListItem::SfxStringListItem( sal_uInt16 which, SvStream& rStream ) :
      80                 :            :     SfxPoolItem( which ),
      81                 :          0 :     pImp(NULL)
      82                 :            : {
      83                 :            :     //fdo#39428 SvStream no longer supports operator>>(long&)
      84                 :            :     sal_Int32 nEntryCount;
      85         [ #  # ]:          0 :     rStream >> nEntryCount;
      86                 :            : 
      87         [ #  # ]:          0 :     if( nEntryCount )
      88 [ #  # ][ #  # ]:          0 :         pImp = new SfxImpStringList;
      89                 :            : 
      90         [ #  # ]:          0 :     if (pImp)
      91                 :            :     {
      92                 :            :         long   i;
      93         [ #  # ]:          0 :         String  aStr;
      94         [ #  # ]:          0 :         for( i=0; i < nEntryCount; i++ )
      95                 :            :         {
      96 [ #  # ][ #  # ]:          0 :             aStr = readByteString(rStream);
      97         [ #  # ]:          0 :             pImp->aList.push_back(aStr);
      98         [ #  # ]:          0 :         }
      99                 :            :     }
     100                 :          0 : }
     101                 :            : 
     102                 :            : //------------------------------------------------------------------------
     103                 :            : 
     104                 :       1794 : SfxStringListItem::SfxStringListItem( const SfxStringListItem& rItem ) :
     105                 :            :     SfxPoolItem( rItem ),
     106                 :       1794 :     pImp(rItem.pImp)
     107                 :            : {
     108         [ +  - ]:       1794 :     if( pImp )
     109                 :            :     {
     110                 :            :         DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
     111                 :       1794 :         pImp->nRefCount++;
     112                 :            :     }
     113                 :       1794 : }
     114                 :            : 
     115                 :            : //------------------------------------------------------------------------
     116                 :            : 
     117                 :       2392 : SfxStringListItem::~SfxStringListItem()
     118                 :            : {
     119         [ +  - ]:       2392 :     if( pImp )
     120                 :            :     {
     121                 :            :         DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
     122         [ +  + ]:       2392 :         if( pImp->nRefCount > 1 )
     123                 :       1794 :             pImp->nRefCount--;
     124                 :            :         else
     125         [ +  - ]:        598 :             delete pImp;
     126                 :            :     }
     127         [ -  + ]:       4186 : }
     128                 :            : 
     129                 :            : //------------------------------------------------------------------------
     130                 :            : 
     131                 :          0 : std::vector<String>& SfxStringListItem::GetList()
     132                 :            : {
     133         [ #  # ]:          0 :     if( !pImp )
     134         [ #  # ]:          0 :         pImp = new SfxImpStringList;
     135                 :            :     DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
     136                 :          0 :     return pImp->aList;
     137                 :            : }
     138                 :            : 
     139                 :          0 : const std::vector<String>& SfxStringListItem::GetList () const
     140                 :            : {
     141                 :          0 :     return (const_cast< SfxStringListItem * >(this))->GetList();
     142                 :            : }
     143                 :            : 
     144                 :            : //------------------------------------------------------------------------
     145                 :            : 
     146                 :        242 : int SfxStringListItem::operator==( const SfxPoolItem& rItem ) const
     147                 :            : {
     148                 :            :     DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
     149                 :            : 
     150                 :        242 :     SfxStringListItem* pItem = (SfxStringListItem*)&rItem;
     151                 :            : 
     152                 :        242 :     return pImp == pItem->pImp;
     153                 :            : }
     154                 :            : 
     155                 :            : //------------------------------------------------------------------------
     156                 :            : 
     157                 :          0 : SfxItemPresentation SfxStringListItem::GetPresentation
     158                 :            : (
     159                 :            :     SfxItemPresentation     /*ePresentation*/,
     160                 :            :     SfxMapUnit              /*eCoreMetric*/,
     161                 :            :     SfxMapUnit              /*ePresentationMetric*/,
     162                 :            :     XubString&              rText,
     163                 :            :     const IntlWrapper *
     164                 :            : )   const
     165                 :            : {
     166                 :          0 :     rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("(List)"));
     167                 :          0 :     return SFX_ITEM_PRESENTATION_NONE;
     168                 :            : }
     169                 :            : 
     170                 :            : //------------------------------------------------------------------------
     171                 :            : 
     172                 :       1794 : SfxPoolItem* SfxStringListItem::Clone( SfxItemPool *) const
     173                 :            : {
     174         [ +  - ]:       1794 :     return new SfxStringListItem( *this );
     175                 :            :     /*
     176                 :            :     if( pImp )
     177                 :            :         return new SfxStringListItem( Which(), &(pImp->aList) );
     178                 :            :     else
     179                 :            :         return new SfxStringListItem( Which(), NULL );
     180                 :            :     */
     181                 :            : 
     182                 :            : }
     183                 :            : 
     184                 :            : //------------------------------------------------------------------------
     185                 :            : 
     186                 :          0 : SfxPoolItem* SfxStringListItem::Create( SvStream & rStream, sal_uInt16 ) const
     187                 :            : {
     188         [ #  # ]:          0 :     return new SfxStringListItem( Which(), rStream );
     189                 :            : }
     190                 :            : 
     191                 :            : //------------------------------------------------------------------------
     192                 :            : 
     193                 :          0 : SvStream& SfxStringListItem::Store( SvStream & rStream, sal_uInt16 ) const
     194                 :            : {
     195         [ #  # ]:          0 :     if( !pImp )
     196                 :            :     {
     197                 :            :         //fdo#39428 SvStream no longer supports operator<<(long)
     198                 :          0 :         rStream << (sal_Int32) 0;
     199                 :          0 :         return rStream;
     200                 :            :     }
     201                 :            : 
     202                 :            :     DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
     203                 :            : 
     204                 :          0 :     sal_uInt32 nCount = pImp->aList.size();
     205                 :          0 :     rStream << nCount;
     206                 :            : 
     207         [ #  # ]:          0 :     for( sal_uInt32 i=0; i < nCount; i++ )
     208         [ #  # ]:          0 :         writeByteString(rStream, pImp->aList[i]);
     209                 :            : 
     210                 :          0 :     return rStream;
     211                 :            : }
     212                 :            : 
     213                 :            : //------------------------------------------------------------------------
     214                 :            : 
     215                 :          0 : void SfxStringListItem::SetString( const XubString& rStr )
     216                 :            : {
     217                 :            :     DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0");
     218                 :            : 
     219 [ #  # ][ #  # ]:          0 :     if ( pImp && (pImp->nRefCount == 1) )
     220         [ #  # ]:          0 :         delete pImp;
     221                 :            :     else
     222         [ #  # ]:          0 :     if( pImp )
     223                 :          0 :         pImp->nRefCount--;
     224 [ #  # ][ #  # ]:          0 :     pImp = new SfxImpStringList;
     225                 :            : 
     226                 :          0 :     xub_StrLen nStart = 0;
     227                 :            :     xub_StrLen nDelimPos;
     228 [ #  # ][ #  # ]:          0 :     XubString aStr(convertLineEnd(rStr, LINEEND_CR));
                 [ #  # ]
     229         [ #  # ]:          0 :     do
     230                 :            :     {
     231         [ #  # ]:          0 :         nDelimPos = aStr.Search( _CR, nStart );
     232                 :            :         xub_StrLen nLen;
     233         [ #  # ]:          0 :         if ( nDelimPos == STRING_NOTFOUND )
     234                 :          0 :             nLen = 0xffff;
     235                 :            :         else
     236                 :          0 :             nLen = nDelimPos - nStart;
     237                 :            : 
     238                 :            :         // String gehoert der Liste
     239 [ #  # ][ #  # ]:          0 :         pImp->aList.push_back(aStr.Copy(nStart, nLen));
                 [ #  # ]
     240                 :            : 
     241                 :          0 :         nStart += nLen + 1 ;    // delimiter ueberspringen
     242                 :            :     } while( nDelimPos != STRING_NOTFOUND );
     243                 :            : 
     244                 :            :     // Kein Leerstring am Ende
     245 [ #  # ][ #  # ]:          0 :     if (!pImp->aList.empty() && !(pImp->aList.rbegin())->Len())
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     246 [ #  # ][ #  # ]:          0 :         pImp->aList.pop_back();
     247                 :          0 : }
     248                 :            : 
     249                 :            : //------------------------------------------------------------------------
     250                 :            : 
     251                 :          0 : XubString SfxStringListItem::GetString()
     252                 :            : {
     253         [ #  # ]:          0 :     XubString aStr;
     254         [ #  # ]:          0 :     if ( pImp )
     255                 :            :     {
     256                 :            :         DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
     257                 :            : 
     258                 :          0 :         std::vector<String>::iterator iter;
     259                 :          0 :         for (iter = pImp->aList.begin();;)
     260                 :            :         {
     261 [ #  # ][ #  # ]:          0 :             aStr += *iter;
     262         [ #  # ]:          0 :             ++iter;
     263                 :            : 
     264 [ #  # ][ #  # ]:          0 :             if (iter != pImp->aList.end())
     265         [ #  # ]:          0 :                 aStr += '\r';
     266                 :            :             else
     267                 :          0 :                 break;
     268                 :            :         }
     269                 :            :     }
     270 [ #  # ][ #  # ]:          0 :     return convertLineEnd(aStr, GetSystemLineEnd());
         [ #  # ][ #  # ]
     271                 :            : }
     272                 :            : 
     273                 :            : //------------------------------------------------------------------------
     274                 :            : 
     275                 :        598 : void SfxStringListItem::SetStringList( const com::sun::star::uno::Sequence< rtl::OUString >& rList )
     276                 :            : {
     277                 :            :     DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0");
     278                 :            : 
     279 [ -  + ][ #  # ]:        598 :     if ( pImp && (pImp->nRefCount == 1) )
     280         [ #  # ]:          0 :         delete pImp;
     281                 :            :     else
     282         [ -  + ]:        598 :     if( pImp )
     283                 :          0 :         pImp->nRefCount--;
     284         [ +  - ]:        598 :     pImp = new SfxImpStringList;
     285                 :            : 
     286         [ +  - ]:        598 :     if (pImp)
     287                 :            :     {
     288                 :            :         // String gehoert der Liste
     289         [ +  + ]:       2990 :         for ( sal_Int32 n = 0; n < rList.getLength(); n++ )
     290         [ +  - ]:       2392 :             pImp->aList.push_back(XubString(rList[n]));
     291                 :            :     }
     292                 :        598 : }
     293                 :            : 
     294                 :            : //----------------------------------------------------------------------------
     295                 :        598 : void SfxStringListItem::GetStringList( com::sun::star::uno::Sequence< rtl::OUString >& rList ) const
     296                 :            : {
     297                 :        598 :     long nCount = pImp->aList.size();
     298                 :            : 
     299                 :        598 :     rList.realloc( nCount );
     300         [ +  + ]:       2990 :     for( long i=0; i < nCount; i++ )
     301         [ +  - ]:       2392 :         rList[i] = pImp->aList[i];
     302                 :        598 : }
     303                 :            : 
     304                 :            : //----------------------------------------------------------------------------
     305                 :            : // virtual
     306                 :          0 : bool SfxStringListItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
     307                 :            : {
     308         [ #  # ]:          0 :     com::sun::star::uno::Sequence< rtl::OUString > aValue;
     309 [ #  # ][ #  # ]:          0 :     if ( rVal >>= aValue )
     310                 :            :     {
     311         [ #  # ]:          0 :         SetStringList( aValue );
     312                 :          0 :         return true;
     313                 :            :     }
     314                 :            : 
     315                 :            :     OSL_FAIL( "SfxStringListItem::PutValue - Wrong type!" );
     316         [ #  # ]:          0 :     return false;
     317                 :            : }
     318                 :            : 
     319                 :            : //----------------------------------------------------------------------------
     320                 :            : // virtual
     321                 :        598 : bool SfxStringListItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
     322                 :            : {
     323                 :            :     // GetString() is not const!!!
     324                 :        598 :     SfxStringListItem* pThis = const_cast< SfxStringListItem * >( this );
     325                 :            : 
     326         [ +  - ]:        598 :     com::sun::star::uno::Sequence< rtl::OUString > aStringList;
     327         [ +  - ]:        598 :     pThis->GetStringList( aStringList );
     328         [ +  - ]:        598 :     rVal = ::com::sun::star::uno::makeAny( aStringList );
     329         [ +  - ]:        598 :     return true;
     330                 :            : }
     331                 :            : 
     332                 :            : 
     333                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10