1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_COMPHELPER_PROPERTYBAG_HXX
#define INCLUDED_COMPHELPER_PROPERTYBAG_HXX
#include <comphelper/comphelperdllapi.h>
#include <comphelper/propertycontainerhelper.hxx>
#include <memory>
namespace comphelper
{
struct PropertyBag_Impl;
//= PropertyBag
/** provides a bag of properties associated with their values
This class can, for instance, be used for components which need to implement
the com.sun.star.beans.PropertyBag service.
*/
class COMPHELPER_DLLPUBLIC PropertyBag : protected OPropertyContainerHelper
{
private:
::std::unique_ptr< PropertyBag_Impl > m_pImpl;
public:
PropertyBag();
virtual ~PropertyBag();
/** allow adding property with empty string as name
(by default, such names are rejected with IllegalActionException).
@param i_isAllowed
iff true, empty property name will be allowed
*/
void setAllowEmptyPropertyName(bool i_isAllowed);
/** adds a property to the bag
The type of the property is determined from its initial value (<code>_rInitialValue</code>).
@param _rName
the name of the new property. Must not be empty unless
explicitly allowed with setAllowEmptyPropertyName.
@param _nHandle
the handle of the new property
@param _nAttributes
the attributes of the property
@param _rInitialValue
the initial value of the property. Must not be <NULL/>, to allow
determining the property type.
@throws css::beans::IllegalTypeException
if the initial value is <NULL/>
@throws css::beans::PropertyExistException
if the name or the handle are already used
@throws css::beans::IllegalArgumentException
if the name is empty
*/
void addProperty(
const OUString& _rName,
sal_Int32 _nHandle,
sal_Int32 _nAttributes,
const css::uno::Any& _rInitialValue
);
/** adds a property to the bag
The initial value of the property is <NULL/>.
@param _rName
the name of the new property. Must not be empty unless
explicitly allowed with setAllowEmptyPropertyName.
@param _rType
the type of the new property
@param _nHandle
the handle of the new property
@param _nAttributes
the attributes of the property
@throws css::beans::IllegalTypeException
if the initial value is <NULL/>
@throws css::beans::PropertyExistException
if the name or the handle are already used
@throws css::beans::IllegalArgumentException
if the name is empty
*/
void addVoidProperty(
const OUString& _rName,
const css::uno::Type& _rType,
sal_Int32 _nHandle,
sal_Int32 _nAttributes
);
/** removes a property from the bag
@param _rName
the name of the to-be-removed property.
@throws UnknownPropertyException
if the bag does not contain a property with the given name
@throws NotRemoveableException
if the property with the given name is not removable, as indicated
by the property attributes used in a previous <code>addProperty</code>
call.
*/
void removeProperty(
const OUString& _rName
);
/** describes all properties in the bag
@param _out_rProps
takes, upon return, the descriptions of all properties in the bag
*/
void describeProperties(
css::uno::Sequence< css::beans::Property >& _out_rProps
) const
{
OPropertyContainerHelper::describeProperties( _out_rProps );
}
/** retrieves the value of a property given by handle
@param _nHandle
the handle of the property whose value is to be retrieved
@param _out_rValue
output parameter taking the property value
@throws UnknownPropertyException
if the given handle does not denote a property in the bag
*/
void getFastPropertyValue(
sal_Int32 _nHandle,
css::uno::Any& _out_rValue
) const;
/** converts a to-be-set value of a property (given by handle) so that it can
be used in subsequent calls to setFastPropertyValue
@param _nHandle
the handle of the property
@param _rNewValue
the new value, which should be converted
@param _out_rConvertedValue
output parameter taking the converted value
@param _out_rCurrentValue
output parameter taking the current value of the
property
@throws UnknownPropertyException
if the given handle does not denote a property in the bag
@throws IllegalArgumentException
if the given value cannot be lossless converted into a value
for the given property.
*/
bool convertFastPropertyValue(
sal_Int32 _nHandle,
const css::uno::Any& _rNewValue,
css::uno::Any& _out_rConvertedValue,
css::uno::Any& _out_rCurrentValue
) const;
/** sets a new value for a property given by handle
@throws UnknownPropertyException
if the given handle does not denote a property in the bag
*/
void setFastPropertyValue(
sal_Int32 _nHandle,
const css::uno::Any& _rValue
);
/** returns the default value for a property given by handle
The default value of a property is its initial value, as passed
to ->addProperty.
@param _nHandle
handle of the property whose default value is to be obtained
@param _out_rValue
the default value
@throws UnknownPropertyException
if the given handle does not denote a property in the bag
*/
void getPropertyDefaultByHandle(
sal_Int32 _nHandle,
css::uno::Any& _out_rValue
) const;
/** determines whether a property with a given name is part of the bag
*/
bool hasPropertyByName( const OUString& _rName ) const
{
return isRegisteredProperty( _rName );
}
/** determines whether a property with a given handle is part of the bag
*/
bool hasPropertyByHandle( sal_Int32 _nHandle ) const
{
return isRegisteredProperty( _nHandle );
}
protected:
using OPropertyContainerHelper::convertFastPropertyValue;
using OPropertyContainerHelper::getFastPropertyValue;
};
} // namespace comphelper
#endif // INCLUDED_COMPHELPER_PROPERTYBAG_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|