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

Generated by: LCOV version 1.10