LCOV - code coverage report
Current view: top level - chart2/source/tools - ImplOPropertySet.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 45 69 65.2 %
Date: 2014-04-11 Functions: 12 19 63.2 %
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      194471 :     lcl_getPropertyStateByHandle(
      41             :         const ::property::impl::ImplOPropertySet::tPropertyMap & rMap )
      42      194471 :             : m_rMap( rMap )
      43      194471 :     {}
      44             : 
      45      194831 :     inline beans::PropertyState operator() ( sal_Int32 nHandle )
      46             :     {
      47      194831 :         if( m_rMap.end() == m_rMap.find( nHandle ))
      48      173013 :             return beans::PropertyState_DEFAULT_VALUE;
      49       21818 :         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 :     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         120 :     inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp )
      77             :     {
      78         240 :         if( rProp.second.hasValue() &&
      79         120 :             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         120 :     }
      86             : };
      87             : 
      88             : } //  anonymous namespace
      89             : 
      90             : namespace property
      91             : {
      92             : namespace impl
      93             : {
      94             : 
      95      114548 : ImplOPropertySet::ImplOPropertySet()
      96      114548 : {}
      97             : 
      98          30 : ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther )
      99             : {
     100             :     ::std::copy( rOther.m_aProperties.begin(), rOther.m_aProperties.end(),
     101          30 :                  ::std::inserter( m_aProperties, m_aProperties.begin() ));
     102          30 :     cloneInterfaceProperties();
     103          30 :     m_xStyle.set( ::chart::CloneHelper::CreateRefClone< Reference< style::XStyle > >()( rOther.m_xStyle ));
     104          30 : }
     105             : 
     106      194461 : beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const
     107             : {
     108      194461 :     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       21739 : void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle )
     124             : {
     125       21739 :     tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) );
     126             : 
     127       21739 :     if( m_aProperties.end() != aFoundIter )
     128             :     {
     129       21739 :         m_aProperties.erase( aFoundIter );
     130             :     }
     131       21739 : }
     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     1208431 : bool ImplOPropertySet::GetPropertyValueByHandle(
     146             :     Any & rValue,
     147             :     sal_Int32 nHandle ) const
     148             : {
     149     1208431 :     bool bResult = false;
     150             : 
     151     1208431 :     tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
     152             : 
     153     1208431 :     if( m_aProperties.end() != aFoundIter )
     154             :     {
     155      156086 :         rValue = (*aFoundIter).second;
     156      156086 :         bResult = true;
     157             :     }
     158             : 
     159     1208431 :     return bResult;
     160             : }
     161             : 
     162      114890 : void ImplOPropertySet::SetPropertyValueByHandle(
     163             :     sal_Int32 nHandle, const Any & rValue, Any * pOldValue )
     164             : {
     165      114890 :     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      114890 :     m_aProperties[ nHandle ] = rValue;
     173      114890 : }
     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     1052345 : Reference< style::XStyle > ImplOPropertySet::GetStyle() const
     185             : {
     186     1052345 :     return m_xStyle;
     187             : }
     188             : 
     189          30 : void ImplOPropertySet::cloneInterfaceProperties()
     190             : {
     191             :     ::std::for_each( m_aProperties.begin(), m_aProperties.end(),
     192          30 :                      lcl_replaceInterfacePropertiesByClones());
     193          30 : }
     194             : 
     195             : } //  namespace impl
     196             : } //  namespace chart
     197             : 
     198             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10