LCOV - code coverage report
Current view: top level - svl/source/items - aeitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 92 57.6 %
Date: 2012-08-25 Functions: 19 28 67.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 40 112 35.7 %

           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 <tools/string.hxx>
      22                 :            : 
      23                 :            : #include <svl/aeitem.hxx>
      24                 :            : #include <vector>
      25                 :            : 
      26                 :            : // STATIC DATA -----------------------------------------------------------
      27                 :            : 
      28                 :            : DBG_NAME(SfxAllEnumItem)
      29                 :            : 
      30 [ -  + ][ +  + ]:      23693 : TYPEINIT1_AUTOFACTORY(SfxAllEnumItem, SfxEnumItem)
                 [ +  - ]
      31                 :            : 
      32                 :            : // -----------------------------------------------------------------------
      33                 :            : 
      34                 :       9662 : struct SfxAllEnumValue_Impl
      35                 :            : {
      36                 :            :     sal_uInt16 nValue;
      37                 :            :     rtl::OUString aText;
      38                 :            : };
      39                 :            : 
      40                 :       4834 : class SfxAllEnumValueArr : public std::vector<SfxAllEnumValue_Impl*>
      41                 :            : {
      42                 :            : public:
      43                 :       4828 :     ~SfxAllEnumValueArr()
      44                 :       4828 :     {
      45 [ +  - ][ +  - ]:       9656 :         for( const_iterator it = begin(); it != end(); ++it )
                 [ +  + ]
      46         [ +  - ]:       4828 :             delete *it;
      47                 :       4828 :     }
      48                 :            : };
      49                 :            : 
      50                 :            : // -----------------------------------------------------------------------
      51                 :            : 
      52                 :       1407 : SfxAllEnumItem::SfxAllEnumItem() :
      53                 :            :     SfxEnumItem(),
      54                 :            :     pValues( 0 ),
      55                 :       1407 :     pDisabledValues( 0 )
      56                 :            : {
      57                 :       1407 : }
      58                 :            : 
      59                 :            : // -----------------------------------------------------------------------
      60                 :            : 
      61                 :       1478 : SfxAllEnumItem::SfxAllEnumItem(sal_uInt16 which, sal_uInt16 nVal):
      62                 :            :     SfxEnumItem(which, nVal),
      63                 :            :     pValues( 0 ),
      64                 :       1478 :     pDisabledValues( 0 )
      65                 :            : {
      66                 :            :     DBG_CTOR(SfxAllEnumItem, 0);
      67         [ +  - ]:       1478 :     InsertValue( nVal );
      68                 :       1478 : }
      69                 :            : 
      70                 :            : // -----------------------------------------------------------------------
      71                 :            : 
      72                 :          0 : SfxAllEnumItem::SfxAllEnumItem( sal_uInt16 which, SvStream &rStream ):
      73                 :            :     SfxEnumItem(which, rStream),
      74                 :            :     pValues( 0 ),
      75                 :          0 :     pDisabledValues( 0 )
      76                 :            : {
      77                 :            :     DBG_CTOR(SfxAllEnumItem, 0);
      78         [ #  # ]:          0 :     InsertValue( GetValue() );
      79                 :          0 : }
      80                 :            : 
      81                 :            : // -----------------------------------------------------------------------
      82                 :            : 
      83                 :            : 
      84                 :       1198 : SfxAllEnumItem::SfxAllEnumItem(sal_uInt16 which):
      85                 :            :     SfxEnumItem(which, 0),
      86                 :            :     pValues( 0 ),
      87                 :       1198 :     pDisabledValues( 0 )
      88                 :            : {
      89                 :            :     DBG_CTOR(SfxAllEnumItem, 0);
      90                 :       1198 : }
      91                 :            : 
      92                 :            : 
      93                 :            : // -----------------------------------------------------------------------
      94                 :            : 
      95                 :       3356 : SfxAllEnumItem::SfxAllEnumItem(const SfxAllEnumItem &rCopy):
      96                 :            :     SfxEnumItem(rCopy),
      97                 :            :     pValues(0),
      98                 :       3356 :     pDisabledValues( 0 )
      99                 :            : {
     100                 :            :     DBG_CTOR(SfxAllEnumItem, 0);
     101         [ -  + ]:       3356 :     if ( !rCopy.pValues )
     102                 :       3356 :         return;
     103                 :            : 
     104 [ +  - ][ +  - ]:       3356 :     pValues = new SfxAllEnumValueArr;
     105                 :            : 
     106         [ +  + ]:       6712 :     for ( sal_uInt16 nPos = 0; nPos < rCopy.pValues->size(); ++nPos )
     107                 :            :     {
     108         [ +  - ]:       3356 :         SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
     109                 :       3356 :         pVal->nValue = (*rCopy.pValues)[nPos]->nValue;
     110                 :       3356 :         pVal->aText = (*rCopy.pValues)[nPos]->aText;
     111 [ +  - ][ +  - ]:       3356 :         pValues->insert( pValues->begin() + nPos, pVal );
     112                 :            :     }
     113                 :            : 
     114         [ +  - ]:       3356 :     if( rCopy.pDisabledValues )
     115                 :            :     {
     116 [ +  - ][ +  - ]:       3356 :         pDisabledValues = new std::vector<sal_uInt16>( *(rCopy.pDisabledValues) );
     117                 :            :     }
     118                 :            : }
     119                 :            : 
     120                 :            : // -----------------------------------------------------------------------
     121                 :            : 
     122                 :       7145 : SfxAllEnumItem::~SfxAllEnumItem()
     123                 :            : {
     124                 :            :     DBG_DTOR(SfxAllEnumItem, 0);
     125 [ +  + ][ +  - ]:       7145 :     delete pValues;
     126         [ +  + ]:       7145 :     delete pDisabledValues;
     127         [ -  + ]:      12812 : }
     128                 :            : 
     129                 :            : // -----------------------------------------------------------------------
     130                 :            : 
     131                 :          0 : sal_uInt16 SfxAllEnumItem::GetValueCount() const
     132                 :            : {
     133                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     134         [ #  # ]:          0 :     return pValues ? pValues->size() : 0;
     135                 :            : }
     136                 :            : 
     137                 :            : // -----------------------------------------------------------------------
     138                 :            : 
     139                 :          0 : rtl::OUString SfxAllEnumItem::GetValueTextByPos( sal_uInt16 nPos ) const
     140                 :            : {
     141                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     142                 :            :     DBG_ASSERT( pValues && nPos < pValues->size(), "enum overflow" );
     143                 :          0 :     return (*pValues)[nPos]->aText;
     144                 :            : }
     145                 :            : 
     146                 :            : // -----------------------------------------------------------------------
     147                 :            : 
     148                 :          0 : sal_uInt16 SfxAllEnumItem::GetValueByPos( sal_uInt16 nPos ) const
     149                 :            : {
     150                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     151                 :            :     DBG_ASSERT( pValues && nPos < pValues->size(), "enum overflow" );
     152                 :          0 :     return (*pValues)[nPos]->nValue;
     153                 :            : }
     154                 :            : 
     155                 :            : // -----------------------------------------------------------------------
     156                 :            : 
     157                 :       3356 : SfxPoolItem* SfxAllEnumItem::Clone( SfxItemPool * ) const
     158                 :            : {
     159                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     160         [ +  - ]:       3356 :     return new SfxAllEnumItem(*this);
     161                 :            : }
     162                 :            : 
     163                 :            : // -----------------------------------------------------------------------
     164                 :            : 
     165                 :          0 : SfxPoolItem* SfxAllEnumItem::Create( SvStream & rStream, sal_uInt16 ) const
     166                 :            : {
     167                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     168         [ #  # ]:          0 :     return new SfxAllEnumItem( Which(), rStream );
     169                 :            : }
     170                 :            : 
     171                 :            : 
     172                 :            : // -----------------------------------------------------------------------
     173                 :            : 
     174                 :       1478 : sal_uInt16 SfxAllEnumItem::_GetPosByValue( sal_uInt16 nVal ) const
     175                 :            : 
     176                 :            : /*  [Beschreibung]
     177                 :            : 
     178                 :            :     Im Ggs. zu <SfxEnumItemInterface::GetPosByValue(sal_uInt16)const> liefert
     179                 :            :     diese interne Methode bei nicht vorhandenen Values die Position,
     180                 :            :     an der der Wert liegen w"urde.
     181                 :            : */
     182                 :            : 
     183                 :            : {
     184                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     185                 :            : 
     186         [ -  + ]:       1478 :     if ( !pValues )
     187                 :          0 :         return 0;
     188                 :            : 
     189                 :            :     //!O: binaere Suche oder SortArray verwenden
     190                 :            :     sal_uInt16 nPos;
     191         [ -  + ]:       1478 :     for ( nPos = 0; nPos < pValues->size(); ++nPos )
     192         [ #  # ]:          0 :         if ( (*pValues)[nPos]->nValue >= nVal )
     193                 :          0 :             return nPos;
     194                 :       1478 :     return nPos;
     195                 :            : }
     196                 :            : 
     197                 :            : // -----------------------------------------------------------------------
     198                 :            : 
     199                 :          0 : sal_uInt16 SfxAllEnumItem::GetPosByValue( sal_uInt16 nValue ) const
     200                 :            : 
     201                 :            : /*  [Beschreibung]
     202                 :            : 
     203                 :            :     Liefert im Gegensatz zu <SfxEnumItemInterface::GetPosByValue(sal_uInt16)const>
     204                 :            :     immer nValue zur"uck, solange nicht mindestens ein Wert mit einer der
     205                 :            :     Methoden <SfxAllEnumItem::InsertValue()> eingef"ugt wurde.
     206                 :            : */
     207                 :            : 
     208                 :            : {
     209                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     210                 :            : 
     211 [ #  # ][ #  # ]:          0 :     if ( !pValues || pValues->empty() )
                 [ #  # ]
     212                 :          0 :         return nValue;
     213                 :            : 
     214                 :          0 :     return SfxEnumItem::GetPosByValue( nValue );
     215                 :            : }
     216                 :            : 
     217                 :            : // -----------------------------------------------------------------------
     218                 :            : 
     219                 :          0 : void SfxAllEnumItem::InsertValue( sal_uInt16 nValue, const rtl::OUString &rValue )
     220                 :            : {
     221                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     222         [ #  # ]:          0 :     SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
     223                 :          0 :     pVal->nValue = nValue;
     224                 :          0 :     pVal->aText = rValue;
     225         [ #  # ]:          0 :     if ( !pValues )
     226 [ #  # ][ #  # ]:          0 :         pValues = new SfxAllEnumValueArr;
     227 [ #  # ][ #  # ]:          0 :     else if ( GetPosByValue( nValue ) != USHRT_MAX )
     228                 :            :         // remove when exists
     229         [ #  # ]:          0 :         RemoveValue( nValue );
     230                 :            :     // then insert
     231 [ #  # ][ #  # ]:          0 :     pValues->insert( pValues->begin() + _GetPosByValue(nValue), pVal ); //! doppelte?!
                 [ #  # ]
     232                 :          0 : }
     233                 :            : 
     234                 :            : // -----------------------------------------------------------------------
     235                 :            : 
     236                 :       1478 : void SfxAllEnumItem::InsertValue( sal_uInt16 nValue )
     237                 :            : {
     238                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     239         [ +  - ]:       1478 :     SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
     240                 :       1478 :     pVal->nValue = nValue;
     241                 :       1478 :     pVal->aText = rtl::OUString::valueOf(static_cast<sal_Int32>(nValue));
     242         [ +  - ]:       1478 :     if ( !pValues )
     243 [ +  - ][ +  - ]:       1478 :         pValues = new SfxAllEnumValueArr;
     244                 :            : 
     245 [ +  - ][ +  - ]:       1478 :     pValues->insert( pValues->begin() + _GetPosByValue(nValue), pVal ); //! doppelte?!
                 [ +  - ]
     246                 :       1478 : }
     247                 :            : 
     248                 :       2956 : void SfxAllEnumItem::DisableValue( sal_uInt16 nValue )
     249                 :            : {
     250                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     251         [ +  + ]:       2956 :     if ( !pDisabledValues )
     252         [ +  - ]:       1478 :         pDisabledValues = new std::vector<sal_uInt16>;
     253                 :            : 
     254                 :       2956 :     pDisabledValues->push_back( nValue );
     255                 :       2956 : }
     256                 :            : 
     257                 :          0 : sal_Bool SfxAllEnumItem::IsEnabled( sal_uInt16 nValue ) const
     258                 :            : {
     259         [ #  # ]:          0 :     if ( pDisabledValues )
     260                 :            :     {
     261         [ #  # ]:          0 :         for ( size_t i=0; i<pDisabledValues->size(); i++ )
     262         [ #  # ]:          0 :             if ( (*pDisabledValues)[i] == nValue )
     263                 :          0 :                 return sal_False;
     264                 :            :     }
     265                 :            : 
     266                 :          0 :     return sal_True;
     267                 :            : }
     268                 :            : 
     269                 :            : // -----------------------------------------------------------------------
     270                 :            : 
     271                 :          0 : void SfxAllEnumItem::RemoveValue( sal_uInt16 nValue )
     272                 :            : {
     273                 :            :     DBG_CHKTHIS(SfxAllEnumItem, 0);
     274                 :          0 :     sal_uInt16 nPos = GetPosByValue(nValue);
     275                 :            :     DBG_ASSERT( nPos != USHRT_MAX, "removing value not in enum" );
     276 [ #  # ][ #  # ]:          0 :     pValues->erase( pValues->begin() + nPos );
     277                 :          0 : }
     278                 :            : 
     279                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10