LCOV - code coverage report
Current view: top level - comphelper/source/property - opropertybag.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 8 16 50.0 %
Date: 2015-06-13 12:38:46 Functions: 3 7 42.9 %
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_COMPHELPER_SOURCE_PROPERTY_OPROPERTYBAG_HXX
      21             : #define INCLUDED_COMPHELPER_SOURCE_PROPERTY_OPROPERTYBAG_HXX
      22             : 
      23             : #include <com/sun/star/lang/XInitialization.hpp>
      24             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25             : #include <com/sun/star/lang/XServiceInfo.hpp>
      26             : #include <com/sun/star/util/XModifiable.hpp>
      27             : #include <com/sun/star/beans/XPropertyBag.hpp>
      28             : #include <com/sun/star/uno/XComponentContext.hpp>
      29             : #include <com/sun/star/container/XSet.hpp>
      30             : 
      31             : #include <boost/noncopyable.hpp>
      32             : #include <cppuhelper/implbase5.hxx>
      33             : #include <comphelper/propstate.hxx>
      34             : #include <comphelper/broadcasthelper.hxx>
      35             : #include <comphelper/propertybag.hxx>
      36             : #include <comphelper/uno3.hxx>
      37             : 
      38             : #include <map>
      39             : #include <set>
      40             : #include <memory>
      41             : 
      42             : 
      43             : namespace comphelper
      44             : {
      45             : 
      46             : 
      47             :     struct UnoTypeLess : public ::std::unary_function< ::com::sun::star::uno::Type, bool >
      48             :     {
      49      253945 :         inline bool operator()( const ::com::sun::star::uno::Type& _rLHS, const ::com::sun::star::uno::Type& _rRHS ) const
      50             :         {
      51             :             return rtl_ustr_compare(
      52      253945 :                 _rLHS.getTypeLibType()->pTypeName->buffer,
      53      253945 :                 _rRHS.getTypeLibType()->pTypeName->buffer
      54      507890 :             ) < 0;
      55             :         }
      56             :     };
      57             : 
      58             :     typedef ::std::map< sal_Int32, ::com::sun::star::uno::Any >     MapInt2Any;
      59             :     typedef ::std::set< ::com::sun::star::uno::Type, UnoTypeLess >  TypeBag;
      60             : 
      61             :     typedef ::cppu::WeakAggImplHelper5  <   ::com::sun::star::beans::XPropertyBag
      62             :                                         ,   ::com::sun::star::util::XModifiable
      63             :                                         ,   ::com::sun::star::lang::XServiceInfo
      64             :                                         ,   ::com::sun::star::lang::XInitialization
      65             :                                         ,   ::com::sun::star::container::XSet
      66             :                                         >   OPropertyBag_Base;
      67             :     typedef ::comphelper::OPropertyStateHelper  OPropertyBag_PBase;
      68             : 
      69             :     class OPropertyBag  :public ::comphelper::OMutexAndBroadcastHelper  // must be before OPropertyBag_PBase
      70             :                         ,public OPropertyBag_PBase
      71             :                         ,public OPropertyBag_Base
      72             :                         ,public ::cppu::IEventNotificationHook
      73             :                         ,private boost::noncopyable
      74             :     {
      75             :     private:
      76             :         /// our IPropertyArrayHelper implementation
      77             :         ::std::unique_ptr< ::cppu::OPropertyArrayHelper >
      78             :                         m_pArrayHelper;
      79             :         ::comphelper::PropertyBag
      80             :                         m_aDynamicProperties;
      81             :         /// set of allowed property types
      82             :         TypeBag         m_aAllowedTypes;
      83             :         /// should we automatically add properties which are tried to set, if they don't exist previously?
      84             :         bool            m_bAutoAddProperties;
      85             : 
      86             :         /// for notification
      87             :         ::cppu::OInterfaceContainerHelper m_NotifyListeners;
      88             :         /// modify flag
      89             :         bool            m_isModified;
      90             : 
      91             :     public:
      92             :         // XServiceInfo - static versions
      93             :         static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_static() throw( ::com::sun::star::uno::RuntimeException );
      94             :         static OUString getImplementationName_static() throw( ::com::sun::star::uno::RuntimeException );
      95             :         static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
      96             :                 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
      97             : 
      98             :     protected:
      99             :         OPropertyBag();
     100             :         virtual ~OPropertyBag();
     101             :         DECLARE_XINTERFACE()
     102             :         DECLARE_XTYPEPROVIDER()
     103             : 
     104             :         /** === begin UNO interface implementations == **/
     105             :         // XInitialization
     106             :         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     107             : 
     108             :         // XServiceInfo
     109             :         virtual OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     110             :         virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     111             :         virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     112             : 
     113             :         // XModifiable:
     114             :         virtual sal_Bool SAL_CALL isModified(  )
     115             :             throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     116             :         virtual void SAL_CALL setModified( sal_Bool bModified )
     117             :             throw (::com::sun::star::beans::PropertyVetoException,
     118             :                     ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     119             : 
     120             :         // XModifyBroadcaster
     121             :         virtual void SAL_CALL addModifyListener(
     122             :             const ::com::sun::star::uno::Reference<
     123             :                     ::com::sun::star::util::XModifyListener > & xListener)
     124             :             throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     125             :         virtual void SAL_CALL removeModifyListener(
     126             :             const ::com::sun::star::uno::Reference<
     127             :                     ::com::sun::star::util::XModifyListener > & xListener)
     128             :             throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     129             : 
     130             :         // XPropertyContainer
     131             :         virtual void SAL_CALL addProperty( const OUString& Name, ::sal_Int16 Attributes, const ::com::sun::star::uno::Any& DefaultValue ) throw (::com::sun::star::beans::PropertyExistException, ::com::sun::star::beans::IllegalTypeException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     132             :         virtual void SAL_CALL removeProperty( const OUString& Name ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::NotRemoveableException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     133             : 
     134             :         // XPropertyAccess
     135             :         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     136             :         virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     137             : 
     138             :         // XPropertySet
     139             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     140           3 :         virtual void SAL_CALL setPropertyValue(const rtl::OUString& p1, const com::sun::star::uno::Any& p2) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     141           3 :            { OPropertyBag_PBase::setPropertyValue(p1, p2); }
     142        9456 :         virtual com::sun::star::uno::Any SAL_CALL getPropertyValue(const rtl::OUString& p1) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     143        9456 :            { return OPropertyBag_PBase::getPropertyValue(p1); }
     144           0 :         virtual void SAL_CALL addPropertyChangeListener(const rtl::OUString& p1, const com::sun::star::uno::Reference<com::sun::star::beans::XPropertyChangeListener>& p2) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     145           0 :            { OPropertyBag_PBase::addPropertyChangeListener(p1, p2); }
     146           0 :         virtual void SAL_CALL removePropertyChangeListener(const rtl::OUString& p1, const com::sun::star::uno::Reference<com::sun::star::beans::XPropertyChangeListener>& p2) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     147           0 :            { OPropertyBag_PBase::removePropertyChangeListener(p1, p2); }
     148           0 :         virtual void SAL_CALL addVetoableChangeListener(const rtl::OUString& p1, const com::sun::star::uno::Reference<com::sun::star::beans::XVetoableChangeListener>& p2) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     149           0 :            { OPropertyBag_PBase::addVetoableChangeListener(p1, p2); }
     150           0 :         virtual void SAL_CALL removeVetoableChangeListener(const rtl::OUString& p1, const com::sun::star::uno::Reference<com::sun::star::beans::XVetoableChangeListener>& p2) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     151           0 :            { OPropertyBag_PBase::removeVetoableChangeListener(p1, p2); }
     152             : 
     153             :         // XSet
     154             :         virtual sal_Bool SAL_CALL has( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     155             :         virtual void SAL_CALL insert( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     156             :         virtual void SAL_CALL remove( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     157             : 
     158             :         // XEnumerationAccess (base of XSet)
     159             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     160             : 
     161             :         // XElementAccess (basf of XEnumerationAccess
     162             :         virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     163             :         virtual sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     164             :         /** === UNO interface implementations == **/
     165             : 
     166             :         // XPropertyState
     167             :         virtual ::com::sun::star::uno::Any  getPropertyDefaultByHandle( sal_Int32 _nHandle ) const SAL_OVERRIDE;
     168             : 
     169             :         // OPropertyStateHelper
     170             :         virtual ::com::sun::star::beans::PropertyState  getPropertyStateByHandle( sal_Int32 _nHandle ) SAL_OVERRIDE;
     171             : 
     172             :         // OPropertySetHelper
     173             :         virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const SAL_OVERRIDE;
     174             :         virtual sal_Bool SAL_CALL convertFastPropertyValue( ::com::sun::star::uno::Any & rConvertedValue, ::com::sun::star::uno::Any & rOldValue, sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (css::lang::IllegalArgumentException, css::beans::UnknownPropertyException) SAL_OVERRIDE;
     175             :         virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
     176             :         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;
     177             : 
     178             :         // IEventNotificationHook
     179             :         virtual void fireEvents(
     180             :             sal_Int32 * pnHandles,
     181             :             sal_Int32 nCount,
     182             :             sal_Bool bVetoable,
     183             :             bool bIgnoreRuntimeExceptionsWhileFiring) SAL_OVERRIDE;
     184             : 
     185             :         void SAL_CALL setModifiedImpl( bool bModified,
     186             :             bool bIgnoreRuntimeExceptionsWhileFiring);
     187             : 
     188             :     private:
     189             :         /** finds a free property handle
     190             :             @precond
     191             :                 our mutex is locked
     192             :         */
     193             :         sal_Int32   findFreeHandle() const;
     194             : 
     195             :         /** implements the setPropertyValues method
     196             :             @param _rProps
     197             :                 the property values to set
     198             : 
     199             :             @throws PropertyVetoException
     200             :                 if the XMultiPropertySet::setPropertyValues call does so
     201             : 
     202             :             @throws ::com::sun::star::lang::IllegalArgumentException
     203             :                 if the XMultiPropertySet::setPropertyValues call does so
     204             : 
     205             :             @throws ::com::sun::star::lang::WrappedTargetException
     206             :                 if the XMultiPropertySet::setPropertyValues call does so
     207             : 
     208             :             @throws ::com::sun::star::uno::RuntimeException
     209             :                 if the XMultiPropertySet::setPropertyValues call does so
     210             : 
     211             :             @throws ::com::sun::star::beans::UnknownPropertyException
     212             :                 if the XMultiPropertySet::setPropertyValues call does so, and <arg>_bTolerateUnknownProperties</arg>
     213             :                 was set to <FALSE/>
     214             : 
     215             :             @throws ::com::sun::star::lang::WrappedTargetException
     216             :                 if the XMultiPropertySet::setPropertyValues call did throw an exception not listed
     217             :                 above
     218             :         */
     219             :         void impl_setPropertyValues_throw( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rProps );
     220             : 
     221             :     protected:
     222             :         using ::cppu::OPropertySetHelper::getPropertyValues;
     223             :         using ::cppu::OPropertySetHelper::setPropertyValues;
     224             :         using ::cppu::OPropertySetHelper::getFastPropertyValue;
     225             :     };
     226             : 
     227             : 
     228             : } // namespace comphelper
     229             : 
     230             : 
     231             : #endif // INCLUDED_COMPHELPER_SOURCE_PROPERTY_OPROPERTYBAG_HXX
     232             : 
     233             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11