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 <config_options.h>
24 #include <com/sun/star/uno/Any.h>
25 #include <comphelper/comphelperdllapi.h>
26 #include <comphelper/propertycontainerhelper.hxx>
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 UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC
) PropertyBag final
: protected OPropertyContainerHelper
44 std::map
< sal_Int32
, css::uno::Any
> aDefaults
;
45 bool m_bAllowEmptyPropertyName
;
48 virtual ~PropertyBag();
50 /** allow adding property with empty string as name
51 (by default, such names are rejected with IllegalActionException).
53 iff true, empty property name will be allowed
55 void setAllowEmptyPropertyName(bool i_isAllowed
);
57 /** adds a property to the bag
59 The type of the property is determined from its initial value (<code>_rInitialValue</code>).
62 the name of the new property. Must not be empty unless
63 explicitly allowed with setAllowEmptyPropertyName.
65 the handle of the new property
67 the attributes of the property
69 the initial value of the property. Must not be <NULL/>, to allow
70 determining the property type.
72 @throws css::beans::IllegalTypeException
73 if the initial value is <NULL/>
74 @throws css::beans::PropertyExistException
75 if the name or the handle are already used
76 @throws css::beans::IllegalArgumentException
80 const OUString
& _rName
,
82 sal_Int32 _nAttributes
,
83 const css::uno::Any
& _rInitialValue
86 /** adds a property to the bag
88 The initial value of the property is <NULL/>.
91 the name of the new property. Must not be empty unless
92 explicitly allowed with setAllowEmptyPropertyName.
94 the type of the new property
96 the handle of the new property
98 the attributes of the property
100 @throws css::beans::IllegalTypeException
101 if the initial value is <NULL/>
102 @throws css::beans::PropertyExistException
103 if the name or the handle are already used
104 @throws css::beans::IllegalArgumentException
107 void addVoidProperty(
108 const OUString
& _rName
,
109 const css::uno::Type
& _rType
,
111 sal_Int32 _nAttributes
114 /** removes a property from the bag
116 the name of the to-be-removed property.
117 @throws UnknownPropertyException
118 if the bag does not contain a property with the given name
119 @throws NotRemoveableException
120 if the property with the given name is not removable, as indicated
121 by the property attributes used in a previous <code>addProperty</code>
125 const OUString
& _rName
128 /** describes all properties in the bag
130 takes, upon return, the descriptions of all properties in the bag
132 void describeProperties(
133 css::uno::Sequence
< css::beans::Property
>& _out_rProps
136 OPropertyContainerHelper::describeProperties( _out_rProps
);
139 /** retrieves the value of a property given by handle
141 the handle of the property whose value is to be retrieved
143 output parameter taking the property value
144 @throws UnknownPropertyException
145 if the given handle does not denote a property in the bag
147 void getFastPropertyValue(
149 css::uno::Any
& _out_rValue
152 /** converts a to-be-set value of a property (given by handle) so that it can
153 be used in subsequent calls to setFastPropertyValue
155 the handle of the property
157 the new value, which should be converted
158 @param _out_rConvertedValue
159 output parameter taking the converted value
160 @param _out_rCurrentValue
161 output parameter taking the current value of the
163 @throws UnknownPropertyException
164 if the given handle does not denote a property in the bag
165 @throws IllegalArgumentException
166 if the given value cannot be lossless converted into a value
167 for the given property.
169 bool convertFastPropertyValue(
171 const css::uno::Any
& _rNewValue
,
172 css::uno::Any
& _out_rConvertedValue
,
173 css::uno::Any
& _out_rCurrentValue
176 /** sets a new value for a property given by handle
177 @throws UnknownPropertyException
178 if the given handle does not denote a property in the bag
180 void setFastPropertyValue(
182 const css::uno::Any
& _rValue
185 /** returns the default value for a property given by handle
187 The default value of a property is its initial value, as passed
191 handle of the property whose default value is to be obtained
194 @throws UnknownPropertyException
195 if the given handle does not denote a property in the bag
197 void getPropertyDefaultByHandle(
199 css::uno::Any
& _out_rValue
202 /** determines whether a property with a given name is part of the bag
204 bool hasPropertyByName( const OUString
& _rName
) const
206 return isRegisteredProperty( _rName
);
209 /** determines whether a property with a given handle is part of the bag
211 bool hasPropertyByHandle( sal_Int32 _nHandle
) const
213 return isRegisteredProperty( _nHandle
);
216 using OPropertyContainerHelper::convertFastPropertyValue
;
217 using OPropertyContainerHelper::getFastPropertyValue
;
221 } // namespace comphelper
224 #endif // INCLUDED_COMPHELPER_PROPERTYBAG_HXX
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */