8 #ifndef META_OCEAN_IO_JSON_CONFIG_H
9 #define META_OCEAN_IO_JSON_CONFIG_H
36 typedef std::unordered_map<std::string, std::vector<JSONValue>>
JSONValues;
80 unsigned int values()
const override;
87 unsigned int values(
const std::string& name)
const override;
94 bool exist(
const std::string& name)
const override;
113 bool value(
const std::string& name,
const unsigned int index,
Value** value)
override;
132 bool value(
const unsigned int index, std::string& name,
Value** value)
override;
171 std::string
operator()(
const std::string& value)
const override;
179 std::vector<bool>
operator()(
const std::vector<bool>& value)
const override;
187 std::vector<int>
operator()(
const std::vector<int>& value)
const override;
195 std::vector<double>
operator()(
const std::vector<double>& value)
const override;
203 std::vector<std::string>
operator()(
const std::vector<std::string>& value)
const override;
243 bool operator=(
const std::vector<bool>& values)
override;
251 bool operator=(
const std::vector<int>& values)
override;
259 bool operator=(
const std::vector<double>& values)
override;
267 bool operator=(
const std::vector<std::string>& values)
override;
388 explicit JSONScanner(
const std::shared_ptr<std::istream>& stream,
float* progress =
nullptr,
bool* cancel =
nullptr);
404 explicit JSONConfig(
const std::string& filename,
const bool read =
true);
410 explicit JSONConfig(
const std::shared_ptr<std::istream>& stream);
416 inline const std::string& filename()
const;
425 bool setFilename(
const std::string& filename,
const bool read =
true);
449 unsigned int values(
const std::string& name)
const override;
455 bool exist(
const std::string& name)
const override;
467 bool value(
const unsigned int index, std::string& name,
Value** value)
override;
479 bool value(
const std::string& name,
const unsigned int index,
Value** value)
override;
529 static bool writeLine(
const std::string&
string, std::ostream& stream,
const unsigned int indentation);
This class implements a configuration value.
Definition: Config.h:77
This class implements an application or module configuration toolkit.
Definition: Config.h:38
ValueType
Definition of different value types.
Definition: Config.h:45
This class implements a scanner for JSON files.
Definition: JSONConfig.h:344
JSONScanner(const std::shared_ptr< std::istream > &stream, float *progress=nullptr, bool *cancel=nullptr)
Creates a new scanner by a given filename.
JSONKeyword
Definition of individual JSON keywords.
Definition: JSONConfig.h:370
@ JK_FALSE
Keyword false.
Definition: JSONConfig.h:374
@ JK_TRUE
Keyword true.
Definition: JSONConfig.h:372
JSONSymbol
Definition of individual JSON symbols.
Definition: JSONConfig.h:351
@ JS_NODE_BEGIN
Node begin symbol: '{'.
Definition: JSONConfig.h:353
@ JS_ARRAY_END
Node end symbol: ']'.
Definition: JSONConfig.h:359
@ JS_COLON
Colon symbol: '.'.
Definition: JSONConfig.h:361
@ JS_NODE_END
Node end symbol: '}'.
Definition: JSONConfig.h:355
@ JS_ARRAY_BEGIN
Array begin symbol: '['.
Definition: JSONConfig.h:357
Definition of a JSON value object.
Definition: JSONConfig.h:42
JSONValues subValues_
Sub values if this value is a group.
Definition: JSONConfig.h:335
bool value(const std::string &name, const unsigned int index, Value **value) override
Returns a sub value specified by it's name and it's index if more than one value exists with the same...
std::string operator()(const std::string &value) const override
Returns this value as string.
std::vector< std::string > stringValues() const
Returns the string values of this object.
const JSONValue & operator[](const std::string &name) const
Returns a sub value specified by it's name.
double operator()(const double value) const override
Returns this value as number.
std::vector< std::string > operator()(const std::vector< std::string > &value) const override
Returns this value as multi string.
std::vector< double > operator()(const std::vector< double > &value) const override
Returns this value as multi number.
std::vector< int > operator()(const std::vector< int > &value) const override
Returns this value as multi integer.
JSONValue & add(const std::string &name) override
Adds a new sub value specified by it's name.
int operator()(const int value) const override
Returns this value as integer.
bool operator=(const std::vector< bool > &values) override
Sets this value as multi boolean.
bool boolValue() const
Returns the boolean value of this object.
JSONValue()
Creates a new value object.
bool exist(const std::string &name) const override
Returns whether this value holds at least one specified sub value.
int integerValue() const
Returns the integer value of this object.
bool operator=(const double value) override
Sets this value as number.
std::vector< bool > boolValues() const
Returns the boolean value of this object.
JSONValue(const JSONValues &values)
Creates a new value object holding sub values.
JSONValue(const JSONValue &value)=default
Default copy constructor.
unsigned int values() const override
Returns the number of sub values.
bool value(const unsigned int index, std::string &name, Value **value) override
Returns a sub value specified by it's index.
bool operator=(const std::vector< int > &values) override
Sets this value as multi integer.
~JSONValue() override
Destructs a value object.
std::string valueString_
Value as string.
Definition: JSONConfig.h:332
bool operator=(const std::vector< std::string > &values) override
Sets this value as multi string.
JSONValue & value(const unsigned int index, std::string &name) override
Returns a sub value specified by it's index.
bool operator()(const bool value) const override
Returns this value as boolean.
bool operator=(const bool value) override
Sets this value as boolean.
std::vector< bool > operator()(const std::vector< bool > &value) const override
Returns this value as multi boolean.
JSONValue & operator[](const std::string &name) override
Returns a sub value specified by it's name.
bool operator=(const std::string &value) override
Sets this value as string.
std::vector< double > numberValues() const
Returns the number values of this object.
JSONValue(const std::string &value, const ValueType type)
Creates a new value object by a single value as string and the real value type.
JSONValue & value(const std::string &name, const unsigned int index) override
Returns a sub value specified by it's name and it's index if more than one value exists with the same...
bool operator=(const int value) override
Sets this value as integer.
double numberValue() const
Returns the number value of this object.
unsigned int values(const std::string &name) const override
Returns the number of sub values with a given name.
std::vector< int > integerValues() const
Returns the integer values of this object.
bool operator=(const std::vector< double > &values) override
Sets this value as multi number.
This class implements a configuration toolkit based on JSON.
Definition: JSONConfig.h:27
JSONValue root_
The root value.
Definition: JSONConfig.h:543
static bool writeNode(JSONValue &node, std::ostream &stream, const unsigned int indentation)
Writes a JSON node.
bool value(const unsigned int index, std::string &name, Value **value) override
Returns a sub value specified by it's index.
JSONConfig(const std::string &filename, const bool read=true)
Creates a new config object with a specified configuration file.
const std::string & filename() const
Returns the config file.
Definition: JSONConfig.h:546
std::string filename_
Filename of this config object.
Definition: JSONConfig.h:540
JSONConfig()
Creates a new config object.
bool read() override
Reads / loads all values of this configuration.
static JSONValue & nullValue()
Returns the default value holding no data.
bool parseArray(JSONValue &node, const std::string &fieldName, JSONScanner &scanner)
Parses a JSON array.
JSONValue & value(const unsigned int index, std::string &name) override
Returns a sub value specified by it's index.
bool parseNode(JSONValue &node, JSONScanner &scanner)
Parses a JSON node.
unsigned int values() const override
Returns the number of sub values.
bool setFilename(const std::string &filename, const bool read=true)
Sets the filename of the new config objects.
bool write() override
Writes / saves all values of this configuration.
bool value(const std::string &name, const unsigned int index, Value **value) override
Returns a sub value specified by it's name and it's index if more than one value exists with the same...
JSONValue & operator[](const std::string &name) override
Returns a sub value specified by it's name.
JSONConfig(const std::shared_ptr< std::istream > &stream)
Creates a new config object with a specified input stream.
JSONValue & value(const std::string &name, const unsigned int index) override
Returns a sub value specified by it's name and it's index if more than one value exists with the same...
unsigned int values(const std::string &name) const override
Returns the number of sub values with a given name.
bool exist(const std::string &name) const override
Returns whether this value holds at least one specified sub value.
static bool writeLine(const std::string &string, std::ostream &stream, const unsigned int indentation)
Writes a line (with indentation) to an output stream.
std::unordered_map< std::string, std::vector< JSONValue > > JSONValues
Definition of a map mapping value names to value objects.
Definition: JSONConfig.h:31
JSONValue & add(const std::string &name) override
Adds a new sub value specified by it's name.
This class implements a simple scanner.
Definition: Scanner.h:31
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15