LibreOffice Module comphelper (master)  1
opropertybag.hxx
Go to the documentation of this file.
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/XServiceInfo.hpp>
25 #include <com/sun/star/util/XModifiable.hpp>
26 #include <com/sun/star/beans/XPropertyBag.hpp>
27 #include <com/sun/star/container/XSet.hpp>
28 
29 #include <cppuhelper/implbase5.hxx>
31 #include <comphelper/propstate.hxx>
34 #include <comphelper/uno3.hxx>
35 
36 #include <map>
37 #include <set>
38 #include <memory>
39 
40 
41 namespace comphelper
42 {
43 
44 
45  struct UnoTypeLess
46  {
47  bool operator()( const css::uno::Type& _rLHS, const css::uno::Type& _rRHS ) const
48  {
49  return rtl_ustr_compare(
50  _rLHS.getTypeLibType()->pTypeName->buffer,
51  _rRHS.getTypeLibType()->pTypeName->buffer
52  ) < 0;
53  }
54  };
55 
56  typedef std::map< sal_Int32, css::uno::Any > MapInt2Any;
57  typedef std::set< css::uno::Type, UnoTypeLess > TypeBag;
58 
59  typedef ::cppu::WeakAggImplHelper5 < css::beans::XPropertyBag
60  , css::util::XModifiable
61  , css::lang::XServiceInfo
62  , css::lang::XInitialization
63  , css::container::XSet
65  typedef ::comphelper::OPropertyStateHelper OPropertyBag_PBase;
66 
67  class OPropertyBag final : public ::comphelper::OMutexAndBroadcastHelper // must be before OPropertyBag_PBase
68  ,public OPropertyBag_PBase
69  ,public OPropertyBag_Base
71  {
72  private:
74  std::unique_ptr< ::cppu::OPropertyArrayHelper >
79  TypeBag m_aAllowedTypes;
82 
87 
88  public:
89  //noncopyable
90  OPropertyBag(const OPropertyBag&) = delete;
91  const OPropertyBag& operator=(const OPropertyBag&) = delete;
92  OPropertyBag();
93  virtual ~OPropertyBag() override;
94 
95  private:
98 
100  // XInitialization
101  virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
102 
103  // XServiceInfo
104  virtual OUString SAL_CALL getImplementationName( ) override;
105  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
106  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
107 
108  // XModifiable:
109  virtual sal_Bool SAL_CALL isModified( ) override;
110  virtual void SAL_CALL setModified( sal_Bool bModified ) override;
111 
112  // XModifyBroadcaster
113  virtual void SAL_CALL addModifyListener(
114  const css::uno::Reference<
115  css::util::XModifyListener > & xListener) override;
116  virtual void SAL_CALL removeModifyListener(
117  const css::uno::Reference<
118  css::util::XModifyListener > & xListener) override;
119 
120  // XPropertyContainer
121  virtual void SAL_CALL addProperty( const OUString& Name, ::sal_Int16 Attributes, const css::uno::Any& DefaultValue ) override;
122  virtual void SAL_CALL removeProperty( const OUString& Name ) override;
123 
124  // XPropertyAccess
125  virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getPropertyValues( ) override;
126  virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& aProps ) override;
127 
128  // XPropertySet
129  virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
130  virtual void SAL_CALL setPropertyValue(const OUString& p1, const css::uno::Any& p2) override
132  virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& p1) override
134  virtual void SAL_CALL addPropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2) override
136  virtual void SAL_CALL removePropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2) override
138  virtual void SAL_CALL addVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2) override
140  virtual void SAL_CALL removeVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2) override
142 
143  // XSet
144  virtual sal_Bool SAL_CALL has( const css::uno::Any& aElement ) override;
145  virtual void SAL_CALL insert( const css::uno::Any& aElement ) override;
146  virtual void SAL_CALL remove( const css::uno::Any& aElement ) override;
147 
148  // XEnumerationAccess (base of XSet)
149  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) override;
150 
151  // XElementAccess (base of XEnumerationAccess)
152  virtual css::uno::Type SAL_CALL getElementType( ) override;
153  virtual sal_Bool SAL_CALL hasElements( ) override;
154  // UNO interface implementations
155 
156  // XPropertyState
157  virtual css::uno::Any getPropertyDefaultByHandle( sal_Int32 _nHandle ) const override;
158 
159  // OPropertyStateHelper
160  virtual css::beans::PropertyState getPropertyStateByHandle( sal_Int32 _nHandle ) override;
161 
162  // OPropertySetHelper
163  virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nHandle ) const override;
164  virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any & rConvertedValue, css::uno::Any & rOldValue, sal_Int32 nHandle, const css::uno::Any& rValue ) override;
165  virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override;
166  virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
167 
168  // IEventNotificationHook
169  virtual void fireEvents(
170  sal_Int32 * pnHandles,
171  sal_Int32 nCount,
172  sal_Bool bVetoable,
173  bool bIgnoreRuntimeExceptionsWhileFiring) override;
174 
175  void setModifiedImpl( bool bModified,
176  bool bIgnoreRuntimeExceptionsWhileFiring);
177 
182  sal_Int32 findFreeHandle() const;
183 
208  void impl_setPropertyValues_throw( const css::uno::Sequence< css::beans::PropertyValue >& _rProps );
209 
210  using ::cppu::OPropertySetHelper::getPropertyValues;
211  using ::cppu::OPropertySetHelper::setPropertyValues;
212  using ::cppu::OPropertySetHelper::getFastPropertyValue;
213  };
214 
215 
216 } // namespace comphelper
217 
218 
219 #endif // INCLUDED_COMPHELPER_SOURCE_PROPERTY_OPROPERTYBAG_HXX
220 
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL removeVetoableChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) SAL_OVERRIDE
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual void SAL_CALL addProperty(const OUString &Name,::sal_Int16 Attributes, const css::uno::Any &DefaultValue) override
virtual void fireEvents(sal_Int32 *pnHandles, sal_Int32 nCount, sal_Bool bVetoable, bool bIgnoreRuntimeExceptionsWhileFiring) override
void setModifiedImpl(bool bModified, bool bIgnoreRuntimeExceptionsWhileFiring)
::comphelper::OInterfaceContainerHelper2 m_NotifyListeners
for notification
virtual void SAL_CALL removePropertyChangeListener(const OUString &p1, const css::uno::Reference< css::beans::XPropertyChangeListener > &p2) override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
=== begin UNO interface implementations ==
virtual css::uno::Any SAL_CALL getPropertyValue(const ::rtl::OUString &aPropertyName) SAL_OVERRIDE
virtual void SAL_CALL removeVetoableChangeListener(const OUString &p1, const css::uno::Reference< css::beans::XVetoableChangeListener > &p2) override
::comphelper::OPropertyStateHelper OPropertyBag_PBase
::comphelper::PropertyBag m_aDynamicProperties
virtual css::uno::Any getPropertyDefaultByHandle(sal_Int32 _nHandle) const override
virtual ~OPropertyBag() override
virtual void SAL_CALL setPropertyValue(const ::rtl::OUString &rPropertyName, const css::uno::Any &aValue) SAL_OVERRIDE
virtual void SAL_CALL insert(const css::uno::Any &aElement) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual void SAL_CALL addPropertyChangeListener(const OUString &p1, const css::uno::Reference< css::beans::XPropertyChangeListener > &p2) override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &xListener) override
provides a bag of properties associated with their values
Definition: propertybag.hxx:42
virtual void SAL_CALL setModified(sal_Bool bModified) override
std::unique_ptr< ::cppu::OPropertyArrayHelper > m_pArrayHelper
our IPropertyArrayHelper implementation
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL removeProperty(const OUString &Name) override
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &aProps) override
#define DECLARE_XTYPEPROVIDER()
Definition: uno3.hxx:126
virtual sal_Bool SAL_CALL hasElements() override
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &xListener) override
unsigned char sal_Bool
virtual css::beans::PropertyState getPropertyStateByHandle(sal_Int32 _nHandle) override
TypeBag m_aAllowedTypes
set of allowed property types
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &p1) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
sal_Int32 findFreeHandle() const
finds a free property handle our mutex is locked
virtual sal_Bool SAL_CALL isModified() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
const OPropertyBag & operator=(const OPropertyBag &)=delete
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &p1, const css::uno::Reference< css::beans::XVetoableChangeListener > &p2) override
void impl_setPropertyValues_throw(const css::uno::Sequence< css::beans::PropertyValue > &_rProps)
implements the setPropertyValues method
bool m_bAutoAddProperties
should we automatically add properties which are tried to set, if they don't exist previously...
virtual sal_Bool SAL_CALL has(const css::uno::Any &aElement) override
virtual void SAL_CALL addPropertyChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) SAL_OVERRIDE
virtual void SAL_CALL setPropertyValue(const OUString &p1, const css::uno::Any &p2) override
bool operator()(const css::uno::Type &_rLHS, const css::uno::Type &_rRHS) const
bool m_isModified
modify flag
::cppu::WeakAggImplHelper5< css::beans::XPropertyBag, css::util::XModifiable, css::lang::XServiceInfo, css::lang::XInitialization, css::container::XSet > OPropertyBag_Base
virtual void SAL_CALL removePropertyChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) SAL_OVERRIDE
std::map< sal_Int32, css::uno::Any > MapInt2Any
virtual css::uno::Type SAL_CALL getElementType() override
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getPropertyValues() override
std::set< css::uno::Type, UnoTypeLess > TypeBag
#define DECLARE_XINTERFACE()
Definition: uno3.hxx:90
virtual void SAL_CALL addVetoableChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) SAL_OVERRIDE