/usr/include/Poco/Util/AbstractConfiguration.h is in libpoco-dev 1.8.0.1-1ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | //
// AbstractConfiguration.h
//
// Library: Util
// Package: Configuration
// Module: AbstractConfiguration
//
// Definition of the AbstractConfiguration class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Util_AbstractConfiguration_INCLUDED
#define Util_AbstractConfiguration_INCLUDED
#include "Poco/Util/Util.h"
#include "Poco/Mutex.h"
#include "Poco/RefCountedObject.h"
#include "Poco/BasicEvent.h"
#include <vector>
#include <utility>
namespace Poco {
namespace Util {
class Util_API AbstractConfiguration: public Poco::RefCountedObject
/// AbstractConfiguration is an abstract base class for different
/// kinds of configuration data, such as INI files, property files,
/// XML configuration files or the Windows Registry.
///
/// Configuration property keys have a hierarchical format, consisting
/// of names separated by periods. The exact interpretation of key names
/// is up to the actual subclass implementation of AbstractConfiguration.
/// Keys are case sensitive.
///
/// All public methods are synchronized, so the class is safe for multithreaded use.
/// AbstractConfiguration implements reference counting based garbage collection.
///
/// Subclasses must override the getRaw(), setRaw() and enumerate() methods.
{
public:
typedef std::vector<std::string> Keys;
class KeyValue
/// A key-value pair, used as event argument.
{
public:
KeyValue(const std::string& key, std::string& value):
_key(key),
_value(value)
{
}
const std::string& key() const
{
return _key;
}
const std::string& value() const
{
return _value;
}
std::string& value()
{
return _value;
}
private:
const std::string& _key;
std::string& _value;
};
Poco::BasicEvent<KeyValue> propertyChanging;
/// Fired before a property value is changed or
/// a new property is created.
///
/// Can be used to check or fix a property value,
/// or to cancel the change by throwing an exception.
///
/// The event delegate can use one of the get...() functions
/// to obtain the current property value.
Poco::BasicEvent<const KeyValue> propertyChanged;
/// Fired after a property value has been changed
/// or a property has been created.
Poco::BasicEvent<const std::string> propertyRemoving;
/// Fired before a property is removed by a
/// call to remove().
///
/// Note: This will even be fired if the key
/// does not exist and the remove operation will
/// fail with an exception.
Poco::BasicEvent<const std::string> propertyRemoved;
/// Fired after a property has been removed by
/// a call to remove().
AbstractConfiguration();
/// Creates the AbstractConfiguration.
bool hasProperty(const std::string& key) const;
/// Returns true iff the property with the given key exists.
bool hasOption(const std::string& key) const;
/// Returns true iff the property with the given key exists.
///
/// Same as hasProperty().
bool has(const std::string& key) const;
/// Returns true iff the property with the given key exists.
///
/// Same as hasProperty().
std::string getString(const std::string& key) const;
/// Returns the string value of the property with the given name.
/// Throws a NotFoundException if the key does not exist.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
std::string getString(const std::string& key, const std::string& defaultValue) const;
/// If a property with the given key exists, returns the property's string value,
/// otherwise returns the given default value.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
std::string getRawString(const std::string& key) const;
/// Returns the raw string value of the property with the given name.
/// Throws a NotFoundException if the key does not exist.
/// References to other properties are not expanded.
std::string getRawString(const std::string& key, const std::string& defaultValue) const;
/// If a property with the given key exists, returns the property's raw string value,
/// otherwise returns the given default value.
/// References to other properties are not expanded.
int getInt(const std::string& key) const;
/// Returns the int value of the property with the given name.
/// Throws a NotFoundException if the key does not exist.
/// Throws a SyntaxException if the property can not be converted
/// to an int.
/// Numbers starting with 0x are treated as hexadecimal.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
unsigned int getUInt(const std::string& key) const;
/// Returns the unsigned int value of the property with the given name.
/// Throws a NotFoundException if the key does not exist.
/// Throws a SyntaxException if the property can not be converted
/// to an unsigned int.
/// Numbers starting with 0x are treated as hexadecimal.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
int getInt(const std::string& key, int defaultValue) const;
/// If a property with the given key exists, returns the property's int value,
/// otherwise returns the given default value.
/// Throws a SyntaxException if the property can not be converted
/// to an int.
/// Numbers starting with 0x are treated as hexadecimal.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
unsigned int getUInt(const std::string& key, unsigned int defaultValue) const;
/// If a property with the given key exists, returns the property's unsigned int
/// value, otherwise returns the given default value.
/// Throws a SyntaxException if the property can not be converted
/// to an unsigned int.
/// Numbers starting with 0x are treated as hexadecimal.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
#if defined(POCO_HAVE_INT64)
Int64 getInt64(const std::string& key) const;
/// Returns the Int64 value of the property with the given name.
/// Throws a NotFoundException if the key does not exist.
/// Throws a SyntaxException if the property can not be converted
/// to an Int64.
/// Numbers starting with 0x are treated as hexadecimal.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
UInt64 getUInt64(const std::string& key) const;
/// Returns the UInt64 value of the property with the given name.
/// Throws a NotFoundException if the key does not exist.
/// Throws a SyntaxException if the property can not be converted
/// to an UInt64.
/// Numbers starting with 0x are treated as hexadecimal.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
Int64 getInt64(const std::string& key, Int64 defaultValue) const;
/// If a property with the given key exists, returns the property's Int64 value,
/// otherwise returns the given default value.
/// Throws a SyntaxException if the property can not be converted
/// to an Int64.
/// Numbers starting with 0x are treated as hexadecimal.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
UInt64 getUInt64(const std::string& key, UInt64 defaultValue) const;
/// If a property with the given key exists, returns the property's UInt64
/// value, otherwise returns the given default value.
/// Throws a SyntaxException if the property can not be converted
/// to an UInt64.
/// Numbers starting with 0x are treated as hexadecimal.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
#endif // defined(POCO_HAVE_INT64)
double getDouble(const std::string& key) const;
/// Returns the double value of the property with the given name.
/// Throws a NotFoundException if the key does not exist.
/// Throws a SyntaxException if the property can not be converted
/// to a double.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
double getDouble(const std::string& key, double defaultValue) const;
/// If a property with the given key exists, returns the property's double value,
/// otherwise returns the given default value.
/// Throws a SyntaxException if the property can not be converted
/// to an double.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
bool getBool(const std::string& key) const;
/// Returns the boolean value of the property with the given name.
/// Throws a NotFoundException if the key does not exist.
/// Throws a SyntaxException if the property can not be converted
/// to a boolean.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
bool getBool(const std::string& key, bool defaultValue) const;
/// If a property with the given key exists, returns the property's boolean value,
/// otherwise returns the given default value.
/// Throws a SyntaxException if the property can not be converted
/// to a boolean.
/// The following string values can be converted into a boolean:
/// - numerical values: non zero becomes true, zero becomes false
/// - strings: true, yes, on become true, false, no, off become false
/// Case does not matter.
/// If the value contains references to other properties (${<property>}), these
/// are expanded.
virtual void setString(const std::string& key, const std::string& value);
/// Sets the property with the given key to the given value.
/// An already existing value for the key is overwritten.
virtual void setInt(const std::string& key, int value);
/// Sets the property with the given key to the given value.
/// An already existing value for the key is overwritten.
virtual void setUInt(const std::string& key, unsigned int value);
/// Sets the property with the given key to the given value.
/// An already existing value for the key is overwritten.
#if defined(POCO_HAVE_INT64)
virtual void setInt64(const std::string& key, Int64 value);
/// Sets the property with the given key to the given value.
/// An already existing value for the key is overwritten.
virtual void setUInt64(const std::string& key, UInt64 value);
/// Sets the property with the given key to the given value.
/// An already existing value for the key is overwritten.
#endif // defined(POCO_HAVE_INT64)
virtual void setDouble(const std::string& key, double value);
/// Sets the property with the given key to the given value.
/// An already existing value for the key is overwritten.
virtual void setBool(const std::string& key, bool value);
/// Sets the property with the given key to the given value.
/// An already existing value for the key is overwritten.
void keys(Keys& range) const;
/// Returns in range the names of all keys at root level.
void keys(const std::string& key, Keys& range) const;
/// Returns in range the names of all subkeys under the given key.
/// If an empty key is passed, all root level keys are returned.
const AbstractConfiguration* createView(const std::string& prefix) const;
/// Creates a non-mutable view (see ConfigurationView) into the configuration.
AbstractConfiguration* createView(const std::string& prefix);
/// Creates a view (see ConfigurationView) into the configuration.
std::string expand(const std::string& value) const;
/// Replaces all occurrences of ${<property>} in value with the
/// value of the <property>. If <property> does not exist,
/// nothing is changed.
///
/// If a circular property reference is detected, a
/// CircularReferenceException will be thrown.
void remove(const std::string& key);
/// Removes the property with the given key.
///
/// Does nothing if the key does not exist.
void enableEvents(bool enable = true);
/// Enables (or disables) events.
bool eventsEnabled() const;
/// Returns true iff events are enabled.
protected:
virtual bool getRaw(const std::string& key, std::string& value) const = 0;
/// If the property with the given key exists, stores the property's value
/// in value and returns true. Otherwise, returns false.
///
/// Must be overridden by subclasses.
virtual void setRaw(const std::string& key, const std::string& value) = 0;
/// Sets the property with the given key to the given value.
/// An already existing value for the key is overwritten.
///
/// Must be overridden by subclasses.
virtual void enumerate(const std::string& key, Keys& range) const = 0;
/// Returns in range the names of all subkeys under the given key.
/// If an empty key is passed, all root level keys are returned.
virtual void removeRaw(const std::string& key);
/// Removes the property with the given key.
///
/// Does nothing if the key does not exist.
///
/// Should be overridden by subclasses; the default
/// implementation throws a Poco::NotImplementedException.
static int parseInt(const std::string& value);
static unsigned parseUInt(const std::string& value);
#if defined(POCO_HAVE_INT64)
static Int64 parseInt64(const std::string& value);
static UInt64 parseUInt64(const std::string& value);
#endif // defined(POCO_HAVE_INT64)
static bool parseBool(const std::string& value);
void setRawWithEvent(const std::string& key, std::string value);
virtual ~AbstractConfiguration();
private:
std::string internalExpand(const std::string& value) const;
std::string uncheckedExpand(const std::string& value) const;
AbstractConfiguration(const AbstractConfiguration&);
AbstractConfiguration& operator = (const AbstractConfiguration&);
mutable int _depth;
bool _eventsEnabled;
mutable Poco::Mutex _mutex;
friend class LayeredConfiguration;
friend class ConfigurationView;
friend class ConfigurationMapper;
};
} } // namespace Poco::Util
#endif // Util_AbstractConfiguration_INCLUDED
|