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_PROPERTYCONTAINERHELPER_HXX
21 : #define INCLUDED_COMPHELPER_PROPERTYCONTAINERHELPER_HXX
22 :
23 : #include <cppuhelper/propshlp.hxx>
24 : #include <com/sun/star/uno/Type.hxx>
25 : #include <com/sun/star/beans/Property.hpp>
26 : #include <vector>
27 : #include <comphelper/comphelperdllapi.h>
28 :
29 :
30 : namespace comphelper
31 : {
32 :
33 :
34 : // infos about one single property
35 2697970 : struct COMPHELPER_DLLPUBLIC PropertyDescription
36 : {
37 : // the possibilities where a property holding object may be located
38 : enum LocationType
39 : {
40 : ltDerivedClassRealType, // within the derived class, it's a "real" (non-Any) type
41 : ltDerivedClassAnyType, // within the derived class, it's a com.sun.star.uno::Any
42 : ltHoldMyself // within m_aHoldProperties
43 : };
44 : // the location of an object holding a property value :
45 : union LocationAccess
46 : {
47 : void* pDerivedClassMember; // a pointer to a member of an object of a derived class
48 : sal_Int32 nOwnClassVectorIndex; // an index within m_aHoldProperties
49 : };
50 :
51 : ::com::sun::star::beans::Property
52 : aProperty;
53 : LocationType eLocated; // where is the object containing the value located ?
54 : LocationAccess aLocation; // access to the property value
55 :
56 1127749 : PropertyDescription()
57 : :aProperty( OUString(), -1, ::com::sun::star::uno::Type(), 0 )
58 1127749 : ,eLocated( ltHoldMyself )
59 : {
60 1127749 : aLocation.nOwnClassVectorIndex = -1;
61 1127749 : }
62 : };
63 :
64 :
65 : //= OPropertyContainerHelper
66 :
67 : /** helper class for managing property values, and implementing most of the X*Property* interfaces
68 :
69 : The property values are usually held in derived classes, but can also be given to the
70 : responsibility of this class here.
71 :
72 : For more information, see http://wiki.openoffice.org/wiki/Development/Cpp/Helper/PropertyContainerHelper.
73 : */
74 : class COMPHELPER_DLLPUBLIC OPropertyContainerHelper
75 : {
76 : typedef ::std::vector< ::com::sun::star::uno::Any > PropertyContainer;
77 : typedef PropertyContainer::iterator PropertyContainerIterator;
78 : typedef PropertyContainer::const_iterator ConstPropertyContainerIterator;
79 : PropertyContainer m_aHoldProperties;
80 : // the properties which are hold by this class' instance, not the derived one's
81 :
82 : private:
83 : typedef ::std::vector< PropertyDescription > Properties;
84 : typedef Properties::iterator PropertiesIterator;
85 : typedef Properties::const_iterator ConstPropertiesIterator;
86 : Properties m_aProperties;
87 :
88 : protected:
89 : OPropertyContainerHelper();
90 : ~OPropertyContainerHelper();
91 :
92 : /** register a property. The property is represented through a member of the derived class which calls
93 : this methdod.
94 : @param _rName the name of the property
95 : @param _nHandle the handle of the property
96 : @param _nAttributes the attributes of the property
97 : @param _pPointerToMember the pointer to the member representing the property
98 : within the derived class.
99 : @param _rMemberType the cppu type of the property represented by the object
100 : to which _pPointerToMember points.
101 : */
102 : void registerProperty(const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes,
103 : void* _pPointerToMember, const ::com::sun::star::uno::Type& _rMemberType);
104 :
105 :
106 : /** register a property. The property is represented through a ::com::sun::star::uno::Any member of the
107 : derived class which calls this methdod.
108 : @param _rName the name of the property
109 : @param _nHandle the handle of the property
110 : @param _nAttributes the attributes of the property
111 : @param _pPointerToMember the pointer to the member representing the property
112 : within the derived class, which has to be a ::com::sun::star::uno::Any.
113 : @param _rExpectedType the expected type of the property. NOT the type of the object to which
114 : _pPointerToMember points (this is always an Any).
115 : */
116 : void registerMayBeVoidProperty(const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes,
117 : ::com::sun::star::uno::Any* _pPointerToMember, const ::com::sun::star::uno::Type& _rExpectedType);
118 :
119 : /** register a property. The repository will create an own object holding this property, so there is no
120 : need to declare an extra member in your derived class
121 : @param _rName the name of the property
122 : @param _nHandle the handle of the property
123 : @param _nAttributes the attributes of the property
124 : @param _rType the type of the property
125 : @param _pInitialValue the initial value of the property. May be null if _nAttributes includes
126 : the ::com::sun::star::beans::PropertyAttribute::MAYBEVOID flag.
127 : Else it must be a pointer to an object of the type described by _rType.
128 : */
129 : void registerPropertyNoMember(const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes,
130 : const ::com::sun::star::uno::Type& _rType, const void* _pInitialValue);
131 :
132 : /** revokes a previously registered property
133 : @throw com::sun::star::beans::UnknownPropertyException
134 : if no property with the given handle is registered
135 : */
136 : void revokeProperty( sal_Int32 _nHandle );
137 :
138 :
139 : /// checkes whether a property with the given handle has been registered
140 : bool isRegisteredProperty( sal_Int32 _nHandle ) const;
141 :
142 : /// checkes whether a property with the given name has been registered
143 : bool isRegisteredProperty( const OUString& _rName ) const;
144 :
145 :
146 : // helper for implementing OPropertySetHelper overridables
147 : bool convertFastPropertyValue(
148 : ::com::sun::star::uno::Any & rConvertedValue,
149 : ::com::sun::star::uno::Any & rOldValue,
150 : sal_Int32 nHandle,
151 : const ::com::sun::star::uno::Any& rValue
152 : );
153 :
154 : bool setFastPropertyValue(
155 : sal_Int32 nHandle,
156 : const ::com::sun::star::uno::Any& rValue
157 : );
158 :
159 : void getFastPropertyValue(
160 : ::com::sun::star::uno::Any& rValue,
161 : sal_Int32 nHandle
162 : ) const;
163 :
164 : // helper
165 : /** appends the descriptions of all properties which were registered 'til that moment to the given sequence,
166 : keeping the array sorted (by name)
167 : @precond
168 : the given sequence is already sorted by name
169 : @param _rProps
170 : initial property sequence which is to be extended
171 : */
172 : void describeProperties(::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps) const;
173 :
174 : /** retrieves the description for a registered property
175 : @throw com::sun::star::beans::UnknownPropertyException
176 : if no property with the given name is registered
177 : */
178 : const ::com::sun::star::beans::Property&
179 : getProperty( const OUString& _rName ) const;
180 :
181 : private:
182 : /// insertion of _rProp into m_aProperties, keeping the sort order
183 : COMPHELPER_DLLPRIVATE void implPushBackProperty(const PropertyDescription& _rProp);
184 :
185 : /// search the PropertyDescription for the given handle (within m_aProperties)
186 : COMPHELPER_DLLPRIVATE PropertiesIterator searchHandle(sal_Int32 _nHandle);
187 :
188 : private:
189 : OPropertyContainerHelper( const OPropertyContainerHelper& ) SAL_DELETED_FUNCTION;
190 : OPropertyContainerHelper& operator=( const OPropertyContainerHelper& ) SAL_DELETED_FUNCTION;
191 : };
192 :
193 :
194 : } // namespace comphelper
195 :
196 :
197 : #endif // INCLUDED_COMPHELPER_PROPERTYCONTAINERHELPER_HXX
198 :
199 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|