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