LCOV - code coverage report
Current view: top level - include/oox/helper - propertyset.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 14 14 100.0 %
Date: 2015-06-13 12:38:46 Functions: 132 160 82.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             : #ifndef INCLUDED_OOX_HELPER_PROPERTYSET_HXX
      21             : #define INCLUDED_OOX_HELPER_PROPERTYSET_HXX
      22             : 
      23             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      26             : #include <oox/dllapi.h>
      27             : 
      28             : namespace oox {
      29             : 
      30             : class PropertyMap;
      31             : 
      32             : 
      33             : 
      34             : /** A wrapper for a UNO property set.
      35             : 
      36             :     This class provides functions to silently get and set properties (without
      37             :     exceptions, without the need to check validity of the UNO property set).
      38             : 
      39             :     An instance is constructed with the reference to a UNO property set or any
      40             :     other interface (the constructor will query for the
      41             :     com.sun.star.beans.XPropertySet interface then). The reference to the
      42             :     property set will be kept as long as the instance of this class is alive.
      43             : 
      44             :     The functions setProperties() tries to handle all passed values at once,
      45             :     using the com.sun.star.beans.XMultiPropertySet interface.  If the
      46             :     implementation does not support the XMultiPropertySet interface, all
      47             :     properties are handled separately in a loop.
      48             :  */
      49       45227 : class OOX_DLLPUBLIC PropertySet
      50             : {
      51             : public:
      52        1357 :     PropertySet() {}
      53             : 
      54             :     /** Constructs a property set wrapper with the passed UNO property set. */
      55        9781 :     explicit     PropertySet(
      56             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rxPropSet )
      57        9781 :                                 { set( rxPropSet ); }
      58             : 
      59             :     /** Constructs a property set wrapper after querying the XPropertySet interface. */
      60             :     template< typename Type >
      61       34089 :     explicit     PropertySet( const Type& rObject ) { set( rObject ); }
      62             : 
      63             :     /** Sets the passed UNO property set and releases the old UNO property set. */
      64             :     void                set( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rxPropSet );
      65             : 
      66             :     /** Queries the passed object (interface or any) for an XPropertySet and releases the old UNO property set. */
      67             :     template< typename Type >
      68       34773 :     void         set( const Type& rObject )
      69       34773 :                             { set( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >( rObject, ::com::sun::star::uno::UNO_QUERY ) ); }
      70             : 
      71             :     /** Returns true, if the contained XPropertySet interface is valid. */
      72        5174 :     bool         is() const { return mxPropSet.is(); }
      73             : 
      74             :     /** Returns the contained XPropertySet interface. */
      75             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
      76             :                         getXPropertySet() const { return mxPropSet; }
      77             : 
      78             :     /** Returns true, if the specified property is supported by the property set. */
      79             :     bool                hasProperty( sal_Int32 nPropId ) const;
      80             : 
      81             :     // Get properties ---------------------------------------------------------
      82             : 
      83             :     /** Gets the specified property from the property set.
      84             :         @return  the property value, or an empty Any, if the property is missing. */
      85             :     ::com::sun::star::uno::Any getAnyProperty( sal_Int32 nPropId ) const;
      86             : 
      87             :     /** Gets the specified property from the property set.
      88             :         @return  true, if the passed variable could be filled with the property value. */
      89             :     template< typename Type >
      90        8656 :     bool         getProperty( Type& orValue, sal_Int32 nPropId ) const
      91        8656 :                             { return getAnyProperty( nPropId ) >>= orValue; }
      92             : 
      93             :     /** Gets the specified boolean property from the property set.
      94             :         @return  true = property contains true; false = property contains false or error occurred. */
      95         107 :     bool         getBoolProperty( sal_Int32 nPropId ) const
      96         107 :                             { bool bValue = false; return getProperty( bValue, nPropId ) && bValue; }
      97             :     // Set properties ---------------------------------------------------------
      98             : 
      99             :     /** Puts the passed any into the property set. */
     100             :     bool                setAnyProperty( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue );
     101             : 
     102             :     /** Puts the passed value into the property set. */
     103             :     template< typename Type >
     104       37887 :     bool         setProperty( sal_Int32 nPropId, const Type& rValue )
     105       37887 :                             { return setAnyProperty( nPropId, ::com::sun::star::uno::Any( rValue ) ); }
     106             : 
     107             :     /** Puts the passed properties into the property set. Tries to use the XMultiPropertySet interface.
     108             :         @param rPropNames  The property names. MUST be ordered alphabetically.
     109             :         @param rValues  The related property values. */
     110             :     void                setProperties(
     111             :                             const ::com::sun::star::uno::Sequence< OUString >& rPropNames,
     112             :                             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues );
     113             : 
     114             :     /** Puts the passed property map into the property set. Tries to use the XMultiPropertySet interface.
     115             :         @param rPropertyMap  The property map. */
     116             :     void                setProperties( const PropertyMap& rPropertyMap );
     117             : 
     118             : #ifdef DBG_UTIL
     119             :     void dump();
     120             : #endif
     121             : 
     122             : 
     123             : private:
     124             :     /** Gets the specified property from the property set.
     125             :         @return  true, if the any could be filled with the property value. */
     126             :     bool                implGetPropertyValue( ::com::sun::star::uno::Any& orValue, const OUString& rPropName ) const;
     127             : 
     128             :     /** Puts the passed any into the property set. */
     129             :     bool                implSetPropertyValue( const OUString& rPropName, const ::com::sun::star::uno::Any& rValue );
     130             : 
     131             : private:
     132             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
     133             :                         mxPropSet;          ///< The mandatory property set interface.
     134             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet >
     135             :                         mxMultiPropSet;     ///< The optional multi property set interface.
     136             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
     137             :                         mxPropSetInfo;      ///< Property information.
     138             : };
     139             : 
     140             : 
     141             : 
     142             : } // namespace oox
     143             : 
     144             : #endif
     145             : 
     146             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11