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

Generated by: LCOV version 1.10