LCOV - code coverage report
Current view: top level - comphelper/source/misc - sequenceashashmap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 122 73.8 %
Date: 2012-08-25 Functions: 14 17 82.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 54 154 35.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                 :            : #include <comphelper/sequenceashashmap.hxx>
      21                 :            : 
      22                 :            : 
      23                 :            : namespace comphelper{
      24                 :            : 
      25                 :            : namespace css = ::com::sun::star;
      26                 :            : 
      27                 :            : 
      28                 :     289242 : SequenceAsHashMap::SequenceAsHashMap()
      29                 :     289242 :     : SequenceAsHashMapBase()
      30                 :            : {
      31                 :     289242 : }
      32                 :            : 
      33                 :      21485 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any& aSource)
      34                 :            : {
      35         [ +  - ]:      21485 :     (*this) << aSource;
      36                 :      21485 : }
      37                 :            : 
      38                 :            : //-----------------------------------------------
      39                 :       5526 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource)
      40                 :            : {
      41         [ +  - ]:       5526 :     (*this) << lSource;
      42                 :       5526 : }
      43                 :            : 
      44                 :       9846 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
      45                 :            : {
      46         [ +  - ]:       9846 :     (*this) << lSource;
      47                 :       9846 : }
      48                 :            : 
      49                 :         20 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource)
      50                 :            : {
      51         [ +  - ]:         20 :     (*this) << lSource;
      52                 :         20 : }
      53                 :            : 
      54                 :     448856 : SequenceAsHashMap::~SequenceAsHashMap()
      55                 :            : {
      56                 :     448856 : }
      57                 :            : 
      58                 :      21493 : void SequenceAsHashMap::operator<<(const css::uno::Any& aSource)
      59                 :            : {
      60                 :            :     // An empty Any reset this instance!
      61         [ +  + ]:      21493 :     if (!aSource.hasValue())
      62                 :            :     {
      63         [ +  - ]:         26 :         clear();
      64                 :            :         return;
      65                 :            :     }
      66                 :            : 
      67         [ +  - ]:      21467 :     css::uno::Sequence< css::beans::NamedValue > lN;
      68 [ +  - ][ -  + ]:      21467 :     if (aSource >>= lN)
      69                 :            :     {
      70         [ #  # ]:          0 :         (*this) << lN;
      71                 :            :         return;
      72                 :            :     }
      73                 :            : 
      74         [ +  - ]:      21467 :     css::uno::Sequence< css::beans::PropertyValue > lP;
      75 [ +  - ][ +  + ]:      21467 :     if (aSource >>= lP)
      76                 :            :     {
      77         [ +  - ]:      21465 :         (*this) << lP;
      78                 :            :         return;
      79                 :            :     }
      80                 :            : 
      81                 :            :     throw css::beans::IllegalTypeException(
      82                 :            :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Any contains wrong type." )),
      83 [ +  - ][ +  - ]:      21493 :             css::uno::Reference< css::uno::XInterface >());
         [ +  - ][ +  - ]
      84                 :            : }
      85                 :            : 
      86                 :            : //-----------------------------------------------
      87                 :       5526 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::uno::Any >& lSource)
      88                 :            : {
      89                 :       5526 :     sal_Int32 c = lSource.getLength();
      90                 :       5526 :     sal_Int32 i = 0;
      91                 :            : 
      92         [ +  + ]:      21430 :     for (i=0; i<c; ++i)
      93                 :            :     {
      94                 :      15904 :         css::beans::PropertyValue lP;
      95 [ +  + ][ +  - ]:      15904 :         if (lSource[i] >>= lP)
      96                 :            :         {
      97         [ -  + ]:       3102 :             if (
           [ +  -  -  + ]
      98                 :       1551 :                 (lP.Name.isEmpty()) ||
      99                 :       1551 :                 (!lP.Value.hasValue())
     100                 :            :                )
     101                 :            :                 throw css::beans::IllegalTypeException(
     102                 :            :                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PropertyValue struct contains no usefull informations." )),
     103 [ #  # ][ #  # ]:          0 :                         css::uno::Reference< css::uno::XInterface >());
     104         [ +  - ]:       1551 :             (*this)[lP.Name] = lP.Value;
     105                 :       1551 :             continue;
     106                 :            :         }
     107                 :            : 
     108                 :      14353 :         css::beans::NamedValue lN;
     109 [ +  - ][ +  - ]:      14353 :         if (lSource[i] >>= lN)
     110                 :            :         {
     111         [ -  + ]:      28706 :             if (
           [ +  -  -  + ]
     112                 :      14353 :                 (lN.Name.isEmpty()) ||
     113                 :      14353 :                 (!lN.Value.hasValue())
     114                 :            :                )
     115                 :            :                 throw css::beans::IllegalTypeException(
     116                 :            :                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedValue struct contains no usefull informations." )),
     117 [ #  # ][ #  # ]:          0 :                         css::uno::Reference< css::uno::XInterface >());
     118         [ +  - ]:      14353 :             (*this)[lN.Name] = lN.Value;
     119                 :      14353 :             continue;
     120                 :            :         }
     121                 :            : 
     122                 :            :         // ignore VOID Any ... but reject wrong filled ones!
     123         [ #  # ]:          0 :         if (lSource[i].hasValue())
     124                 :            :             throw css::beans::IllegalTypeException(
     125                 :            :                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Any contains wrong type." )),
     126 [ #  # ][ #  # ]:          0 :                     css::uno::Reference< css::uno::XInterface >());
     127 [ +  - ][ -  + ]:      15904 :     }
     128                 :       5526 : }
     129                 :            : 
     130                 :      34735 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
     131                 :            : {
     132                 :      34735 :     clear();
     133                 :            : 
     134                 :      34735 :           sal_Int32                  c       = lSource.getLength();
     135                 :      34735 :     const css::beans::PropertyValue* pSource = lSource.getConstArray();
     136                 :            : 
     137         [ +  + ]:     415638 :     for (sal_Int32 i=0; i<c; ++i)
     138                 :     380903 :         (*this)[pSource[i].Name] = pSource[i].Value;
     139                 :      34735 : }
     140                 :            : 
     141                 :       9518 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::NamedValue >& lSource)
     142                 :            : {
     143                 :       9518 :     clear();
     144                 :            : 
     145                 :       9518 :           sal_Int32               c       = lSource.getLength();
     146                 :       9518 :     const css::beans::NamedValue* pSource = lSource.getConstArray();
     147                 :            : 
     148         [ +  + ]:      20187 :     for (sal_Int32 i=0; i<c; ++i)
     149                 :      10669 :         (*this)[pSource[i].Name] = pSource[i].Value;
     150                 :       9518 : }
     151                 :            : 
     152                 :      72050 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::PropertyValue >& lDestination) const
     153                 :            : {
     154                 :      72050 :     sal_Int32 c = (sal_Int32)size();
     155                 :      72050 :     lDestination.realloc(c);
     156                 :      72050 :     css::beans::PropertyValue* pDestination = lDestination.getArray();
     157                 :            : 
     158                 :      72050 :     sal_Int32 i = 0;
     159 [ +  + ][ +  - ]:     891002 :     for (const_iterator pThis  = begin();
     160         [ +  - ]:     445501 :                         pThis != end()  ;
     161                 :            :                       ++pThis           )
     162                 :            :     {
     163         [ +  - ]:     373451 :         pDestination[i].Name  = pThis->first ;
     164         [ +  - ]:     373451 :         pDestination[i].Value = pThis->second;
     165                 :     373451 :         ++i;
     166                 :            :     }
     167                 :      72050 : }
     168                 :            : 
     169                 :         60 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::NamedValue >& lDestination) const
     170                 :            : {
     171                 :         60 :     sal_Int32 c = (sal_Int32)size();
     172                 :         60 :     lDestination.realloc(c);
     173                 :         60 :     css::beans::NamedValue* pDestination = lDestination.getArray();
     174                 :            : 
     175                 :         60 :     sal_Int32 i = 0;
     176 [ +  + ][ +  - ]:        480 :     for (const_iterator pThis  = begin();
     177         [ +  - ]:        240 :                         pThis != end()  ;
     178                 :            :                       ++pThis           )
     179                 :            :     {
     180         [ +  - ]:        180 :         pDestination[i].Name  = pThis->first ;
     181         [ +  - ]:        180 :         pDestination[i].Value = pThis->second;
     182                 :        180 :         ++i;
     183                 :            :     }
     184                 :         60 : }
     185                 :            : 
     186                 :          0 : const css::uno::Any SequenceAsHashMap::getAsConstAny(::sal_Bool bAsPropertyValueList) const
     187                 :            : {
     188                 :          0 :     css::uno::Any aDestination;
     189         [ #  # ]:          0 :     if (bAsPropertyValueList)
     190 [ #  # ][ #  # ]:          0 :         aDestination = css::uno::makeAny(getAsConstPropertyValueList());
                 [ #  # ]
     191                 :            :     else
     192 [ #  # ][ #  # ]:          0 :         aDestination = css::uno::makeAny(getAsConstNamedValueList());
                 [ #  # ]
     193                 :          0 :     return aDestination;
     194                 :            : }
     195                 :            : 
     196                 :         60 : const css::uno::Sequence< css::beans::NamedValue > SequenceAsHashMap::getAsConstNamedValueList() const
     197                 :            : {
     198                 :         60 :     css::uno::Sequence< css::beans::NamedValue > lReturn;
     199         [ +  - ]:         60 :     (*this) >> lReturn;
     200                 :         60 :     return lReturn;
     201                 :            : }
     202                 :            : 
     203                 :      65495 : const css::uno::Sequence< css::beans::PropertyValue > SequenceAsHashMap::getAsConstPropertyValueList() const
     204                 :            : {
     205                 :      65495 :     css::uno::Sequence< css::beans::PropertyValue > lReturn;
     206         [ +  - ]:      65495 :     (*this) >> lReturn;
     207                 :      65495 :     return lReturn;
     208                 :            : }
     209                 :            : 
     210                 :          0 : sal_Bool SequenceAsHashMap::match(const SequenceAsHashMap& rCheck) const
     211                 :            : {
     212                 :          0 :     const_iterator pCheck;
     213 [ #  # ][ #  # ]:          0 :     for (  pCheck  = rCheck.begin();
     214         [ #  # ]:          0 :            pCheck != rCheck.end()  ;
     215                 :            :          ++pCheck                  )
     216                 :            :     {
     217         [ #  # ]:          0 :         const ::rtl::OUString& sCheckName  = pCheck->first;
     218         [ #  # ]:          0 :         const css::uno::Any&   aCheckValue = pCheck->second;
     219         [ #  # ]:          0 :               const_iterator   pFound      = find(sCheckName);
     220                 :            : 
     221 [ #  # ][ #  # ]:          0 :         if (pFound == end())
     222                 :          0 :             return sal_False;
     223                 :            : 
     224         [ #  # ]:          0 :         const css::uno::Any& aFoundValue = pFound->second;
     225         [ #  # ]:          0 :         if (aFoundValue != aCheckValue)
     226                 :          0 :             return sal_False;
     227                 :            :     }
     228                 :            : 
     229                 :          0 :     return sal_True;
     230                 :            : }
     231                 :            : 
     232                 :          0 : void SequenceAsHashMap::update(const SequenceAsHashMap& rUpdate)
     233                 :            : {
     234                 :          0 :     const_iterator pUpdate;
     235 [ #  # ][ #  # ]:          0 :     for (  pUpdate  = rUpdate.begin();
     236         [ #  # ]:          0 :            pUpdate != rUpdate.end()  ;
     237                 :            :          ++pUpdate                   )
     238                 :            :     {
     239         [ #  # ]:          0 :         const ::rtl::OUString& sName  = pUpdate->first;
     240         [ #  # ]:          0 :         const css::uno::Any&   aValue = pUpdate->second;
     241                 :            : 
     242         [ #  # ]:          0 :         (*this)[sName] = aValue;
     243                 :            :     }
     244                 :          0 : }
     245                 :            : 
     246                 :            : } // namespace comphelper
     247                 :            : 
     248                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10