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

Generated by: LCOV version 1.10