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