LCOV - code coverage report
Current view: top level - chart2/source/tools - ImplOPropertySet.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 69 59.4 %
Date: 2012-08-25 Functions: 11 19 57.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 56 33.9 %

           Branch data     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 <functional>
      25                 :            : #include <com/sun/star/beans/XFastPropertySet.hpp>
      26                 :            : 
      27                 :            : using namespace ::com::sun::star;
      28                 :            : 
      29                 :            : using ::rtl::OUString;
      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                 :      10608 :     lcl_getPropertyStateByHandle(
      41                 :            :         const ::property::impl::ImplOPropertySet::tPropertyMap & rMap )
      42                 :      10608 :             : m_rMap( rMap )
      43                 :      10608 :     {}
      44                 :            : 
      45                 :      10608 :     inline beans::PropertyState operator() ( sal_Int32 nHandle )
      46                 :            :     {
      47         [ +  + ]:      10608 :         if( m_rMap.end() == m_rMap.find( nHandle ))
      48                 :      10226 :             return beans::PropertyState_DEFAULT_VALUE;
      49                 :      10608 :         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                 :        140 :     inline void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp )
      77                 :            :     {
      78   [ +  -  -  + ]:        280 :         if( rProp.second.hasValue() &&
                 [ -  + ]
      79                 :        140 :             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                 :        140 :     }
      86                 :            : };
      87                 :            : 
      88                 :            : } //  anonymous namespace
      89                 :            : 
      90                 :            : namespace property
      91                 :            : {
      92                 :            : namespace impl
      93                 :            : {
      94                 :            : 
      95                 :       7881 : ImplOPropertySet::ImplOPropertySet()
      96                 :       7881 : {}
      97                 :            : 
      98                 :         35 : ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther )
      99                 :            : {
     100                 :            :     ::std::copy( rOther.m_aProperties.begin(), rOther.m_aProperties.end(),
     101 [ +  - ][ +  - ]:         35 :                  ::std::inserter( m_aProperties, m_aProperties.begin() ));
     102         [ +  - ]:         35 :     cloneInterfaceProperties();
     103 [ +  - ][ +  - ]:         35 :     m_xStyle.set( ::chart::CloneHelper::CreateRefClone< Reference< style::XStyle > >()( rOther.m_xStyle ));
     104                 :         35 : }
     105                 :            : 
     106                 :      10608 : beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const
     107                 :            : {
     108         [ +  - ]:      10608 :     return lcl_getPropertyStateByHandle( m_aProperties ) ( nHandle );
     109                 :            : }
     110                 :            : 
     111                 :          0 : Sequence< beans::PropertyState > ImplOPropertySet::GetPropertyStatesByHandle(
     112                 :            :     const ::std::vector< sal_Int32 > & aHandles ) const
     113                 :            : {
     114                 :          0 :     Sequence< beans::PropertyState > aResult( aHandles.size());
     115                 :            : 
     116                 :            :     ::std::transform( aHandles.begin(), aHandles.end(),
     117                 :            :                       aResult.getArray(),
     118 [ #  # ][ #  # ]:          0 :                       lcl_getPropertyStateByHandle( m_aProperties ));
     119                 :            : 
     120                 :          0 :     return aResult;
     121                 :            : }
     122                 :            : 
     123                 :        891 : void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle )
     124                 :            : {
     125         [ +  - ]:        891 :     tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) );
     126                 :            : 
     127         [ +  - ]:        891 :     if( m_aProperties.end() != aFoundIter )
     128                 :            :     {
     129         [ +  - ]:        891 :         m_aProperties.erase( aFoundIter );
     130                 :            :     }
     131                 :        891 : }
     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                 :    1248607 : bool ImplOPropertySet::GetPropertyValueByHandle(
     146                 :            :     Any & rValue,
     147                 :            :     sal_Int32 nHandle ) const
     148                 :            : {
     149                 :    1248607 :     bool bResult = false;
     150                 :            : 
     151         [ +  - ]:    1248607 :     tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );
     152                 :            : 
     153         [ +  + ]:    1248607 :     if( m_aProperties.end() != aFoundIter )
     154                 :            :     {
     155                 :     136197 :         rValue = (*aFoundIter).second;
     156                 :     136197 :         bResult = true;
     157                 :            :     }
     158                 :            : 
     159                 :    1248607 :     return bResult;
     160                 :            : }
     161                 :            : 
     162                 :      37741 : void ImplOPropertySet::SetPropertyValueByHandle(
     163                 :            :     sal_Int32 nHandle, const Any & rValue, Any * pOldValue )
     164                 :            : {
     165         [ -  + ]:      37741 :     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                 :      37741 :     m_aProperties[ nHandle ] = rValue;
     173                 :      37741 : }
     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                 :    1112410 : Reference< style::XStyle > ImplOPropertySet::GetStyle() const
     185                 :            : {
     186                 :    1112410 :     return m_xStyle;
     187                 :            : }
     188                 :            : 
     189                 :         35 : void ImplOPropertySet::cloneInterfaceProperties()
     190                 :            : {
     191                 :            :     ::std::for_each( m_aProperties.begin(), m_aProperties.end(),
     192         [ +  - ]:         35 :                      lcl_replaceInterfacePropertiesByClones());
     193                 :         35 : }
     194                 :            : 
     195                 :            : 
     196                 :            : } //  namespace impl
     197                 :            : } //  namespace chart
     198                 :            : 
     199                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10