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

Generated by: LCOV version 1.10