Data.hpp
209 errorif(true, "Cannot convert an object of type ", typeid(T).name(), " to Data because Encode::eval was not defined for it.");
220 errorif(true, "Cannot convert an object a Data object to an object of type ", typeid(T).name(), " because Decode::eval was not defined for it.");
280 errorif(!convertable, "Could not convert from Data object to an object of type ", typeid(T).name(), " because this is not the type of the data stored nor it is convertible to that type.");
307 template<__VA_ARGS__> struct Data::Encode<T> { static auto eval(Data& data, const T& obj) -> void; };
315 template<__VA_ARGS__> struct Data::Decode<T> { static auto eval(const Data& data, T& obj) -> void; };
378 errorif(l.size() != 2, "Converting from Data to Pair requires the Data object to be a list with two entries.");
The class used to store and retrieve data for assemblying chemical systems.
Definition: Data.hpp:30
auto asList() const -> Vec< Data > const &
Return this Data object as a list object.
auto assign(T const &obj) -> void
Assign an object of type T to this Data object.
Definition: Data.hpp:248
auto dump() const -> String
Return a YAML formatted string representing the state of this Data object.
auto dumpYaml() const -> String
Return a YAML formatted string representing the state of this Data object.
auto add(String const &key, Data data) -> void
Add a Data object with given key to this Data object, which becomes a dictionary if not already.
auto saveYaml(String const &filepath) const -> void
Save the state of this Data object into a YAML formatted file.
auto dumpJson() const -> String
Return a JSON formatted string representing the state of this Data object.
auto repr() const -> String
Return a YAML formatted string representing the state of this Data object.
auto operator=(T const &obj) -> Data &
Assign an object of type T to this Data object.
Definition: Data.hpp:226
auto assign(char obj) -> void
Assign a char to this Data object.
Definition: Data.hpp:263
static auto parseJson(String const &text) -> Data
Return a Data object by parsing a JSON formatted string.
static auto parseYaml(Chars text) -> Data
Return a Data object by parsing an YAML formatted string.
static auto parseJson(Chars text) -> Data
Return a Data object by parsing a JSON formatted string.
auto exists(String const &key) const -> bool
Return true if a child Data object exists with given key, presuming this Data object is a dictionary.
static auto parseYaml(String const &text) -> Data
Return a Data object by parsing an YAML formatted string.
auto to(T &obj) const -> void
Decode this Data object into an object of type T.
Definition: Data.hpp:296
auto isFloat() const -> bool
Return true if this Data object is a float number.
static auto parseJson(std::istream &text) -> Data
Return a Data object by parsing a JSON formatted string.
auto optional(String const &key) const -> Opt
Return an optional child Data object with given key, presuming this Data object is a dictionary.
static auto load(String const &path) -> Data
Return a Data object by parsing either an YAML or JSON formatted file at a given path.
auto isBoolean() const -> bool
Return true if this Data object is a boolean value.
auto at(String const &key) const -> Data const &
Return the child Data object with given key, presuming this Data object is a dictionary.
auto reset() -> void
Reset this Data object to a null state, deleting its current stored data.
static auto parse(Chars text) -> Data
Return a Data object by parsing an YAML formatted string.
auto isDict() const -> bool
Return true if this Data object is a dictionary object.
static auto loadJson(String const &path) -> Data
Return a Data object by parsing a JSON formatted file at a given path.
auto saveJson(String const &filepath) const -> void
Save the state of this Data object into a JSON formatted file.
auto update(Data const &data) -> void
Update this Data object with data given in another, with key-value pairs being either added or overwr...
auto as() const -> T
Convert this Data object into an object of type T.
Definition: Data.hpp:276
static auto parse(String const &text) -> Data
Return a Data object by parsing an YAML formatted string.
auto add(Data data) -> void
Add a Data object to this Data object, which becomes a list if not already.
Data(T const &obj)
Construct a Data object from one of type T.
Definition: Data.hpp:241
auto required(String const &key) const -> Data const &
Return a required to exist child Data object with given key, presuming this Data object is a dictiona...
auto asDict() const -> Dict< String, Data > const &
Return this Data object as a dictionary object.
auto assign(Chars obj) -> void
Assign a raw string to this Data object.
Definition: Data.hpp:269
auto isInteger() const -> bool
Return true if this Data object is an integer number.
auto with(String const &attribute, String const &value) const -> Data const &
Return the child Data object whose attribute has a given value, presuming this Data object is a list.
static auto parse(std::istream &text) -> Data
Return a Data object by parsing an YAML formatted string.
auto save(String const &filepath) const -> void
Save the state of this Data object into a YAML formatted file.
static auto parseYaml(std::istream &text) -> Data
Return a Data object by parsing an YAML formatted string.
static auto loadYaml(String const &path) -> Data
Return a Data object by parsing an YAML formatted file at a given path.
#define errorif(condition,...)
Define a macro to raise a runtime exception if condition is true.
Definition: Exception.hpp:140
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
std::nullptr_t Nullptr
Convenient alias for std::nullptr_t.
Definition: Types.hpp:128
auto index(const Container &c, const T &x) -> std::size_t
Return the index of item x in container c or the number of items if not found.
Definition: Algorithms.hpp:37
Used to allow conversion of Data objects to objects with custom types.
Definition: Data.hpp:216
static auto eval(Data const &data, T &obj) -> void
Evaluate the conversion of a Data object to an object with custom type.
Definition: Data.hpp:218
Used to allow conversion of objects with custom types to Data objects.
Definition: Data.hpp:205
static auto eval(Data &data, T const &obj) -> void
Evaluate the conversion of an object with custom type to a Data object.
Definition: Data.hpp:207
auto to(T &obj) const -> void
Decode this Opt object into an object of type T, or leave it unchanged if no data is available.
Definition: Data.hpp:148