LCOV - code coverage report
Current view: top level - comphelper/source/property - propertycontainerhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 170 172 98.8 %
Date: 2012-08-25 Functions: 22 22 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 149 255 58.4 %

           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 <comphelper/propertycontainerhelper.hxx>
      21                 :            : #include <comphelper/property.hxx>
      22                 :            : #include <osl/diagnose.h>
      23                 :            : #include <uno/data.h>
      24                 :            : #include <com/sun/star/uno/genfunc.h>
      25                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      26                 :            : #include <com/sun/star/beans/UnknownPropertyException.hpp>
      27                 :            : #include <rtl/ustrbuf.hxx>
      28                 :            : 
      29                 :            : #include <algorithm>
      30                 :            : 
      31                 :            : //.........................................................................
      32                 :            : namespace comphelper
      33                 :            : {
      34                 :            : //.........................................................................
      35                 :            : 
      36                 :            : using namespace ::com::sun::star::uno;
      37                 :            : using namespace ::com::sun::star::lang;
      38                 :            : using namespace ::com::sun::star::beans;
      39                 :            : 
      40                 :            : //--------------------------------------------------------------------------
      41                 :            : namespace
      42                 :            : {
      43                 :            :     // comparing two property descriptions
      44                 :            :     struct PropertyDescriptionCompareByHandle : public ::std::binary_function< PropertyDescription, PropertyDescription, bool >
      45                 :            :     {
      46                 :            :         bool operator() (const PropertyDescription& x, const PropertyDescription& y) const
      47                 :            :         {
      48                 :            :             return x.aProperty.Handle < y.aProperty.Handle;
      49                 :            :         }
      50                 :            :     };
      51                 :            :     // comparing two property descriptions
      52                 :            :     struct PropertyDescriptionHandleCompare : public ::std::binary_function< PropertyDescription, PropertyDescription, bool >
      53                 :            :     {
      54                 :    3498379 :         bool operator() (const PropertyDescription& x, const PropertyDescription& y) const
      55                 :            :         {
      56                 :    3498379 :             return x.aProperty.Handle < y.aProperty.Handle;
      57                 :            :         }
      58                 :            :     };
      59                 :            :     // comparing two property descriptions (by name)
      60                 :      35523 :     struct PropertyDescriptionNameMatch : public ::std::unary_function< PropertyDescription, bool >
      61                 :            :     {
      62                 :            :         ::rtl::OUString m_rCompare;
      63                 :      11841 :         PropertyDescriptionNameMatch( const ::rtl::OUString& _rCompare ) : m_rCompare( _rCompare ) { }
      64                 :            : 
      65                 :     265535 :         bool operator() (const PropertyDescription& x ) const
      66                 :            :         {
      67                 :     265535 :             return x.aProperty.Name.equals(m_rCompare);
      68                 :            :         }
      69                 :            :     };
      70                 :            : }
      71                 :            : 
      72                 :            : //==========================================================================
      73                 :            : //= OPropertyContainerHelper
      74                 :            : //==========================================================================
      75                 :            : //--------------------------------------------------------------------------
      76                 :      96232 : OPropertyContainerHelper::OPropertyContainerHelper()
      77         [ +  - ]:      96232 :     :m_bUnused(sal_False)
      78                 :            : {
      79                 :      96232 : }
      80                 :            : 
      81                 :            : // -------------------------------------------------------------------------
      82                 :      95919 : OPropertyContainerHelper::~OPropertyContainerHelper()
      83                 :            : {
      84                 :      95919 : }
      85                 :            : 
      86                 :            : //--------------------------------------------------------------------------
      87                 :     229960 : void OPropertyContainerHelper::registerProperty(const ::rtl::OUString& _rName, sal_Int32 _nHandle,
      88                 :            :         sal_Int32 _nAttributes, void* _pPointerToMember, const Type& _rMemberType)
      89                 :            : {
      90                 :            :     OSL_ENSURE((_nAttributes & PropertyAttribute::MAYBEVOID) == 0,
      91                 :            :         "OPropertyContainerHelper::registerProperty: don't use this for properties which may be void ! There is a method called \"registerMayBeVoidProperty\" for this !");
      92                 :            :     OSL_ENSURE(!_rMemberType.equals(::getCppuType(static_cast< Any* >(NULL))),
      93                 :            :         "OPropertyContainerHelper::registerProperty: don't give my the type of an uno::Any ! Really can't handle this !");
      94                 :            :     OSL_ENSURE(_pPointerToMember,
      95                 :            :         "OPropertyContainerHelper::registerProperty: you gave me nonsense : the pointer must be non-NULL");
      96                 :            : 
      97                 :     229960 :     PropertyDescription aNewProp;
      98                 :     229960 :     aNewProp.aProperty = Property( _rName, _nHandle, _rMemberType, (sal_Int16)_nAttributes );
      99                 :     229960 :     aNewProp.eLocated = PropertyDescription::ltDerivedClassRealType;
     100                 :     229960 :     aNewProp.aLocation.pDerivedClassMember = _pPointerToMember;
     101                 :            : 
     102 [ +  - ][ +  - ]:     229960 :     implPushBackProperty(aNewProp);
     103                 :     229960 : }
     104                 :            : 
     105                 :            : //--------------------------------------------------------------------------
     106                 :         54 : void OPropertyContainerHelper::revokeProperty( sal_Int32 _nHandle )
     107                 :            : {
     108         [ +  - ]:         54 :     PropertiesIterator aPos = searchHandle( _nHandle );
     109 [ +  - ][ -  + ]:         54 :     if ( aPos == m_aProperties.end() )
     110         [ #  # ]:          0 :         throw UnknownPropertyException();
     111         [ +  - ]:         54 :     m_aProperties.erase( aPos );
     112                 :         54 : }
     113                 :            : 
     114                 :            : //--------------------------------------------------------------------------
     115                 :      19206 : void OPropertyContainerHelper::registerMayBeVoidProperty(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes,
     116                 :            :         Any* _pPointerToMember, const Type& _rExpectedType)
     117                 :            : {
     118                 :            :     OSL_ENSURE((_nAttributes & PropertyAttribute::MAYBEVOID) != 0,
     119                 :            :         "OPropertyContainerHelper::registerMayBeVoidProperty: why calling this when the attributes say nothing about may-be-void ?");
     120                 :            :     OSL_ENSURE(!_rExpectedType.equals(::getCppuType(static_cast< Any* >(NULL))),
     121                 :            :         "OPropertyContainerHelper::registerMayBeVoidProperty: don't give my the type of an uno::Any ! Really can't handle this !");
     122                 :            :     OSL_ENSURE(_pPointerToMember,
     123                 :            :         "OPropertyContainerHelper::registerMayBeVoidProperty: you gave me nonsense : the pointer must be non-NULL");
     124                 :            : 
     125                 :      19206 :     _nAttributes |= PropertyAttribute::MAYBEVOID;
     126                 :            : 
     127                 :      19206 :     PropertyDescription aNewProp;
     128                 :      19206 :     aNewProp.aProperty = Property( _rName, _nHandle, _rExpectedType, (sal_Int16)_nAttributes );
     129                 :      19206 :     aNewProp.eLocated = PropertyDescription::ltDerivedClassAnyType;
     130                 :      19206 :     aNewProp.aLocation.pDerivedClassMember = _pPointerToMember;
     131                 :            : 
     132 [ +  - ][ +  - ]:      19206 :     implPushBackProperty(aNewProp);
     133                 :      19206 : }
     134                 :            : 
     135                 :            : 
     136                 :            : //--------------------------------------------------------------------------
     137                 :      14167 : void OPropertyContainerHelper::registerPropertyNoMember(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes,
     138                 :            :         const Type& _rType, const void* _pInitialValue)
     139                 :            : {
     140                 :            :     OSL_ENSURE(!_rType.equals(::getCppuType(static_cast< Any* >(NULL))),
     141                 :            :         "OPropertyContainerHelper::registerPropertyNoMember : don't give my the type of an uno::Any ! Really can't handle this !");
     142                 :            :     OSL_ENSURE(_pInitialValue || ((_nAttributes & PropertyAttribute::MAYBEVOID) != 0),
     143                 :            :         "OPropertyContainerHelper::registerPropertyNoMember : you should not ommit the initial value if the property can't be void ! This will definitivly crash later !");
     144                 :            : 
     145                 :      14167 :     PropertyDescription aNewProp;
     146                 :      14167 :     aNewProp.aProperty = Property( _rName, _nHandle, _rType, (sal_Int16)_nAttributes );
     147                 :      14167 :     aNewProp.eLocated = PropertyDescription::ltHoldMyself;
     148                 :      14167 :     aNewProp.aLocation.nOwnClassVectorIndex = m_aHoldProperties.size();
     149         [ +  + ]:      14167 :     if (_pInitialValue)
     150         [ +  - ]:      13597 :         m_aHoldProperties.push_back(Any(_pInitialValue, _rType));
     151                 :            :     else
     152         [ +  - ]:        570 :         m_aHoldProperties.push_back(Any());
     153                 :            : 
     154 [ +  - ][ +  - ]:      14167 :     implPushBackProperty(aNewProp);
     155                 :      14167 : }
     156                 :            : 
     157                 :            : //--------------------------------------------------------------------------
     158                 :     503026 : sal_Bool OPropertyContainerHelper::isRegisteredProperty( sal_Int32 _nHandle ) const
     159                 :            : {
     160 [ +  - ][ +  - ]:     503026 :     return const_cast< OPropertyContainerHelper* >( this )->searchHandle( _nHandle ) != m_aProperties.end();
     161                 :            : }
     162                 :            : 
     163                 :            : //--------------------------------------------------------------------------
     164                 :      11781 : sal_Bool OPropertyContainerHelper::isRegisteredProperty( const ::rtl::OUString& _rName ) const
     165                 :            : {
     166                 :            :     // TODO: the current structure is from a time where properties were
     167                 :            :     // static, not dynamic. Since we allow that properties are also dynamic,
     168                 :            :     // i.e. registered and revoked even though the XPropertySet has already been
     169                 :            :     // accessed, a vector is not really the best data structure anymore ...
     170                 :            : 
     171                 :            :     ConstPropertiesIterator pos = ::std::find_if(
     172                 :            :         m_aProperties.begin(),
     173                 :            :         m_aProperties.end(),
     174                 :            :         PropertyDescriptionNameMatch( _rName )
     175         [ +  - ]:      11781 :     );
     176         [ +  - ]:      11781 :     return pos != m_aProperties.end();
     177                 :            : }
     178                 :            : 
     179                 :            : //--------------------------------------------------------------------------
     180                 :            : namespace
     181                 :            : {
     182                 :            :     struct ComparePropertyHandles
     183                 :            :     {
     184                 :     456913 :         bool operator()( const PropertyDescription& _rLHS, const PropertyDescription& _nRHS ) const
     185                 :            :         {
     186                 :     456913 :             return _rLHS.aProperty.Handle < _nRHS.aProperty.Handle;
     187                 :            :         }
     188                 :            :     };
     189                 :            : }
     190                 :            : 
     191                 :            : //--------------------------------------------------------------------------
     192                 :     263333 : void OPropertyContainerHelper::implPushBackProperty(const PropertyDescription& _rProp)
     193                 :            : {
     194                 :            : #ifdef DBG_UTIL
     195                 :            :     for (   PropertiesIterator checkConflicts = m_aProperties.begin();
     196                 :            :             checkConflicts != m_aProperties.end();
     197                 :            :             ++checkConflicts
     198                 :            :         )
     199                 :            :     {
     200                 :            :         OSL_ENSURE(checkConflicts->aProperty.Name != _rProp.aProperty.Name, "OPropertyContainerHelper::implPushBackProperty: name already exists!");
     201                 :            :         OSL_ENSURE(checkConflicts->aProperty.Handle != _rProp.aProperty.Handle, "OPropertyContainerHelper::implPushBackProperty: handle already exists!");
     202                 :            :     }
     203                 :            : #endif
     204                 :            : 
     205                 :            :     PropertiesIterator pos = ::std::lower_bound(
     206                 :            :         m_aProperties.begin(), m_aProperties.end(),
     207         [ +  - ]:     263333 :         _rProp, ComparePropertyHandles() );
     208                 :            : 
     209         [ +  - ]:     263333 :     m_aProperties.insert( pos, _rProp );
     210                 :     263333 : }
     211                 :            : 
     212                 :            : //--------------------------------------------------------------------------
     213                 :            : namespace
     214                 :            : {
     215                 :          6 :     void lcl_throwIllegalPropertyValueTypeException( const PropertyDescription& _rProperty, const Any& _rValue )
     216                 :            :     {
     217                 :          6 :         ::rtl::OUStringBuffer aErrorMessage;
     218         [ +  - ]:          6 :         aErrorMessage.appendAscii( "The given value cannot be converted to the required property type." );
     219         [ +  - ]:          6 :         aErrorMessage.appendAscii( "\n(property name \"" );
     220         [ +  - ]:          6 :         aErrorMessage.append( _rProperty.aProperty.Name );
     221         [ +  - ]:          6 :         aErrorMessage.appendAscii( "\", found value type \"" );
     222         [ +  - ]:          6 :         aErrorMessage.append( _rValue.getValueType().getTypeName() );
     223         [ +  - ]:          6 :         aErrorMessage.appendAscii( "\", required property type \"" );
     224         [ +  - ]:          6 :         aErrorMessage.append( _rProperty.aProperty.Type.getTypeName() );
     225         [ +  - ]:          6 :         aErrorMessage.appendAscii( "\")" );
     226 [ +  - ][ +  - ]:          6 :         throw IllegalArgumentException( aErrorMessage.makeStringAndClear(), NULL, 4 );
                 [ +  - ]
     227                 :            :     }
     228                 :            : }
     229                 :            : 
     230                 :            : //--------------------------------------------------------------------------
     231                 :      35806 : sal_Bool OPropertyContainerHelper::convertFastPropertyValue(
     232                 :            :     Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) SAL_THROW( (IllegalArgumentException) )
     233                 :            : {
     234                 :      35806 :     sal_Bool bModified = sal_False;
     235                 :            : 
     236                 :            :     // get the property somebody is asking for
     237         [ +  - ]:      35806 :     PropertiesIterator aPos = searchHandle(_nHandle);
     238 [ +  - ][ -  + ]:      35806 :     if (aPos == m_aProperties.end())
     239                 :            :     {
     240                 :            :         OSL_FAIL( "OPropertyContainerHelper::convertFastPropertyValue: unknown handle!" );
     241                 :            :         // should not happen if the derived class has built a correct property set info helper to be used by
     242                 :            :         // our base class OPropertySetHelper
     243                 :          0 :         return bModified;
     244                 :            :     }
     245                 :            : 
     246         [ +  - ]:      35806 :     switch (aPos->eLocated)
              [ +  +  - ]
     247                 :            :     {
     248                 :            :         // similar handling for the two cases where the value is stored in an any
     249                 :            :         case PropertyDescription::ltHoldMyself:
     250                 :            :         case PropertyDescription::ltDerivedClassAnyType:
     251                 :            :         {
     252         [ +  - ]:      12262 :             sal_Bool bMayBeVoid = ((aPos->aProperty.Attributes & PropertyAttribute::MAYBEVOID) != 0);
     253                 :            : 
     254                 :            : 
     255                 :            :             // non modifiable version of the value-to-be-set
     256                 :      12262 :             Any aNewRequestedValue( _rValue );
     257                 :            : 
     258                 :            :             // normalization
     259                 :            :             // #i29490#
     260 [ +  + ][ +  - ]:      12262 :             if ( !aNewRequestedValue.getValueType().equals( aPos->aProperty.Type ) )
     261                 :            :             {   // the actually given value is not of the same type as the one required
     262         [ +  - ]:       9326 :                 Any aProperlyTyped( NULL, aPos->aProperty.Type.getTypeLibType() );
     263                 :            : 
     264         [ +  + ]:       9326 :                 if (    uno_type_assignData(
     265                 :      18652 :                             const_cast< void* >( aProperlyTyped.getValue() ), aProperlyTyped.getValueType().getTypeLibType(),
     266                 :      18652 :                             const_cast< void* >( aNewRequestedValue.getValue() ), aNewRequestedValue.getValueType().getTypeLibType(),
     267                 :            :                             reinterpret_cast< uno_QueryInterfaceFunc >( cpp_queryInterface ),
     268                 :            :                             reinterpret_cast< uno_AcquireFunc >( cpp_acquire ),
     269                 :            :                             reinterpret_cast< uno_ReleaseFunc >( cpp_release )
     270                 :      27978 :                         )
     271                 :            :                     )
     272                 :            :                 {
     273                 :            :                     // we were able to query the given XInterface-derivee for the interface
     274                 :            :                     // which is required for this property
     275                 :        360 :                     aNewRequestedValue = aProperlyTyped;
     276                 :       9326 :                 }
     277                 :            :             }
     278                 :            : 
     279                 :            :             // argument check
     280         [ +  + ]:      23814 :             if  (   !   (   (bMayBeVoid && !aNewRequestedValue.hasValue())                      // void is allowed if the attribute says so
     281         [ +  - ]:       3298 :                         ||  (aNewRequestedValue.getValueType().equals(aPos->aProperty.Type))    // else the types have to be equal
     282   [ +  +  +  +  :      27112 :                         )
                   +  + ]
     283                 :            :                 )
     284                 :            :             {
     285 [ +  - ][ -  + ]:          2 :                 lcl_throwIllegalPropertyValueTypeException( *aPos, _rValue );
     286                 :            :             }
     287                 :            : 
     288                 :      12260 :             Any* pPropContainer = NULL;
     289                 :            :                 // the pointer to the any which holds the property value, no matter if located in the derived clas
     290                 :            :                 // or in out vector
     291                 :            : 
     292 [ +  - ][ +  + ]:      12260 :             if (PropertyDescription::ltHoldMyself == aPos->eLocated)
     293                 :            :             {
     294                 :            :                 OSL_ENSURE(aPos->aLocation.nOwnClassVectorIndex < (sal_Int32)m_aHoldProperties.size(),
     295                 :            :                     "OPropertyContainerHelper::convertFastPropertyValue: invalid position !");
     296 [ +  - ][ +  - ]:        762 :                 PropertyContainerIterator aIter = m_aHoldProperties.begin() + aPos->aLocation.nOwnClassVectorIndex;
     297                 :        762 :                 pPropContainer = &(*aIter);
     298                 :            :             }
     299                 :            :             else
     300         [ +  - ]:      11498 :                 pPropContainer = reinterpret_cast<Any*>(aPos->aLocation.pDerivedClassMember);
     301                 :            : 
     302                 :            :             // check if the new value differs from the current one
     303 [ +  + ][ +  + ]:      12260 :             if (!pPropContainer->hasValue() || !aNewRequestedValue.hasValue())
                 [ +  + ]
     304                 :      10549 :                 bModified = pPropContainer->hasValue() != aNewRequestedValue.hasValue();
     305                 :            :             else
     306                 :            :                 bModified = !uno_type_equalData(
     307         [ +  - ]:       3422 :                                 const_cast< void* >( pPropContainer->getValue() ), aPos->aProperty.Type.getTypeLibType(),
     308         [ +  - ]:       3422 :                                 const_cast< void* >( aNewRequestedValue.getValue() ), aPos->aProperty.Type.getTypeLibType(),
     309                 :            :                                 reinterpret_cast< uno_QueryInterfaceFunc >( cpp_queryInterface ),
     310                 :            :                                 reinterpret_cast< uno_ReleaseFunc >( cpp_release )
     311                 :       5133 :                             );
     312                 :            : 
     313         [ +  + ]:      12260 :             if (bModified)
     314                 :            :             {
     315                 :       1900 :                 _rOldValue = *pPropContainer;
     316                 :       1900 :                 _rConvertedValue = aNewRequestedValue;
     317                 :      12262 :             }
     318                 :            :         }
     319                 :            :         break;
     320                 :            :         case PropertyDescription::ltDerivedClassRealType:
     321                 :            :             // let the UNO runtime library do any possible conversion
     322                 :            :             // this may include a change of the type - for instance, if a LONG is required,
     323                 :            :             // but a short is given, then this is valid, as it can be converted without any potential
     324                 :            :             // data loss
     325                 :            : 
     326                 :      23544 :             Any aProperlyTyped;
     327                 :      23544 :             const Any* pNewValue = &_rValue;
     328                 :            : 
     329 [ +  + ][ +  - ]:      23544 :             if (!_rValue.getValueType().equals(aPos->aProperty.Type))
     330                 :            :             {
     331                 :          8 :                 sal_Bool bConverted = sal_False;
     332                 :            : 
     333                 :            :                 // a temporary any of the correct (required) type
     334         [ +  - ]:          8 :                 aProperlyTyped = Any( NULL, aPos->aProperty.Type.getTypeLibType() );
     335                 :            :                     // (need this as we do not want to overwrite the derived class member here)
     336                 :            : 
     337         [ +  + ]:          8 :                 if (    uno_type_assignData(
     338                 :         16 :                             const_cast<void*>(aProperlyTyped.getValue()), aProperlyTyped.getValueType().getTypeLibType(),
     339                 :         16 :                             const_cast<void*>(_rValue.getValue()), _rValue.getValueType().getTypeLibType(),
     340                 :            :                             reinterpret_cast< uno_QueryInterfaceFunc >( cpp_queryInterface ),
     341                 :            :                             reinterpret_cast< uno_AcquireFunc >( cpp_acquire ),
     342                 :            :                             reinterpret_cast< uno_ReleaseFunc >( cpp_release )
     343                 :         24 :                         )
     344                 :            :                     )
     345                 :            :                 {
     346                 :            :                     // could query for the requested interface
     347                 :          4 :                     bConverted = sal_True;
     348                 :          4 :                     pNewValue = &aProperlyTyped;
     349                 :            :                 }
     350                 :            : 
     351         [ +  + ]:          8 :                 if ( !bConverted )
     352 [ +  - ][ -  + ]:          4 :                     lcl_throwIllegalPropertyValueTypeException( *aPos, _rValue );
     353                 :            :             }
     354                 :            : 
     355                 :            :             // from here on, we should have the proper type
     356                 :            :             OSL_ENSURE( pNewValue->getValueType() == aPos->aProperty.Type,
     357                 :            :                 "OPropertyContainerHelper::convertFastPropertyValue: conversion failed!" );
     358                 :            :             bModified = !uno_type_equalData(
     359   [ +  -  +  - ]:      47080 :                             aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type.getTypeLibType(),
     360         [ +  - ]:      47080 :                             const_cast<void*>(pNewValue->getValue()), aPos->aProperty.Type.getTypeLibType(),
     361                 :            :                             reinterpret_cast< uno_QueryInterfaceFunc >( cpp_queryInterface ),
     362                 :            :                             reinterpret_cast< uno_ReleaseFunc >( cpp_release )
     363                 :      70620 :                         );
     364                 :            : 
     365         [ +  + ]:      23540 :             if (bModified)
     366                 :            :             {
     367 [ +  - ][ +  - ]:       7144 :                 _rOldValue.setValue(aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type);
     368                 :       7144 :                 _rConvertedValue = *pNewValue;
     369                 :            :             }
     370                 :      35806 :             break;
     371                 :            :     }
     372                 :            : 
     373                 :      35800 :     return bModified;
     374                 :            : }
     375                 :            : 
     376                 :            : //--------------------------------------------------------------------------
     377                 :      24000 : void OPropertyContainerHelper::setFastPropertyValue(sal_Int32 _nHandle, const Any& _rValue) SAL_THROW( (Exception) )
     378                 :            : {
     379                 :            :     // get the property somebody is asking for
     380         [ +  - ]:      24000 :     PropertiesIterator aPos = searchHandle(_nHandle);
     381 [ +  - ][ +  - ]:      24000 :     if (aPos == m_aProperties.end())
     382                 :            :     {
     383                 :            :         OSL_FAIL( "OPropertyContainerHelper::setFastPropertyValue: unknown handle!" );
     384                 :            :         // should not happen if the derived class has built a correct property set info helper to be used by
     385                 :            :         // our base class OPropertySetHelper
     386                 :      24000 :         return;
     387                 :            :     }
     388                 :            : 
     389         [ +  - ]:      24000 :     switch (aPos->eLocated)
           [ +  +  +  - ]
     390                 :            :     {
     391                 :            :         case PropertyDescription::ltHoldMyself:
     392         [ +  - ]:         42 :             m_aHoldProperties[aPos->aLocation.nOwnClassVectorIndex] = _rValue;
     393                 :         42 :             break;
     394                 :            : 
     395                 :            :         case PropertyDescription::ltDerivedClassAnyType:
     396         [ +  - ]:       2362 :             *reinterpret_cast< Any* >(aPos->aLocation.pDerivedClassMember) = _rValue;
     397                 :       2362 :             break;
     398                 :            : 
     399                 :            :         case PropertyDescription::ltDerivedClassRealType:
     400                 :            : #if OSL_DEBUG_LEVEL > 0
     401                 :            :             sal_Bool bSuccess =
     402                 :            : #endif
     403                 :            :             // copy the data from the to-be-set value
     404                 :            :             uno_type_assignData(
     405   [ +  -  +  - ]:      43192 :                 aPos->aLocation.pDerivedClassMember,        aPos->aProperty.Type.getTypeLibType(),
     406                 :      43192 :                 const_cast< void* >( _rValue.getValue() ),  _rValue.getValueType().getTypeLibType(),
     407                 :            :                 reinterpret_cast< uno_QueryInterfaceFunc >( cpp_queryInterface ),
     408                 :            :                 reinterpret_cast< uno_AcquireFunc >( cpp_acquire ),
     409                 :      64788 :                 reinterpret_cast< uno_ReleaseFunc >( cpp_release ) );
     410                 :            : 
     411                 :            :             OSL_ENSURE( bSuccess,
     412                 :            :                 "OPropertyContainerHelper::setFastPropertyValue: ooops .... the value could not be assigned!");
     413                 :            : 
     414                 :      24000 :             break;
     415                 :            :     }
     416                 :            : }
     417                 :            : 
     418                 :            : //--------------------------------------------------------------------------
     419                 :     317522 : void OPropertyContainerHelper::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
     420                 :            : {
     421                 :            :     // get the property somebody is asking for
     422         [ +  - ]:     317522 :     PropertiesIterator aPos = const_cast<OPropertyContainerHelper*>(this)->searchHandle(_nHandle);
     423 [ +  - ][ +  - ]:     317522 :     if (aPos == m_aProperties.end())
     424                 :            :     {
     425                 :            :         OSL_FAIL( "OPropertyContainerHelper::getFastPropertyValue: unknown handle!" );
     426                 :            :         // should not happen if the derived class has built a correct property set info helper to be used by
     427                 :            :         // our base class OPropertySetHelper
     428                 :     317522 :         return;
     429                 :            :     }
     430                 :            : 
     431         [ +  - ]:     317522 :     switch (aPos->eLocated)
           [ +  +  +  - ]
     432                 :            :     {
     433                 :            :         case PropertyDescription::ltHoldMyself:
     434                 :            :             OSL_ENSURE(aPos->aLocation.nOwnClassVectorIndex < (sal_Int32)m_aHoldProperties.size(),
     435                 :            :                 "OPropertyContainerHelper::convertFastPropertyValue: invalid position !");
     436         [ +  - ]:      48958 :             _rValue = m_aHoldProperties[aPos->aLocation.nOwnClassVectorIndex];
     437                 :      48958 :             break;
     438                 :            :         case PropertyDescription::ltDerivedClassAnyType:
     439         [ +  - ]:      22776 :             _rValue = *reinterpret_cast<Any*>(aPos->aLocation.pDerivedClassMember);
     440                 :      22776 :             break;
     441                 :            :         case PropertyDescription::ltDerivedClassRealType:
     442 [ +  - ][ +  - ]:     245788 :             _rValue.setValue(aPos->aLocation.pDerivedClassMember, aPos->aProperty.Type);
     443                 :     317522 :             break;
     444                 :            :     }
     445                 :            : }
     446                 :            : 
     447                 :            : //--------------------------------------------------------------------------
     448                 :     880408 : OPropertyContainerHelper::PropertiesIterator OPropertyContainerHelper::searchHandle(sal_Int32 _nHandle)
     449                 :            : {
     450                 :     880408 :     PropertyDescription aHandlePropDesc;
     451                 :     880408 :     aHandlePropDesc.aProperty.Handle = _nHandle;
     452                 :            :     // search a lower bound
     453                 :            :     PropertiesIterator aLowerBound = ::std::lower_bound(
     454                 :            :         m_aProperties.begin(),
     455                 :            :         m_aProperties.end(),
     456                 :            :         aHandlePropDesc,
     457         [ +  - ]:     880408 :         PropertyDescriptionHandleCompare());
     458                 :            : 
     459                 :            :     // check for identity
     460 [ +  - ][ +  + ]:     880408 :     if ((aLowerBound != m_aProperties.end()) && aLowerBound->aProperty.Handle != _nHandle)
         [ +  - ][ +  + ]
                 [ +  - ]
           [ +  +  #  # ]
     461                 :      49053 :         aLowerBound = m_aProperties.end();
     462                 :            : 
     463         [ +  - ]:     880408 :     return aLowerBound;
     464                 :            : }
     465                 :            : 
     466                 :            : //--------------------------------------------------------------------------
     467                 :         60 : const Property& OPropertyContainerHelper::getProperty( const ::rtl::OUString& _rName ) const
     468                 :            : {
     469                 :            :     ConstPropertiesIterator pos = ::std::find_if(
     470                 :            :         m_aProperties.begin(),
     471                 :            :         m_aProperties.end(),
     472                 :            :         PropertyDescriptionNameMatch( _rName )
     473         [ +  - ]:         60 :     );
     474 [ +  + ][ +  - ]:         60 :     if ( pos == m_aProperties.end() )
     475 [ +  - ][ +  - ]:          2 :         throw UnknownPropertyException( _rName, NULL );
     476                 :            : 
     477         [ +  - ]:         58 :     return pos->aProperty;
     478                 :            : }
     479                 :            : 
     480                 :            : //--------------------------------------------------------------------------
     481                 :       4978 : void OPropertyContainerHelper::describeProperties(Sequence< Property >& _rProps) const
     482                 :            : {
     483         [ +  - ]:       4978 :     Sequence< Property > aOwnProps(m_aProperties.size());
     484         [ +  - ]:       4978 :     Property* pOwnProps = aOwnProps.getArray();
     485                 :            : 
     486 [ +  - ][ +  - ]:      97862 :     for (   ConstPropertiesIterator aLoop = m_aProperties.begin();
                 [ +  + ]
     487                 :      48931 :             aLoop != m_aProperties.end();
     488                 :            :             ++aLoop, ++pOwnProps
     489                 :            :         )
     490                 :            :     {
     491         [ +  - ]:      43953 :         pOwnProps->Name = aLoop->aProperty.Name;
     492         [ +  - ]:      43953 :         pOwnProps->Handle = aLoop->aProperty.Handle;
     493         [ +  - ]:      43953 :         pOwnProps->Attributes = (sal_Int16)aLoop->aProperty.Attributes;
     494         [ +  - ]:      43953 :         pOwnProps->Type = aLoop->aProperty.Type;
     495                 :            :     }
     496                 :            : 
     497                 :            :     // as our property vector is sorted by handles, not by name, we have to sort aOwnProps
     498 [ +  - ][ +  - ]:       4978 :     ::std::sort(aOwnProps.getArray(), aOwnProps.getArray() + aOwnProps.getLength(), PropertyCompareByName());
                 [ +  - ]
     499                 :            : 
     500                 :            :     // unfortunally the STL merge function does not allow the output range to overlap one of the input ranges,
     501                 :            :     // so we need an extra sequence
     502         [ +  - ]:       4978 :     Sequence< Property > aOutput;
     503         [ +  - ]:       4978 :     aOutput.realloc(_rProps.getLength() + aOwnProps.getLength());
     504                 :            :     // do the merge
     505                 :       4978 :     ::std::merge(   _rProps.getConstArray(), _rProps.getConstArray() + _rProps.getLength(),         // input 1
     506                 :       4978 :                     aOwnProps.getConstArray(), aOwnProps.getConstArray() + aOwnProps.getLength(),   // input 2
     507                 :            :                     aOutput.getArray(),                                                             // output
     508                 :            :                     PropertyCompareByName()                                                         // compare operator
     509   [ +  -  +  - ]:      14934 :                 );
     510                 :            : 
     511                 :            :     // copy the output
     512 [ +  - ][ +  - ]:       4978 :     _rProps = aOutput;
                 [ +  - ]
     513                 :       4978 : }
     514                 :            : 
     515                 :            : //.........................................................................
     516                 :            : }   // namespace comphelper
     517                 :            : //.........................................................................
     518                 :            : 
     519                 :            : 
     520                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10