8#ifndef META_OCEAN_IO_JSON_CONFIG_H
9#define META_OCEAN_IO_JSON_CONFIG_H
36 using JSONValues = std::unordered_map<std::string, std::vector<JSONValue>>;
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;
388 explicit JSONScanner(
const std::shared_ptr<std::istream>& stream,
float* progress =
nullptr,
bool* cancel =
nullptr);
410 explicit JSONConfig(
const std::shared_ptr<std::istream>& stream);
416 inline const std::string&
filename()
const;
449 unsigned int values(
const std::string& name)
const override;
455 bool exist(
const std::string& name)
const 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
Value()=default
Creates a new value object.
virtual ValueType type() const
Returns the type of this value.
Config()
Creates a new configuration toolkit.
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_NULL
Keyword null.
Definition JSONConfig.h:376
@ 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_COMMA
Comma symbol: ','.
Definition JSONConfig.h:363
@ 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
friend class JSONConfig
Definition JSONConfig.h:43
JSONValue & add(const std::string &name) override
Adds a new sub value specified by it's name.
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< bool > boolValues() const
Returns the boolean value of this object.
double operator()(const double value) const override
Returns this value as number.
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.
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.
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 double value) override
Sets this value as number.
JSONValue(const JSONValues &values)
Creates a new value object holding sub values.
std::vector< int > integerValues() const
Returns the integer values of this object.
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.
JSONValue & value(const unsigned int index, std::string &name) override
Returns a sub value specified by it's index.
bool operator=(const std::vector< int > &values) override
Sets this value as multi integer.
Strings stringValues() const
Returns the string values of this object.
~JSONValue() override
Destructs a value object.
std::string valueString_
Value as string.
Definition JSONConfig.h:332
const JSONValue & operator[](const std::string &name) const
Returns a sub value specified by it's name.
std::vector< double > numberValues() const
Returns the number values of this object.
bool operator()(const bool value) const override
Returns this value as boolean.
bool operator=(const bool value) override
Sets this value as boolean.
bool operator=(const std::string &value) override
Sets this value as string.
JSONValue(const std::string &value, const ValueType type)
Creates a new value object by a single value as string and the real value type.
std::vector< double > operator()(const std::vector< double > &value) const override
Returns this value as multi number.
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.
bool operator=(const Strings &values) override
Sets this value as multi string.
std::vector< int > operator()(const std::vector< int > &value) const override
Returns this value as multi integer.
bool operator=(const std::vector< double > &values) override
Sets this value as multi number.
Strings operator()(const Strings &value) const override
Returns this value as multi string.
JSONValue root_
The root value.
Definition JSONConfig.h:543
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...
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.
JSONValue & add(const std::string &name) override
Adds a new sub value specified by it's name.
bool parseArray(JSONValue &node, const std::string &fieldName, JSONScanner &scanner)
Parses a JSON array.
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.
JSONValue & value(const unsigned int index, std::string &name) override
Returns a sub value specified by it's index.
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.
std::unordered_map< std::string, std::vector< JSONValue > > JSONValues
Definition of a map mapping value names to value objects.
Definition JSONConfig.h:36
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.
static JSONValue & nullValue()
Returns the default value holding no data.
Scanner(const std::shared_ptr< std::istream > &stream, float *progress=nullptr, bool *cancel=nullptr)
Creates a new scanner using a stream as input.
std::vector< std::string > Strings
Definition of a vector holding strings.
Definition Base.h:162
Namespace of the Ocean IO library.
Definition Base64.h:17
The namespace covering the entire Ocean framework.
Definition Accessor.h:15