Library: Util
Package: Util
Header: Poco/Util/JSONConfiguration.h
Description
This configuration class extracts configuration properties from a JSON object. An XPath-like syntax for property names is supported to allow full access to the JSON object.
Given the following JSON object as an example: {
"config" : { "prop1" : "value1", "prop2" : 10, "prop3" : [ "element1", "element2" ], "prop4" : { "prop5" : false, "prop6" : null } }
} The following property names would be valid and would yield the shown values:
config.prop1 --> "value1" config.prop3[1] --> "element2" config.prop4.prop5 --> false
Inheritance
Direct Base Classes: AbstractConfiguration
All Base Classes: Poco::RefCountedObject, AbstractConfiguration
Member Summary
Member Functions: enumerate, getRaw, load, loadEmpty, removeRaw, save, setBool, setDouble, setInt, setRaw, setString
Inherited Functions: createLocalView, createView, duplicate, enableEvents, enumerate, eventsEnabled, expand, getBool, getDouble, getInt, getInt16, getInt32, getInt64, getRaw, getRawString, getString, getUInt, getUInt16, getUInt32, getUInt64, has, hasOption, hasProperty, keys, parseBool, parseInt, parseInt16, parseInt64, parseUInt, parseUInt16, parseUInt64, referenceCount, release, remove, removeRaw, setBool, setDouble, setInt, setInt16, setInt32, setInt64, setRaw, setRawWithEvent, setString, setUInt, setUInt16, setUInt32, setUInt64
Constructors
JSONConfiguration
Creates an empty configuration
JSONConfiguration
JSONConfiguration(
const std::string & path
);
Creates a configuration and loads the JSON structure from the given file
JSONConfiguration
JSONConfiguration(
std::istream & istr
);
Creates a configuration and loads the JSON structure from the given stream
JSONConfiguration
JSONConfiguration(
const JSON::Object::Ptr & object
);
Creates a configuration from the given JSON object
Destructor
~JSONConfiguration
virtual ~JSONConfiguration();
Destructor
Member Functions
load
void load(
const std::string & path
);
Loads the configuration from the given file
load
void load(
std::istream & istr
);
Loads the configuration from the given stream
loadEmpty
void loadEmpty(
const std::string & root
);
Loads an empty object containing only a root object with the given name.
removeRaw
virtual void removeRaw(
const std::string & key
);
save
void save(
std::ostream & ostr,
unsigned int indent = 2
) const;
Saves the configuration to the given stream
setBool
virtual void setBool(
const std::string & key,
bool value
);
setDouble
virtual void setDouble(
const std::string & key,
double value
);
setInt
virtual void setInt(
const std::string & key,
int value
);
setString
virtual void setString(
const std::string & key,
const std::string & value
);
enumerate
void enumerate(
const std::string & key,
Keys & range
) const;
getRaw
bool getRaw(
const std::string & key,
std::string & value
) const;
setRaw
void setRaw(
const std::string & key,
const std::string & value
);