LCOV - code coverage report
Current view: top level - chart2/source/tools - ImplOPropertySet.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 67 64.2 %
Date: 2015-06-13 12:38:46 Functions: 11 18 61.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 "ImplOPropertySet.hxx"
      21             : #include "CloneHelper.hxx"
      22             : 
      23             : #include <algorithm>
      24             : #include <iterator>
      25             : #include <functional>
      26             : #include <com/sun/star/beans/XFastPropertySet.hpp>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : 
      30             : using ::com::sun::star::uno::Sequence;
      31             : using ::com::sun::star::uno::Reference;
      32             : using ::com::sun::star::uno::Any;
      33             : 
      34             : namespace
      35             : {
      36             : 
      37             : struct lcl_getPropertyStateByHandle :
      38             :         public ::std::unary_function< sal_Int32,  beans::PropertyState >
      39             : {
      40      286690 :     explicit lcl_getPropertyStateByHandle(
      41             :         const ::property::impl::ImplOPropertySet::tPropertyMap & rMap )
      42      286690 :             : m_rMap( rMap )
      43      286690 :     {}
      44             : 
      45      287050 :     inline beans::PropertyState operator() ( sal_Int32 nHandle )
      46             :     {
      47      287050 :         if( m_rMap.end() == m_rMap.find( nHandle ))
      48      251185 :             return beans::PropertyState_DEFAULT_VALUE;
      49       35865 :         return beans::PropertyState_DIRECT_VALUE;
      50             :     }
      51             : 
      52             : private:
      53             :     const ::property::impl::ImplOPropertySet::tPropertyMap & m_rMap;
      54             : };
      55             : 
      56             : template< typename K, typename V >
      57           0 : struct lcl_eraseMapEntry :
      58             :         public ::std::unary_function< K, void >
      59             : {
      60           0 :     explicit lcl_eraseMapEntry( ::std::map< K, V > & rMap )
      61           0 :             : m_rMap( rMap )
      62           0 :     {}
      63             : 
      64           0 :     inline void operator() ( const K & aKey )
      65             :     {
      66           0 :         m_rMap.erase( aKey );
      67           0 :     }
      68             : 
      69             : private:
      70             :     ::std::map< K, V > m_rMap;
      71             : };
      72             : 
      73             : struct lcl_replaceInterfacePropertiesByClones :
      74             :     public ::std::unary_function< ::property::impl::ImplOPropertySet::tPropertyMap::value_type, void >
      75             : {
      76         107 :     inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp )
      77             :     {
      78         214 :         if( rProp.second.hasValue() &&
      79         107 :             rProp.second.getValueType().getTypeClass() == uno::TypeClass_INTERFACE )
      80             :         {
      81           0 :             Reference< util::XCloneable > xCloneable;
      82           0 :             if( rProp.second >>= xCloneable )
      83           0 :                 rProp.second <<= xCloneable->createClone();
      84             :         }
      85         107 :     }
      86             : };
      87             : 
      88             : } //  anonymous namespace
      89             : 
      90             : namespace property
      91             : {
      92             : namespace impl
      93             : {
      94             : 
      95      146897 : ImplOPropertySet::ImplOPropertySet()
      96      146897 : {}
      97             : 
      98          28 : ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther )
      99             : {
     100             :     ::std::copy( rOther.m_aProperties.begin(), rOther.m_aProperties.end(),
     101          28 :                  ::std::inserter( m_aProperties, m_aProperties.begin() ));
     102          28 :     cloneInterfaceProperties();
     103          28 :     m_xStyle.set( ::chart::CloneHelper::CreateRefClone< Reference< style::XStyle > >()( rOther.m_xStyle ));
     104          28 : }
     105             : 
     106      286680 : beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const
     107             : {
     108      286680 :     return lcl_getPropertyStateByHandle( m_aProperties ) ( nHandle );
     109             : }
     110             : 
     111          10 : Sequence< beans::PropertyState > ImplOPropertySet::GetPropertyStatesByHandle(
     112             :     const ::std::vector< sal_Int32 > & aHandles ) const
     113             : {
     114          10 :     Sequence< beans::PropertyState > aResult( aHandles.size());
     115             : 
     116             :     ::std::transform( aHandles.begin(), aHandles.end(),
     117             :                       aResult.getArray(),
     118          10 :                       lcl_getPropertyStateByHandle( m_aProperties ));
     119             : 
     120          10 :     return aResult;
     121             : }
     122             : 
     123       29061 : void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle )
     124             : {
     125       29061 :     tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) );
     126             : 
     127       29061 :     if( m_aProperties.end() != aFoundIter )
     128             :     {
     129       29061 :         m_aProperties.erase( aFoundIter );
     130             :     }
     131       29061 : }
     132             : 
     133           0 : void ImplOPropertySet::SetPropertiesToDefault(
     134             :     const ::std::vector< sal_Int32 > & aHandles )
     135             : {
     136             :     ::std::for_each( aHandles.begin(), aHandles.end(),
     137           0 :                      lcl_eraseMapEntry< sal_Int32, Any >( m_aProperties ) );
     138           0 : }
     139             : 
     140           0 : void ImplOPropertySet::SetAllPropertiesToDefault()
     141             : {
     142           0 :     m_aProperties.clear();
     143           0 : }
     144             : 
     145     1831825 : bool ImplOPropertySet::GetPropertyValueByHandle(
     146             :     Any & rValue,
     147             :     sal_Int32 nHandle ) const
     148             : {
     149     1831825 :     bool bResult = false;
     150             : 
     151     1831825 :     tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
     152             : 
     153     1831825 :     if( m_aProperties.end() != aFoundIter )
     154             :     {
     155      262105 :         rValue = (*aFoundIter).second;
     156      262105 :         bResult = true;
     157             :     }
     158             : 
     159     1831825 :     return bResult;
     160             : }
     161             : 
     162      156584 : void ImplOPropertySet::SetPropertyValueByHandle(
     163             :     sal_Int32 nHandle, const Any & rValue, Any * pOldValue )
     164             : {
     165      156584 :     if( pOldValue != NULL )
     166             :     {
     167           0 :         tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
     168           0 :         if( m_aProperties.end() != aFoundIter )
     169           0 :             (*pOldValue) = (*aFoundIter).second;
     170             :     }
     171             : 
     172      156584 :     m_aProperties[ nHandle ] = rValue;
     173      156584 : }
     174             : 
     175           0 : bool ImplOPropertySet::SetStyle( const Reference< style::XStyle > & xStyle )
     176             : {
     177           0 :     if( ! xStyle.is())
     178           0 :         return false;
     179             : 
     180           0 :     m_xStyle = xStyle;
     181           0 :     return true;
     182             : }
     183             : 
     184          28 : void ImplOPropertySet::cloneInterfaceProperties()
     185             : {
     186             :     ::std::for_each( m_aProperties.begin(), m_aProperties.end(),
     187          28 :                      lcl_replaceInterfacePropertiesByClones());
     188          28 : }
     189             : 
     190             : } //  namespace impl
     191             : } //  namespace chart
     192             : 
     193             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11