LCOV - code coverage report
Current view: top level - xmloff/source/style - MultiPropertySetHelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 46 59 78.0 %
Date: 2014-04-11 Functions: 7 8 87.5 %
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             : 
      21             : #include "MultiPropertySetHelper.hxx"
      22             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      25             : #include <com/sun/star/lang/XServiceInfo.hpp>
      26             : 
      27             : // STL includes
      28             : #include <algorithm>
      29             : 
      30             : 
      31             : using ::com::sun::star::beans::XMultiPropertySet;
      32             : using ::com::sun::star::beans::XPropertySet;
      33             : using ::com::sun::star::beans::XPropertySetInfo;
      34             : using ::com::sun::star::lang::XServiceInfo;
      35             : using ::com::sun::star::uno::Any;
      36             : using ::com::sun::star::uno::Reference;
      37             : using ::com::sun::star::uno::Sequence;
      38             : using ::com::sun::star::uno::UNO_QUERY;
      39             : using ::std::sort;
      40             : 
      41             : 
      42         681 : MultiPropertySetHelper::MultiPropertySetHelper(
      43             :     const sal_Char** pNames ) :
      44             :         pPropertyNames( NULL ),
      45             :         nLength( 0 ),
      46             :         aPropertySequence(),
      47             :         pSequenceIndex( NULL ),
      48             :         aValues(),
      49         681 :         pValues( NULL )
      50             : {
      51             :     // first count the elements
      52        3282 :     for( const sal_Char** pPtr = pNames; *pPtr != NULL; pPtr++ )
      53        2601 :         nLength++;
      54             : 
      55             :     // allocate array and create strings
      56         681 :     pPropertyNames = new OUString[nLength];
      57        3282 :     for( sal_Int16 i = 0; i < nLength; i++ )
      58        2601 :         pPropertyNames[i] = OUString::createFromAscii( pNames[i] );
      59         681 : }
      60             : 
      61             : 
      62        1362 : MultiPropertySetHelper::~MultiPropertySetHelper()
      63             : {
      64         681 :     pValues = NULL; // memory 'owned' by aValues
      65             : 
      66         681 :     delete[] pSequenceIndex;
      67         681 :     delete[] pPropertyNames;
      68         681 : }
      69             : 
      70             : 
      71         666 : void MultiPropertySetHelper::hasProperties(
      72             :     const Reference<XPropertySetInfo> & rInfo )
      73             : {
      74             :     DBG_ASSERT( rInfo.is(), "I'd really like an XPropertySetInfo here." );
      75             : 
      76             :     // allocate sequence index
      77         666 :     if ( NULL == pSequenceIndex )
      78         666 :         pSequenceIndex = new sal_Int16[nLength] ;
      79             : 
      80             :     // construct pSequenceIndex
      81         666 :     sal_Int16 nNumberOfProperties = 0;
      82             :     sal_Int16 i;
      83             : 
      84        3177 :     for( i = 0; i < nLength; i++ )
      85             :     {
      86             :         // ask for property
      87             :         sal_Bool bHasProperty =
      88        2511 :             rInfo->hasPropertyByName( pPropertyNames[i] );
      89             : 
      90             :         // set index and increment (if appropriate)
      91        2511 :         pSequenceIndex[i]= bHasProperty ? nNumberOfProperties : -1;
      92        2511 :         if ( bHasProperty )
      93         890 :             nNumberOfProperties++;
      94             :     }
      95             : 
      96             :     // construct property sequence from index array
      97         666 :     if ( aPropertySequence.getLength() != nNumberOfProperties )
      98         666 :         aPropertySequence.realloc( nNumberOfProperties );
      99         666 :     OUString* pPropertySequence = aPropertySequence.getArray();
     100        3177 :     for( i = 0; i < nLength; i ++ )
     101             :     {
     102        2511 :         sal_Int16 nIndex = pSequenceIndex[i];
     103        2511 :         if ( nIndex != -1 )
     104         890 :             pPropertySequence[nIndex] = pPropertyNames[i];
     105             :     }
     106         666 : }
     107             : 
     108        1027 : bool MultiPropertySetHelper::checkedProperties()
     109             : {
     110        1027 :     return (NULL != pSequenceIndex);
     111             : }
     112             : 
     113             : 
     114             : 
     115         184 : void MultiPropertySetHelper::getValues(
     116             :     const Reference<XMultiPropertySet> & rMultiPropertySet )
     117             : {
     118             :     DBG_ASSERT( rMultiPropertySet.is(), "We need an XMultiPropertySet." );
     119             : 
     120         184 :     aValues = rMultiPropertySet->getPropertyValues( aPropertySequence );
     121         184 :     pValues = aValues.getConstArray();
     122         184 : }
     123             : 
     124           0 : void MultiPropertySetHelper::getValues(
     125             :     const Reference<XPropertySet> & rPropertySet )
     126             : {
     127             :     DBG_ASSERT( rPropertySet.is(), "We need an XPropertySet." );
     128             : 
     129             :     // re-alloc aValues (if necessary) and fill with values from XPropertySet
     130             :     sal_Int16 nSupportedPropertiesCount =
     131           0 :         (sal_Int16)aPropertySequence.getLength();
     132           0 :     if ( aValues.getLength() != nSupportedPropertiesCount )
     133           0 :         aValues.realloc( nSupportedPropertiesCount );
     134           0 :     Any* pMutableArray = aValues.getArray();
     135           0 :     for( sal_Int16 i = 0; i < nSupportedPropertiesCount; i++ )
     136             :     {
     137           0 :         pMutableArray[i] = rPropertySet->getPropertyValue(
     138           0 :             pPropertyNames[ pSequenceIndex[ i ] ] );
     139             :     }
     140             : 
     141             :     // re-establish pValues pointer
     142           0 :     pValues = aValues.getConstArray();
     143           0 : }
     144             : 
     145             : 
     146         184 : const Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex,
     147             :                      const Reference< XPropertySet> & rPropSet,
     148             :                      bool bTryMulti )
     149             : {
     150         184 :     if( !pValues )
     151             :     {
     152         184 :         if( bTryMulti )
     153             :         {
     154             :             Reference < XMultiPropertySet > xMultiPropSet( rPropSet,
     155         184 :                                                            UNO_QUERY );
     156         184 :             if( xMultiPropSet.is() )
     157         184 :                 getValues( xMultiPropSet );
     158             :             else
     159           0 :                 getValues( rPropSet );
     160             :         }
     161             :         else
     162             :         {
     163           0 :             getValues( rPropSet );
     164             :         }
     165             :     }
     166             : 
     167         184 :     return getValue( nIndex );
     168             : }
     169             : 
     170         405 : const Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex,
     171             :                      const Reference< XMultiPropertySet> & rMultiPropSet )
     172             : {
     173         405 :     if( !pValues )
     174           0 :         getValues( rMultiPropSet );
     175             : 
     176         405 :     return getValue( nIndex );
     177             : }
     178             : 
     179             : // inline methods defined in header:
     180             : // inline Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex )
     181             : // inline sal_Bool MultiPropertySetHelper::hasProperty( sal_Int16 nValueNo )
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10