LCOV - code coverage report
Current view: top level - comphelper/source/misc - sequenceashashmap.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 125 0.0 %
Date: 2014-04-14 Functions: 0 17 0.0 %
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           0 : SequenceAsHashMap::SequenceAsHashMap()
      26           0 :     : SequenceAsHashMapBase()
      27             : {
      28           0 : }
      29             : 
      30           0 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any& aSource)
      31             : {
      32           0 :     (*this) << aSource;
      33           0 : }
      34             : 
      35             : 
      36           0 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource)
      37             : {
      38           0 :     (*this) << lSource;
      39           0 : }
      40             : 
      41           0 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
      42             : {
      43           0 :     (*this) << lSource;
      44           0 : }
      45             : 
      46           0 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource)
      47             : {
      48           0 :     (*this) << lSource;
      49           0 : }
      50             : 
      51           0 : SequenceAsHashMap::~SequenceAsHashMap()
      52             : {
      53           0 : }
      54             : 
      55           0 : void SequenceAsHashMap::operator<<(const css::uno::Any& aSource)
      56             : {
      57             :     // An empty Any reset this instance!
      58           0 :     if (!aSource.hasValue())
      59             :     {
      60           0 :         clear();
      61           0 :         return;
      62             :     }
      63             : 
      64           0 :     css::uno::Sequence< css::beans::NamedValue > lN;
      65           0 :     if (aSource >>= lN)
      66             :     {
      67           0 :         (*this) << lN;
      68           0 :         return;
      69             :     }
      70             : 
      71           0 :     css::uno::Sequence< css::beans::PropertyValue > lP;
      72           0 :     if (aSource >>= lP)
      73             :     {
      74           0 :         (*this) << lP;
      75           0 :         return;
      76             :     }
      77             : 
      78             :     throw css::beans::IllegalTypeException(
      79             :             OUString( "Any contains wrong type." ),
      80           0 :             css::uno::Reference< css::uno::XInterface >());
      81             : }
      82             : 
      83             : 
      84           0 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::uno::Any >& lSource)
      85             : {
      86           0 :     sal_Int32 c = lSource.getLength();
      87           0 :     sal_Int32 i = 0;
      88             : 
      89           0 :     for (i=0; i<c; ++i)
      90             :     {
      91           0 :         css::beans::PropertyValue lP;
      92           0 :         if (lSource[i] >>= lP)
      93             :         {
      94           0 :             if (
      95           0 :                 (lP.Name.isEmpty()) ||
      96           0 :                 (!lP.Value.hasValue())
      97             :                )
      98             :                 throw css::beans::IllegalTypeException(
      99             :                         OUString( "PropertyValue struct contains no useful information." ),
     100           0 :                         css::uno::Reference< css::uno::XInterface >());
     101           0 :             (*this)[lP.Name] = lP.Value;
     102           0 :             continue;
     103             :         }
     104             : 
     105           0 :         css::beans::NamedValue lN;
     106           0 :         if (lSource[i] >>= lN)
     107             :         {
     108           0 :             if (
     109           0 :                 (lN.Name.isEmpty()) ||
     110           0 :                 (!lN.Value.hasValue())
     111             :                )
     112             :                 throw css::beans::IllegalTypeException(
     113             :                         OUString( "NamedValue struct contains no useful information." ),
     114           0 :                         css::uno::Reference< css::uno::XInterface >());
     115           0 :             (*this)[lN.Name] = lN.Value;
     116           0 :             continue;
     117             :         }
     118             : 
     119             :         // ignore VOID Any ... but reject wrong filled ones!
     120           0 :         if (lSource[i].hasValue())
     121             :             throw css::beans::IllegalTypeException(
     122             :                     OUString( "Any contains wrong type." ),
     123           0 :                     css::uno::Reference< css::uno::XInterface >());
     124           0 :     }
     125           0 : }
     126             : 
     127           0 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
     128             : {
     129           0 :     clear();
     130             : 
     131           0 :           sal_Int32                  c       = lSource.getLength();
     132           0 :     const css::beans::PropertyValue* pSource = lSource.getConstArray();
     133             : 
     134           0 :     for (sal_Int32 i=0; i<c; ++i)
     135           0 :         (*this)[pSource[i].Name] = pSource[i].Value;
     136           0 : }
     137             : 
     138           0 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::NamedValue >& lSource)
     139             : {
     140           0 :     clear();
     141             : 
     142           0 :           sal_Int32               c       = lSource.getLength();
     143           0 :     const css::beans::NamedValue* pSource = lSource.getConstArray();
     144             : 
     145           0 :     for (sal_Int32 i=0; i<c; ++i)
     146           0 :         (*this)[pSource[i].Name] = pSource[i].Value;
     147           0 : }
     148             : 
     149           0 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::PropertyValue >& lDestination) const
     150             : {
     151           0 :     sal_Int32 c = (sal_Int32)size();
     152           0 :     lDestination.realloc(c);
     153           0 :     css::beans::PropertyValue* pDestination = lDestination.getArray();
     154             : 
     155           0 :     sal_Int32 i = 0;
     156           0 :     for (const_iterator pThis  = begin();
     157           0 :                         pThis != end()  ;
     158             :                       ++pThis           )
     159             :     {
     160           0 :         pDestination[i].Name  = pThis->first ;
     161           0 :         pDestination[i].Value = pThis->second;
     162           0 :         ++i;
     163             :     }
     164           0 : }
     165             : 
     166           0 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::NamedValue >& lDestination) const
     167             : {
     168           0 :     sal_Int32 c = (sal_Int32)size();
     169           0 :     lDestination.realloc(c);
     170           0 :     css::beans::NamedValue* pDestination = lDestination.getArray();
     171             : 
     172           0 :     sal_Int32 i = 0;
     173           0 :     for (const_iterator pThis  = begin();
     174           0 :                         pThis != end()  ;
     175             :                       ++pThis           )
     176             :     {
     177           0 :         pDestination[i].Name  = pThis->first ;
     178           0 :         pDestination[i].Value = pThis->second;
     179           0 :         ++i;
     180             :     }
     181           0 : }
     182             : 
     183           0 : const css::uno::Any SequenceAsHashMap::getAsConstAny(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           0 : const css::uno::Sequence< css::beans::NamedValue > SequenceAsHashMap::getAsConstNamedValueList() const
     194             : {
     195           0 :     css::uno::Sequence< css::beans::NamedValue > lReturn;
     196           0 :     (*this) >> lReturn;
     197           0 :     return lReturn;
     198             : }
     199             : 
     200           0 : const css::uno::Sequence< css::beans::PropertyValue > SequenceAsHashMap::getAsConstPropertyValueList() const
     201             : {
     202           0 :     css::uno::Sequence< css::beans::PropertyValue > lReturn;
     203           0 :     (*this) >> lReturn;
     204           0 :     return lReturn;
     205             : }
     206             : 
     207           0 : 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 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 false;
     220             : 
     221           0 :         const css::uno::Any& aFoundValue = pFound->second;
     222           0 :         if (aFoundValue != aCheckValue)
     223           0 :             return false;
     224             :     }
     225             : 
     226           0 :     return 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 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