LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/oox/helper - propertyset.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 14 85.7 %
Date: 2012-08-25 Functions: 69 161 42.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 17 62 27.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                 :            : #ifndef OOX_HELPER_PROPERTYSET_HXX
      21                 :            : #define 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                 :       2747 : class OOX_DLLPUBLIC PropertySet
      50                 :            : {
      51                 :            : public:
      52                 :        244 :     inline explicit     PropertySet() {}
      53                 :            : 
      54                 :            :     /** Constructs a property set wrapper with the passed UNO property set. */
      55                 :        393 :     inline explicit     PropertySet(
      56                 :            :                             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rxPropSet )
      57         [ +  - ]:        393 :                                 { set( rxPropSet ); }
      58                 :            : 
      59                 :            :     /** Constructs a property set wrapper after querying the XPropertySet interface. */
      60                 :            :     template< typename Type >
      61 [ +  - ][ +  - ]:       2110 :     inline 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                 :       2194 :     inline void         set( const Type& rObject )
      69 [ +  - ][ +  - ]:       2194 :                             { 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                 :        174 :     inline bool         is() const { return mxPropSet.is(); }
      73                 :            : 
      74                 :            :     /** Returns the contained XPropertySet interface. */
      75                 :            :     inline ::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                 :        501 :     inline bool         getProperty( Type& orValue, sal_Int32 nPropId ) const
      91 [ +  - ][ +  - ]:        501 :                             { 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                 :          0 :     inline bool         getBoolProperty( sal_Int32 nPropId ) const
      96 [ #  # ][ #  # ]:          0 :                             { 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                 :       2271 :     inline bool         setProperty( sal_Int32 nPropId, const Type& rValue )
     105 [ +  - ][ +  - ]:       2271 :                             { 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< ::rtl::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 ::rtl::OUString& rPropName ) const;
     127                 :            : 
     128                 :            :     /** Puts the passed any into the property set. */
     129                 :            :     bool                implSetPropertyValue( const ::rtl::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.10