1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_COMPHELPER_PROPERTYCONTAINERHELPER_HXX
21 #define INCLUDED_COMPHELPER_PROPERTYCONTAINERHELPER_HXX
23 #include <com/sun/star/uno/Type.hxx>
24 #include <com/sun/star/beans/Property.hpp>
26 #include <comphelper/comphelperdllapi.h>
33 // infos about one single property
34 struct COMPHELPER_DLLPUBLIC PropertyDescription
36 // the possibilities where a property holding object may be located
37 enum class LocationType
39 DerivedClassRealType
, // within the derived class, it's a "real" (non-Any) type
40 DerivedClassAnyType
, // within the derived class, it's a com.sun.star.uno::Any
41 HoldMyself
// within m_aHoldProperties
43 // the location of an object holding a property value :
46 void* pDerivedClassMember
; // a pointer to a member of an object of a derived class
47 sal_Int32 nOwnClassVectorIndex
; // an index within m_aHoldProperties
50 css::beans::Property aProperty
;
51 LocationType eLocated
; // where is the object containing the value located ?
52 LocationAccess aLocation
; // access to the property value
55 :aProperty( OUString(), -1, css::uno::Type(), 0 )
56 ,eLocated( LocationType::HoldMyself
)
58 aLocation
.nOwnClassVectorIndex
= -1;
63 //= OPropertyContainerHelper
65 /** helper class for managing property values, and implementing most of the X*Property* interfaces
67 The property values are usually held in derived classes, but can also be given to the
68 responsibility of this class here.
70 For more information, see http://wiki.openoffice.org/wiki/Development/Cpp/Helper/PropertyContainerHelper.
72 class COMPHELPER_DLLPUBLIC OPropertyContainerHelper
74 typedef ::std::vector
< css::uno::Any
> PropertyContainer
;
75 PropertyContainer m_aHoldProperties
;
76 // the properties which are hold by this class' instance, not the derived one's
79 typedef ::std::vector
< PropertyDescription
> Properties
;
80 typedef Properties::iterator PropertiesIterator
;
81 typedef Properties::const_iterator ConstPropertiesIterator
;
82 Properties m_aProperties
;
85 OPropertyContainerHelper();
86 ~OPropertyContainerHelper();
88 /** register a property. The property is represented through a member of the derived class which calls
90 @param _rName the name of the property
91 @param _nHandle the handle of the property
92 @param _nAttributes the attributes of the property
93 @param _pPointerToMember the pointer to the member representing the property
94 within the derived class.
95 @param _rMemberType the cppu type of the property represented by the object
96 to which _pPointerToMember points.
98 void registerProperty(const OUString
& _rName
, sal_Int32 _nHandle
, sal_Int32 _nAttributes
,
99 void* _pPointerToMember
, const css::uno::Type
& _rMemberType
);
102 /** register a property. The property is represented through a css::uno::Any member of the
103 derived class which calls this method.
104 @param _rName the name of the property
105 @param _nHandle the handle of the property
106 @param _nAttributes the attributes of the property
107 @param _pPointerToMember the pointer to the member representing the property
108 within the derived class, which has to be a css::uno::Any.
109 @param _rExpectedType the expected type of the property. NOT the type of the object to which
110 _pPointerToMember points (this is always an Any).
112 void registerMayBeVoidProperty(const OUString
& _rName
, sal_Int32 _nHandle
, sal_Int32 _nAttributes
,
113 css::uno::Any
* _pPointerToMember
, const css::uno::Type
& _rExpectedType
);
115 /** register a property. The repository will create an own object holding this property, so there is no
116 need to declare an extra member in your derived class
117 @param _rName the name of the property
118 @param _nHandle the handle of the property
119 @param _nAttributes the attributes of the property
120 @param _rType the type of the property
121 @param _pInitialValue the initial value of the property. May be void if _nAttributes includes
122 the css::beans::PropertyAttribute::MAYBEVOID flag.
123 Else it must contain a value compatible with the type described by _rType.
125 void registerPropertyNoMember(const OUString
& _rName
, sal_Int32 _nHandle
, sal_Int32 _nAttributes
,
126 const css::uno::Type
& _rType
, css::uno::Any
const & _pInitialValue
);
128 /** revokes a previously registered property
129 @throw css::beans::UnknownPropertyException
130 if no property with the given handle is registered
132 void revokeProperty( sal_Int32 _nHandle
);
135 /// checks whether a property with the given handle has been registered
136 bool isRegisteredProperty( sal_Int32 _nHandle
) const;
138 /// checks whether a property with the given name has been registered
139 bool isRegisteredProperty( const OUString
& _rName
) const;
142 // helper for implementing OPropertySetHelper overridables
143 bool convertFastPropertyValue(
144 css::uno::Any
& rConvertedValue
,
145 css::uno::Any
& rOldValue
,
147 const css::uno::Any
& rValue
150 void setFastPropertyValue(
152 const css::uno::Any
& rValue
155 void getFastPropertyValue(
156 css::uno::Any
& rValue
,
161 /** appends the descriptions of all properties which were registered 'til that moment to the given sequence,
162 keeping the array sorted (by name)
164 the given sequence is already sorted by name
166 initial property sequence which is to be extended
168 void describeProperties(css::uno::Sequence
< css::beans::Property
>& /* [out] */ _rProps
) const;
170 /** retrieves the description for a registered property
171 @throw css::beans::UnknownPropertyException
172 if no property with the given name is registered
174 const css::beans::Property
&
175 getProperty( const OUString
& _rName
) const;
178 /// insertion of _rProp into m_aProperties, keeping the sort order
179 COMPHELPER_DLLPRIVATE
void implPushBackProperty(const PropertyDescription
& _rProp
);
181 /// search the PropertyDescription for the given handle (within m_aProperties)
182 COMPHELPER_DLLPRIVATE PropertiesIterator
searchHandle(sal_Int32 _nHandle
);
185 OPropertyContainerHelper( const OPropertyContainerHelper
& ) = delete;
186 OPropertyContainerHelper
& operator=( const OPropertyContainerHelper
& ) = delete;
190 } // namespace comphelper
193 #endif // INCLUDED_COMPHELPER_PROPERTYCONTAINERHELPER_HXX
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */