LCOV - code coverage report
Current view: top level - comphelper/source/misc - sequenceashashmap.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 101 125 80.8 %
Date: 2015-06-13 12:38:46 Functions: 16 17 94.1 %
Legend: Lines: hit not hit

          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 <sal/config.h>
      21             : 
      22             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      23             : #include <comphelper/sequenceashashmap.hxx>
      24             : 
      25             : 
      26             : namespace comphelper{
      27             : 
      28     1659919 : SequenceAsHashMap::SequenceAsHashMap()
      29     1659919 :     : SequenceAsHashMapBase()
      30             : {
      31     1659919 : }
      32             : 
      33       35620 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any& aSource)
      34             : {
      35       35620 :     (*this) << aSource;
      36       35620 : }
      37             : 
      38             : 
      39        3293 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource)
      40             : {
      41        3293 :     (*this) << lSource;
      42        3293 : }
      43             : 
      44       59723 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
      45             : {
      46       59723 :     (*this) << lSource;
      47       59723 : }
      48             : 
      49        3525 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource)
      50             : {
      51        3525 :     (*this) << lSource;
      52        3525 : }
      53             : 
      54     3087325 : SequenceAsHashMap::~SequenceAsHashMap()
      55             : {
      56     3087325 : }
      57             : 
      58       35637 : void SequenceAsHashMap::operator<<(const css::uno::Any& aSource)
      59             : {
      60             :     // An empty Any reset this instance!
      61       35637 :     if (!aSource.hasValue())
      62             :     {
      63          14 :         clear();
      64          14 :         return;
      65             :     }
      66             : 
      67       35623 :     css::uno::Sequence< css::beans::NamedValue > lN;
      68       35623 :     if (aSource >>= lN)
      69             :     {
      70        1308 :         (*this) << lN;
      71        1308 :         return;
      72             :     }
      73             : 
      74       68630 :     css::uno::Sequence< css::beans::PropertyValue > lP;
      75       34315 :     if (aSource >>= lP)
      76             :     {
      77       34314 :         (*this) << lP;
      78       34314 :         return;
      79             :     }
      80             : 
      81             :     throw css::lang::IllegalArgumentException(
      82             :         "Any contains wrong type.", css::uno::Reference<css::uno::XInterface>(),
      83       35624 :         -1);
      84             : }
      85             : 
      86             : 
      87        3293 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::uno::Any >& lSource)
      88             : {
      89        3293 :     sal_Int32 c = lSource.getLength();
      90        3293 :     sal_Int32 i = 0;
      91             : 
      92       19699 :     for (i=0; i<c; ++i)
      93             :     {
      94       16406 :         css::beans::PropertyValue lP;
      95       16406 :         if (lSource[i] >>= lP)
      96             :         {
      97           0 :             if (
      98           0 :                 (lP.Name.isEmpty()) ||
      99           0 :                 (!lP.Value.hasValue())
     100             :                )
     101             :                 throw css::lang::IllegalArgumentException(
     102             :                     "PropertyValue struct contains no useful information.",
     103           0 :                     css::uno::Reference<css::uno::XInterface>(), -1);
     104           0 :             (*this)[lP.Name] = lP.Value;
     105           0 :             continue;
     106             :         }
     107             : 
     108       16406 :         css::beans::NamedValue lN;
     109       16406 :         if (lSource[i] >>= lN)
     110             :         {
     111       16406 :             if (
     112       32812 :                 (lN.Name.isEmpty()) ||
     113       16406 :                 (!lN.Value.hasValue())
     114             :                )
     115             :                 throw css::lang::IllegalArgumentException(
     116             :                     "NamedValue struct contains no useful information.",
     117           0 :                     css::uno::Reference<css::uno::XInterface>(), -1);
     118       16406 :             (*this)[lN.Name] = lN.Value;
     119       16406 :             continue;
     120             :         }
     121             : 
     122             :         // ignore VOID Any ... but reject wrong filled ones!
     123           0 :         if (lSource[i].hasValue())
     124             :             throw css::lang::IllegalArgumentException(
     125             :                 "Any contains wrong type.",
     126           0 :                 css::uno::Reference<css::uno::XInterface>(), -1);
     127           0 :     }
     128        3293 : }
     129             : 
     130      119080 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
     131             : {
     132      119080 :     clear();
     133             : 
     134      119080 :           sal_Int32                  c       = lSource.getLength();
     135      119080 :     const css::beans::PropertyValue* pSource = lSource.getConstArray();
     136             : 
     137      984643 :     for (sal_Int32 i=0; i<c; ++i)
     138      865563 :         (*this)[pSource[i].Name] = pSource[i].Value;
     139      119080 : }
     140             : 
     141       55955 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::NamedValue >& lSource)
     142             : {
     143       55955 :     clear();
     144             : 
     145       55955 :           sal_Int32               c       = lSource.getLength();
     146       55955 :     const css::beans::NamedValue* pSource = lSource.getConstArray();
     147             : 
     148      118861 :     for (sal_Int32 i=0; i<c; ++i)
     149       62906 :         (*this)[pSource[i].Name] = pSource[i].Value;
     150       55955 : }
     151             : 
     152      116159 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::PropertyValue >& lDestination) const
     153             : {
     154      116159 :     sal_Int32 c = (sal_Int32)size();
     155      116159 :     lDestination.realloc(c);
     156      116159 :     css::beans::PropertyValue* pDestination = lDestination.getArray();
     157             : 
     158      116159 :     sal_Int32 i = 0;
     159     2685198 :     for (const_iterator pThis  = begin();
     160     1790132 :                         pThis != end()  ;
     161             :                       ++pThis           )
     162             :     {
     163      778907 :         pDestination[i].Name  = pThis->first ;
     164      778907 :         pDestination[i].Value = pThis->second;
     165      778907 :         ++i;
     166             :     }
     167      116159 : }
     168             : 
     169         142 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::NamedValue >& lDestination) const
     170             : {
     171         142 :     sal_Int32 c = (sal_Int32)size();
     172         142 :     lDestination.realloc(c);
     173         142 :     css::beans::NamedValue* pDestination = lDestination.getArray();
     174             : 
     175         142 :     sal_Int32 i = 0;
     176        1530 :     for (const_iterator pThis  = begin();
     177        1020 :                         pThis != end()  ;
     178             :                       ++pThis           )
     179             :     {
     180         368 :         pDestination[i].Name  = pThis->first ;
     181         368 :         pDestination[i].Value = pThis->second;
     182         368 :         ++i;
     183             :     }
     184         142 : }
     185             : 
     186           1 : const css::uno::Any SequenceAsHashMap::getAsConstAny(bool bAsPropertyValueList) const
     187             : {
     188           1 :     css::uno::Any aDestination;
     189           1 :     if (bAsPropertyValueList)
     190           0 :         aDestination = css::uno::makeAny(getAsConstPropertyValueList());
     191             :     else
     192           1 :         aDestination = css::uno::makeAny(getAsConstNamedValueList());
     193           1 :     return aDestination;
     194             : }
     195             : 
     196         142 : const css::uno::Sequence< css::beans::NamedValue > SequenceAsHashMap::getAsConstNamedValueList() const
     197             : {
     198         142 :     css::uno::Sequence< css::beans::NamedValue > lReturn;
     199         142 :     (*this) >> lReturn;
     200         142 :     return lReturn;
     201             : }
     202             : 
     203       83987 : const css::uno::Sequence< css::beans::PropertyValue > SequenceAsHashMap::getAsConstPropertyValueList() const
     204             : {
     205       83987 :     css::uno::Sequence< css::beans::PropertyValue > lReturn;
     206       83987 :     (*this) >> lReturn;
     207       83987 :     return lReturn;
     208             : }
     209             : 
     210           0 : 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 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 false;
     223             : 
     224           0 :         const css::uno::Any& aFoundValue = pFound->second;
     225           0 :         if (aFoundValue != aCheckValue)
     226           0 :             return false;
     227             :     }
     228             : 
     229           0 :     return true;
     230             : }
     231             : 
     232        4364 : void SequenceAsHashMap::update(const SequenceAsHashMap& rUpdate)
     233             : {
     234        4364 :     const_iterator pUpdate;
     235       64173 :     for (  pUpdate  = rUpdate.begin();
     236       42782 :            pUpdate != rUpdate.end()  ;
     237             :          ++pUpdate                   )
     238             :     {
     239       17027 :         const OUString& sName  = pUpdate->first;
     240       17027 :         const css::uno::Any&   aValue = pUpdate->second;
     241             : 
     242       17027 :         (*this)[sName] = aValue;
     243             :     }
     244        4364 : }
     245             : 
     246             : } // namespace comphelper
     247             : 
     248             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11