1*9877b273SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9877b273SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9877b273SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9877b273SAndrew Rist  * distributed with this work for additional information
6*9877b273SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9877b273SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9877b273SAndrew Rist  * "License"); you may not use this file except in compliance
9*9877b273SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9877b273SAndrew Rist  *
11*9877b273SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9877b273SAndrew Rist  *
13*9877b273SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9877b273SAndrew Rist  * software distributed under the License is distributed on an
15*9877b273SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9877b273SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9877b273SAndrew Rist  * specific language governing permissions and limitations
18*9877b273SAndrew Rist  * under the License.
19*9877b273SAndrew Rist  *
20*9877b273SAndrew Rist  *************************************************************/
21*9877b273SAndrew Rist 
22*9877b273SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef COMPHELPER_PROPERTYCONTAINERHELPER_HXX
25cdf0e10cSrcweir #define COMPHELPER_PROPERTYCONTAINERHELPER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <cppuhelper/propshlp.hxx>
28cdf0e10cSrcweir #include <com/sun/star/uno/Type.hxx>
29cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp>
30cdf0e10cSrcweir #ifndef __SGI_STL_VECTOR
31cdf0e10cSrcweir #include <vector>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include "comphelper/comphelperdllapi.h"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //.........................................................................
36cdf0e10cSrcweir namespace comphelper
37cdf0e10cSrcweir {
38cdf0e10cSrcweir //.........................................................................
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // infos about one single property
41cdf0e10cSrcweir struct COMPHELPER_DLLPUBLIC PropertyDescription
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     // the possibilities where a property holding object may be located
44cdf0e10cSrcweir     enum LocationType
45cdf0e10cSrcweir     {
46cdf0e10cSrcweir         ltDerivedClassRealType,     // within the derived class, it's a "real" (non-Any) type
47cdf0e10cSrcweir         ltDerivedClassAnyType,      // within the derived class, it's a <type scope="com.sun.star.uno">Any</type>
48cdf0e10cSrcweir         ltHoldMyself                // within m_aHoldProperties
49cdf0e10cSrcweir     };
50cdf0e10cSrcweir     // the location of an object holding a property value :
51cdf0e10cSrcweir     union LocationAccess
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir         void*       pDerivedClassMember;        // a pointer to a member of an object of a derived class
54cdf0e10cSrcweir         sal_Int32   nOwnClassVectorIndex;       // an index within m_aHoldProperties
55cdf0e10cSrcweir     };
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     ::com::sun::star::beans::Property
58cdf0e10cSrcweir                         aProperty;
59cdf0e10cSrcweir     LocationType        eLocated;       // where is the object containing the value located ?
60cdf0e10cSrcweir     LocationAccess      aLocation;      // access to the property value
61cdf0e10cSrcweir 
PropertyDescriptioncomphelper::PropertyDescription62cdf0e10cSrcweir     PropertyDescription()
63cdf0e10cSrcweir         :aProperty( ::rtl::OUString(), -1, ::com::sun::star::uno::Type(), 0 )
64cdf0e10cSrcweir         ,eLocated( ltHoldMyself )
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir         aLocation.nOwnClassVectorIndex = -1;
67cdf0e10cSrcweir     }
68cdf0e10cSrcweir };
69cdf0e10cSrcweir 
70cdf0e10cSrcweir //==========================================================================
71cdf0e10cSrcweir //= OPropertyContainerHelper
72cdf0e10cSrcweir //==========================================================================
73cdf0e10cSrcweir /** helper class for managing property values, and implementing most of the X*Property* interfaces
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     The property values are usually held in derived classes, but can also be given to the
76cdf0e10cSrcweir     responsibility of this class here.
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     For more information, see http://wiki.services.openoffice.org/wiki/Development/Cpp/Helper/PropertyContainerHelper.
79cdf0e10cSrcweir */
80cdf0e10cSrcweir class COMPHELPER_DLLPUBLIC OPropertyContainerHelper
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	typedef ::std::vector< ::com::sun::star::uno::Any >	PropertyContainer;
83cdf0e10cSrcweir 	typedef PropertyContainer::iterator					PropertyContainerIterator;
84cdf0e10cSrcweir 	typedef PropertyContainer::const_iterator			ConstPropertyContainerIterator;
85cdf0e10cSrcweir 	PropertyContainer	m_aHoldProperties;
86cdf0e10cSrcweir 		// the properties which are hold by this class' instance, not the derived one's
87cdf0e10cSrcweir 
88cdf0e10cSrcweir private:
89cdf0e10cSrcweir 	typedef ::std::vector< PropertyDescription >	Properties;
90cdf0e10cSrcweir 	typedef Properties::iterator					PropertiesIterator;
91cdf0e10cSrcweir 	typedef Properties::const_iterator				ConstPropertiesIterator;
92cdf0e10cSrcweir 	Properties		m_aProperties;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	sal_Bool		m_bUnused;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir protected:
97cdf0e10cSrcweir 	OPropertyContainerHelper();
98cdf0e10cSrcweir 	~OPropertyContainerHelper();
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	/** register a property. The property is represented through a member of the derived class which calls
101cdf0e10cSrcweir 		this methdod.
102cdf0e10cSrcweir 		@param		_rName				the name of the property
103cdf0e10cSrcweir 		@param		_nHandle			the handle of the property
104cdf0e10cSrcweir 		@param		_nAttributes		the attributes of the property
105cdf0e10cSrcweir 		@param		_pPointerToMember	the pointer to the member representing the property
106cdf0e10cSrcweir 										within the derived class.
107cdf0e10cSrcweir 		@param		_rMemberType		the cppu type of the property represented by the object
108cdf0e10cSrcweir 										to which _pPointerToMember points.
109cdf0e10cSrcweir 	*/
110cdf0e10cSrcweir 	void	registerProperty(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes,
111cdf0e10cSrcweir 		void* _pPointerToMember, const ::com::sun::star::uno::Type& _rMemberType);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	/** register a property. The property is represented through a ::com::sun::star::uno::Any member of the
115cdf0e10cSrcweir 		derived class which calls this methdod.
116cdf0e10cSrcweir 		@param		_rName				the name of the property
117cdf0e10cSrcweir 		@param		_nHandle			the handle of the property
118cdf0e10cSrcweir 		@param		_nAttributes		the attributes of the property
119cdf0e10cSrcweir 		@param		_pPointerToMember	the pointer to the member representing the property
120cdf0e10cSrcweir 										within the derived class, which has to be a ::com::sun::star::uno::Any.
121cdf0e10cSrcweir 		@param		_rExpectedType		the expected type of the property. NOT the type of the object to which
122cdf0e10cSrcweir 										_pPointerToMember points (this is always an Any).
123cdf0e10cSrcweir 	*/
124cdf0e10cSrcweir 	void	registerMayBeVoidProperty(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes,
125cdf0e10cSrcweir 		::com::sun::star::uno::Any* _pPointerToMember, const ::com::sun::star::uno::Type& _rExpectedType);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	/** register a property. The repository will create an own object holding this property, so there is no
128cdf0e10cSrcweir 		need to declare an extra member in your derived class
129cdf0e10cSrcweir 		@param		_rName				the name of the property
130cdf0e10cSrcweir 		@param		_nHandle			the handle of the property
131cdf0e10cSrcweir 		@param		_nAttributes		the attributes of the property
132cdf0e10cSrcweir 		@param		_rType				the type of the property
133cdf0e10cSrcweir 		@param		_pInitialValue		the initial value of the property. May be null if _nAttributes includes
134cdf0e10cSrcweir 										the ::com::sun::star::beans::PropertyAttribute::MAYBEVOID flag.
135cdf0e10cSrcweir 										Else it must be a pointer to an object of the type described by _rType.
136cdf0e10cSrcweir 	*/
137cdf0e10cSrcweir 	void	registerPropertyNoMember(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes,
138cdf0e10cSrcweir 		const ::com::sun::star::uno::Type& _rType, const void* _pInitialValue);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     /** revokes a previously registered property
141cdf0e10cSrcweir         @throw  com::sun::star::beans::UnknownPropertyException
142cdf0e10cSrcweir             if no property with the given handle is registered
143cdf0e10cSrcweir     */
144cdf0e10cSrcweir     void    revokeProperty( sal_Int32 _nHandle );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     /// checkes whether a property with the given handle has been registered
148cdf0e10cSrcweir     sal_Bool    isRegisteredProperty( sal_Int32 _nHandle ) const;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     /// checkes whether a property with the given name has been registered
151cdf0e10cSrcweir     sal_Bool    isRegisteredProperty( const ::rtl::OUString& _rName ) const;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     // helper for implementing OPropertySetHelper overridables
155cdf0e10cSrcweir 	sal_Bool    convertFastPropertyValue(
156cdf0e10cSrcweir 				    ::com::sun::star::uno::Any & rConvertedValue,
157cdf0e10cSrcweir 				    ::com::sun::star::uno::Any & rOldValue,
158cdf0e10cSrcweir 				    sal_Int32 nHandle,
159cdf0e10cSrcweir 				    const ::com::sun::star::uno::Any& rValue
160cdf0e10cSrcweir                 )
161cdf0e10cSrcweir                 SAL_THROW((::com::sun::star::lang::IllegalArgumentException));
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	void        setFastPropertyValue(
164cdf0e10cSrcweir                         sal_Int32 nHandle,
165cdf0e10cSrcweir                         const ::com::sun::star::uno::Any& rValue
166cdf0e10cSrcweir                     )
167cdf0e10cSrcweir 				    SAL_THROW((::com::sun::star::uno::Exception));
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	void        getFastPropertyValue(
170cdf0e10cSrcweir                         ::com::sun::star::uno::Any& rValue,
171cdf0e10cSrcweir                         sal_Int32 nHandle
172cdf0e10cSrcweir                     ) const;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir // helper
175cdf0e10cSrcweir 	/** appends the descriptions of all properties which were registered 'til that moment to the given sequence,
176cdf0e10cSrcweir 		keeping the array sorted (by name)
177cdf0e10cSrcweir         @precond
178cdf0e10cSrcweir             the given sequence is already sorted by name
179cdf0e10cSrcweir         @param  _rProps
180cdf0e10cSrcweir             initial property sequence which is to be extended
181cdf0e10cSrcweir 	*/
182cdf0e10cSrcweir 	void	describeProperties(::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps) const;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	/** modify the attributes of an already registered property.
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 		You may want to use this if you're a derived from OPropertyContainer indirectly and want to override
187cdf0e10cSrcweir 		some settings your base class did.
188cdf0e10cSrcweir 	*/
189cdf0e10cSrcweir 	void	modifyAttributes(sal_Int32 _nHandle, sal_Int32 _nAddAttrib, sal_Int32 _nRemoveAttrib);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     /** retrieves the description for a registered property
192cdf0e10cSrcweir         @throw  com::sun::star::beans::UnknownPropertyException
193cdf0e10cSrcweir             if no property with the given name is registered
194cdf0e10cSrcweir     */
195cdf0e10cSrcweir     const ::com::sun::star::beans::Property&
196cdf0e10cSrcweir             getProperty( const ::rtl::OUString& _rName ) const;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir private:
199cdf0e10cSrcweir 	/// insertion of _rProp into m_aProperties, keeping the sort order
200cdf0e10cSrcweir 	COMPHELPER_DLLPRIVATE void	implPushBackProperty(const PropertyDescription& _rProp);
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	/// search the PropertyDescription for the given handle (within m_aProperties)
203cdf0e10cSrcweir 	COMPHELPER_DLLPRIVATE PropertiesIterator	searchHandle(sal_Int32 _nHandle);
204cdf0e10cSrcweir 
205cdf0e10cSrcweir private:
206cdf0e10cSrcweir     COMPHELPER_DLLPRIVATE OPropertyContainerHelper( const OPropertyContainerHelper& );            // never implemented
207cdf0e10cSrcweir     COMPHELPER_DLLPRIVATE OPropertyContainerHelper& operator=( const OPropertyContainerHelper& ); // never implemented
208cdf0e10cSrcweir };
209cdf0e10cSrcweir 
210cdf0e10cSrcweir //.........................................................................
211cdf0e10cSrcweir }	// namespace comphelper
212cdf0e10cSrcweir //.........................................................................
213cdf0e10cSrcweir 
214cdf0e10cSrcweir #endif // COMPHELPER_PROPERTYCONTAINERHELPER_HXX
215