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_PROPERTYBAG_HXX
21 #define INCLUDED_COMPHELPER_PROPERTYBAG_HXX
23 #include <comphelper/comphelperdllapi.h>
24 #include <comphelper/propertycontainerhelper.hxx>
33 struct PropertyBag_Impl
;
37 /** provides a bag of properties associated with their values
39 This class can, for instance, be used for components which need to implement
40 the com.sun.star.beans.PropertyBag service.
42 class COMPHELPER_DLLPUBLIC PropertyBag
: protected OPropertyContainerHelper
45 ::std::unique_ptr
< PropertyBag_Impl
> m_pImpl
;
49 virtual ~PropertyBag();
51 /** allow adding property with empty string as name
52 (by default, such names are rejected with IllegalActionException).
54 iff true, empty property name will be allowed
56 void setAllowEmptyPropertyName(bool i_isAllowed
);
58 /** adds a property to the bag
60 The type of the property is determined from its initial value (<code>_rInitialValue</code>).
63 the name of the new property. Must not be empty unless
64 explicitly allowed with setAllowEmptyPropertyName.
66 the handle of the new property
68 the attributes of the property
70 the initial value of the property. Must not be <NULL/>, to allow
71 determining the property type.
73 @throws css::beans::IllegalTypeException
74 if the initial value is <NULL/>
75 @throws css::beans::PropertyExistException
76 if the name or the handle are already used
77 @throws css::beans::IllegalArgumentException
81 const OUString
& _rName
,
83 sal_Int32 _nAttributes
,
84 const css::uno::Any
& _rInitialValue
87 /** adds a property to the bag
89 The initial value of the property is <NULL/>.
92 the name of the new property. Must not be empty unless
93 explicitly allowed with setAllowEmptyPropertyName.
95 the type of the new property
97 the handle of the new property
99 the attributes of the property
101 @throws css::beans::IllegalTypeException
102 if the initial value is <NULL/>
103 @throws css::beans::PropertyExistException
104 if the name or the handle are already used
105 @throws css::beans::IllegalArgumentException
108 void addVoidProperty(
109 const OUString
& _rName
,
110 const css::uno::Type
& _rType
,
112 sal_Int32 _nAttributes
115 /** removes a property from the bag
117 the name of the to-be-removed property.
118 @throws UnknownPropertyException
119 if the bag does not contain a property with the given name
120 @throws NotRemoveableException
121 if the property with the given name is not removable, as indicated
122 by the property attributes used in a previous <code>addProperty</code>
126 const OUString
& _rName
129 /** describes all properties in the bag
131 takes, upon return, the descriptions of all properties in the bag
133 void describeProperties(
134 css::uno::Sequence
< css::beans::Property
>& _out_rProps
137 OPropertyContainerHelper::describeProperties( _out_rProps
);
140 /** retrieves the value of a property given by handle
142 the handle of the property whose value is to be retrieved
144 output parameter taking the property value
145 @throws UnknownPropertyException
146 if the given handle does not denote a property in the bag
148 void getFastPropertyValue(
150 css::uno::Any
& _out_rValue
153 /** converts a to-be-set value of a property (given by handle) so that it can
154 be used in subsequent calls to setFastPropertyValue
156 the handle of the property
158 the new value, which should be converted
159 @param _out_rConvertedValue
160 output parameter taking the converted value
161 @param _out_rCurrentValue
162 output parameter taking the current value of the
164 @throws UnknownPropertyException
165 if the given handle does not denote a property in the bag
166 @throws IllegalArgumentException
167 if the given value cannot be lossless converted into a value
168 for the given property.
170 bool convertFastPropertyValue(
172 const css::uno::Any
& _rNewValue
,
173 css::uno::Any
& _out_rConvertedValue
,
174 css::uno::Any
& _out_rCurrentValue
177 /** sets a new value for a property given by handle
178 @throws UnknownPropertyException
179 if the given handle does not denote a property in the bag
181 void setFastPropertyValue(
183 const css::uno::Any
& _rValue
186 /** returns the default value for a property given by handle
188 The default value of a property is its initial value, as passed
192 handle of the property whose default value is to be obtained
195 @throws UnknownPropertyException
196 if the given handle does not denote a property in the bag
198 void getPropertyDefaultByHandle(
200 css::uno::Any
& _out_rValue
203 /** determines whether a property with a given name is part of the bag
205 bool hasPropertyByName( const OUString
& _rName
) const
207 return isRegisteredProperty( _rName
);
210 /** determines whether a property with a given handle is part of the bag
212 bool hasPropertyByHandle( sal_Int32 _nHandle
) const
214 return isRegisteredProperty( _nHandle
);
217 using OPropertyContainerHelper::convertFastPropertyValue
;
218 using OPropertyContainerHelper::getFastPropertyValue
;
222 } // namespace comphelper
225 #endif // INCLUDED_COMPHELPER_PROPERTYBAG_HXX
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */