Configuration object that keeps track of the file it comes from More...
#include <mc_rtc/Configuration.h>
Public Member Functions | |
ConfigurationFile (const std::string &path) | |
void | reload () |
void | save () const |
const std::string & | path () const noexcept |
void | save (const std::string &path, bool pretty=true) const |
Save the configuration to a file. More... | |
Public Member Functions inherited from mc_rtc::Configuration | |
MC_RTC_DEPRECATED bool | isMember (const std::string &key) const |
Deprecated, see has. More... | |
bool | has (const std::string &key) const |
Check if the key is part of the conf. More... | |
operator bool () const | |
Cast to bool. More... | |
operator int8_t () const | |
Cast to int8_t. More... | |
operator uint8_t () const | |
Cast to uint8_t. More... | |
operator int16_t () const | |
Cast to int16_t. More... | |
operator uint16_t () const | |
Cast to uint16_t. More... | |
operator int32_t () const | |
Cast to int32_t. More... | |
operator uint32_t () const | |
Cast to uint32_t. More... | |
operator int64_t () const | |
Cast to int64_t. More... | |
operator uint64_t () const | |
Cast to uint64_t. More... | |
operator double () const | |
Cast to double. More... | |
operator std::string () const | |
Cast to a string. More... | |
operator Eigen::Vector2d () const | |
Retrieve as a Eigen::Vector2d instance. More... | |
operator Eigen::Vector3d () const | |
Retrieve as a Eigen::Vector3d instance. More... | |
operator Eigen::Vector4d () const | |
Retrieve as a Eigen::Vector4d instance. More... | |
operator Eigen::Vector6d () const | |
Retrieve as a Eigen::Vector6d instance. More... | |
operator mc_rbdyn::Gains2d () const | |
Retrieve as a mc_rbdyn::Gains2d instance. More... | |
operator mc_rbdyn::Gains3d () const | |
Retrieve as a mc_rbdyn::Gains3d instance. More... | |
operator mc_rbdyn::Gains6d () const | |
Retrieve as a mc_rbdyn::Gains6d instance. More... | |
operator Eigen::VectorXd () const | |
Retrieve as a Eigen::VectorXd instance. More... | |
operator Eigen::Quaterniond () const | |
Retrieve as a Eigen::Quaterniond instance. More... | |
operator Eigen::Matrix3d () const | |
Retrieve as a Eigen::Matrix3d instance. More... | |
operator Eigen::Matrix6d () const | |
Retrieve as a Eigen::Matrix6d instance. More... | |
operator Eigen::MatrixXd () const | |
Retrieve as a Eigen::MatrixXd instance. More... | |
operator sva::PTransformd () const | |
Retrieve as an sva::PTransformd. More... | |
operator sva::ForceVecd () const | |
Retrieve as an sva::ForceVecd. More... | |
operator sva::MotionVecd () const | |
Retrieve as an sva::MotionVecd. More... | |
operator sva::ImpedanceVecd () const | |
Retrieve as an sva::ImpedanceVecd. More... | |
template<class T , class A > | |
operator std::vector< T, A > () const | |
Retrieve a vector instance. More... | |
template<class T , std::size_t N> | |
operator std::array< T, N > () const | |
Retrieve an array instance. More... | |
template<class T1 , class T2 > | |
operator std::pair< T1, T2 > () const | |
Retrieve a pair instance. More... | |
template<typename T , class C , class A > | |
operator std::map< std::string, T, C, A > () const | |
Retrieve a string-indexed map instance. More... | |
template<typename T , typename C = std::less<T>, typename A = std::allocator<T>> | |
operator std::set< T, C, A > () const | |
Retrieve a set of objects. More... | |
template<typename T , typename H = std::hash<T>, typename E = std::equal_to<T>, typename A = std::allocator<T>> | |
operator std::unordered_set< T, H, E, A > () const | |
Retrieve an unordered set of objects. More... | |
template<typename... Args> | |
operator std::variant< Args... > () const | |
template<typename T , typename std::enable_if< internal::is_integral_v< T >, int >::type = 0> | |
operator T () const | |
template<typename T , typename std::enable_if< internal::has_configuration_load_object_v< T >||internal::has_static_fromConfiguration_v< T >, int >::type = 0> | |
operator T () const | |
User-defined conversions. More... | |
template<typename T > | |
operator std::optional< T > () const | |
Retrieves an optional<T> More... | |
Configuration () | |
Creates an empty configuration. More... | |
Configuration (const std::string &path) | |
Constructor using a file path. More... | |
Configuration (const char *path) | |
Constructor using a file path (C-style string) More... | |
void | load (const std::string &path) |
Load more data into the configuration. More... | |
void | load (const mc_rtc::Configuration &config) |
Load data from another Configuration object. More... | |
void | loadData (const std::string &data) |
Load data from a JSON string. More... | |
void | loadYAMLData (const std::string &data) |
Load data from a YAML string. More... | |
void | save (const std::string &path, bool pretty=true) const |
Save the configuration to a file. More... | |
std::string | dump (bool pretty=false, bool yaml=false) const |
Dump the configuration into a string. More... | |
size_t | toMessagePack (std::vector< char > &data) const |
Convert to MessagePack. More... | |
void | toMessagePack (MessagePackBuilder &builder) const |
Append to an existing MessagePackBuilder. More... | |
Configuration | operator() (const std::string &key) const |
Returns a Entry value stored within the configuration. More... | |
std::optional< Configuration > | find (const std::string &key) const |
Returns the Configuration entry if it exists, std::nullopt otherwise. More... | |
template<typename... Args> | |
std::optional< Configuration > | find (const std::string &key, Args &&... others) const |
Return the Configuration entry at (key, others...) if it exists, std::nullopt otherwise. More... | |
template<typename T , typename... Args> | |
std::optional< T > | find (const std::string &key, Args &&... others) const |
Return the Configuration entry at (key, others...) if it exists, std::nullopt otherwise. More... | |
bool | empty () const |
Returns true if the underlying array or underlying object is empty. More... | |
size_t | size () const |
If the stored value is an array, returns its size, otherwise returns 0. More... | |
bool | isArray () const noexcept |
Returns true if the underlying value is an array. More... | |
bool | isObject () const noexcept |
Returns true if the underlying value is an object. More... | |
bool | isString () const noexcept |
Returns true if the underlying value is a string. More... | |
bool | isNumeric () const noexcept |
Returns true if the underlying value is numeric. More... | |
Configuration | operator[] (size_t i) const |
If the stored value is an array, return a Configuration element for the i-th element. More... | |
template<typename T > | |
T | at (size_t i, const T &v) const |
Retrieve a given value from a JSON array. More... | |
template<typename T > | |
void | operator() (const std::string &key, T &v) const |
Retrieve and store a given value stored within the configuration. More... | |
template<typename T > | |
T | operator() (const std::string &key, const T &v) const |
Retrieve a given value stored within the configuration with a default value. More... | |
bool | operator== (const char *rhs) const |
Non-template version for C-style strings comparison. More... | |
template<typename T > | |
bool | operator== (const T &rhs) const |
Compare stored values with given value. More... | |
void | add_null (const std::string &key) |
Add a null element to the configuration. More... | |
void | add (const std::string &key, bool value) |
Add a bool element to the Configuration. More... | |
void | add (const std::string &key, int8_t value) |
Add a int64_t element to the Configuration. More... | |
void | add (const std::string &key, uint8_t value) |
Add a uint8_t element to the Configuration. More... | |
void | add (const std::string &key, int16_t value) |
Add a int16_t element to the Configuration. More... | |
void | add (const std::string &key, uint16_t value) |
Add a uint16_t element to the Configuration. More... | |
void | add (const std::string &key, int32_t value) |
Add a int32_t element to the Configuration. More... | |
void | add (const std::string &key, uint32_t value) |
Add a uint32_t element to the Configuration. More... | |
void | add (const std::string &key, int64_t value) |
Add a int64_t element to the Configuration. More... | |
void | add (const std::string &key, uint64_t value) |
Add a uint64_t element to the Configuration. More... | |
void | add (const std::string &key, double value) |
Add a double element to the Configuration. More... | |
void | add (const std::string &key, const std::string &value) |
Add a std::string element to the Configuration. More... | |
void | add (const std::string &key, const char *value) |
Add a const char* element to the Configuration, Behaves like std::string. More... | |
void | add (const std::string &key, const Eigen::Vector2d &value) |
Add a Eigen::Vector2d element to the Configuration. More... | |
void | add (const std::string &key, const Eigen::Vector3d &value) |
Add a Eigen::Vector3d element to the Configuration. More... | |
void | add (const std::string &key, const Eigen::Vector4d &value) |
Add a Eigen::Vector4d element to the Configuration. More... | |
void | add (const std::string &key, const Eigen::Vector6d &value) |
Add a Eigen::Vector6d element to the Configuration. More... | |
void | add (const std::string &key, const Eigen::VectorXd &value) |
Add a Eigen::VectorXd element to the Configuration. More... | |
void | add (const std::string &key, const Eigen::Quaterniond &value) |
Add a Eigen::Quaterniond element to the Configuration. More... | |
void | add (const std::string &key, const Eigen::Matrix3d &value) |
Add a Eigen::Matrix3d element to the Configuration. More... | |
void | add (const std::string &key, const Eigen::Matrix6d &value) |
Add a Eigen::Matrix6d element to the Configuration. More... | |
void | add (const std::string &key, const Eigen::MatrixXd &value) |
Add an Eigen::MatrixXd element to the Configuration. More... | |
void | add (const std::string &key, const sva::PTransformd &value) |
Add an sva::PTransformd element to the Configuration. More... | |
void | add (const std::string &key, const sva::ForceVecd &value) |
Add an sva::ForceVecd element to the Configuration. More... | |
void | add (const std::string &key, const sva::MotionVecd &value) |
Add an sva::MotionVecd element to the Configuration. More... | |
void | add (const std::string &key, const sva::ImpedanceVecd &value) |
Add an sva::ImpedanceVecd element to the Configuration. More... | |
void | add (const std::string &key, const Configuration &value) |
Add another Configuration to the Configuration. More... | |
Configuration | add (const std::string &key) |
Create an empty object in the Configuration. More... | |
Configuration | array (const std::string &key, size_t size=0) |
Create an empty array in the Configuration. More... | |
void | push_null () |
Insert a null value into an array. More... | |
void | push (bool value) |
Insert a bool element into an array. More... | |
void | push (int8_t value) |
Insert a int8_t element int8_to an array. More... | |
void | push (uint8_t value) |
Insert a uint8_t element into an array. More... | |
void | push (int16_t value) |
Insert a int16_t element int16_to an array. More... | |
void | push (uint16_t value) |
Insert a uint16_t element into an array. More... | |
void | push (int32_t value) |
Insert a int32_t element int32_to an array. More... | |
void | push (uint32_t value) |
Insert a uint32_t element into an array. More... | |
void | push (int64_t value) |
Insert a int64_t element int64_to an array. More... | |
void | push (uint64_t value) |
Insert a uint64_t element into an array. More... | |
void | push (double value) |
Insert a double element into an array. More... | |
void | push (const std::string &value) |
Insert a std::string element into an array. More... | |
void | push (const char *value) |
Insert a const char * element into an array Behaves like push(std::string) More... | |
void | push (const Eigen::Vector2d &value) |
Insert a Eigen::Vector2d element into an array. More... | |
void | push (const Eigen::Vector3d &value) |
Insert a Eigen::Vector3d element into an array. More... | |
void | push (const Eigen::Vector4d &value) |
Insert a Eigen::Vector4d element into an array. More... | |
void | push (const Eigen::Vector6d &value) |
Insert a Eigen::Vector6d element into an array. More... | |
void | push (const Eigen::VectorXd &value) |
Insert a Eigen::VectorXd element into an array. More... | |
void | push (const Eigen::Quaterniond &value) |
Insert a Eigen::Quaterniond element into an array. More... | |
void | push (const Eigen::Matrix3d &value) |
Insert a Eigen::Matrix3d element into an array. More... | |
void | push (const Eigen::Matrix6d &value) |
Insert a Eigen::Matrix6d element into an array. More... | |
void | push (const Eigen::MatrixXd &value) |
Insert a Eigen::MatrixXd element into an array. More... | |
void | push (const sva::PTransformd &value) |
Insert an sva::PTransformd element into an array. More... | |
void | push (const sva::ForceVecd &value) |
Insert an sva::ForceVecd element into an array. More... | |
void | push (const sva::MotionVecd &value) |
Insert an sva::MotionVecd element into an array. More... | |
void | push (const sva::ImpedanceVecd &value) |
Insert an sva::ImpedanceVecd element into an array. More... | |
void | push (const Configuration &value) |
Push a Configuration element into an array. More... | |
Configuration | array (size_t reserve=0) |
Push an empty array. More... | |
Configuration | object () |
Push an empty object. More... | |
template<typename T , typename... Args, typename std::enable_if< internal::has_configuration_save_object_v< T, Args... >||internal::has_toConfiguration_method_v< T, Args... >, int >::type = 0> | |
void | push (const T &value, Args &&... args) |
User-defined conversion. More... | |
template<typename T , typename std::enable_if< internal::is_integral_v< T >, int >::type = 0> | |
void | push (const T &value) |
template<typename T , typename A = std::allocator<T>, typename... Args> | |
void | add (const std::string &key, const std::vector< T, A > &value, Args &&... args) |
Add a vector into the JSON document. More... | |
template<typename T , std::size_t N, typename... Args> | |
void | add (const std::string &key, const std::array< T, N > &value, Args &&... args) |
Add an array into the JSON document. More... | |
template<typename T1 , typename T2 , typename... Args> | |
void | add (const std::string &key, const std::pair< T1, T2 > &value, Args &&... args) |
Add a pair into the JSON document. More... | |
template<typename T , class C = std::less<std::string>, class A = std::allocator<std::pair<const std::string, T>>, typename... Args> | |
void | add (const std::string &key, const std::map< std::string, T, C, A > &value, Args &&... args) |
Add string-indexed map into the JSON document. More... | |
template<typename T , typename C = std::less<T>, typename A = std::allocator<T>, typename... Args> | |
void | add (const std::string &key, const std::set< T, C, A > &value, Args &&... args) |
Add a set into the JSON document. More... | |
template<typename T , typename H = std::hash<T>, typename E = std::equal_to<T>, typename A = std::allocator<T>, typename... Args> | |
void | add (const std::string &key, const std::unordered_set< T, H, E, A > &value, Args &&... args) |
Add an unordered set into the JSON document. More... | |
template<typename... Args> | |
void | add (const std::string &key, const std::variant< Args... > &value) |
Add a variant object into the JSON document. More... | |
template<typename T , typename std::enable_if< internal::is_integral_v< T >, int >::type = 0> | |
void | add (const std::string &key, const T &value) |
template<typename T , typename... Args, typename std::enable_if< internal::has_configuration_save_object_v< T, Args... >||internal::has_toConfiguration_method_v< T, Args... >, int >::type = 0> | |
void | add (const std::string &key, const T &value, Args &&... args) |
User-defined conversion. More... | |
template<typename T , typename A = std::allocator<T>, typename... Args> | |
void | push (const std::vector< T, A > &value, Args &&... args) |
Push a vector into the JSON document. More... | |
template<typename T , std::size_t N, typename... Args> | |
void | push (const std::array< T, N > &value, Args &&... args) |
Push an array into the JSON document. More... | |
template<typename T1 , typename T2 , typename... Args> | |
void | push (const std::pair< T1, T2 > &value, Args &&... args) |
Push a pair into the JSON document. More... | |
template<typename T , class C = std::less<std::string>, class A = std::allocator<std::pair<const std::string, T>>, typename... Args> | |
void | push (const std::map< std::string, T, C, A > &value, Args &&... args) |
Push a string-indexed map into the JSON document. More... | |
template<typename T , typename C = std::less<T>, typename A = std::allocator<T>, typename... Args> | |
void | push (const std::set< T, C, A > &value, Args &&... args) |
Push a set into the JSON document. More... | |
template<typename T , typename H = std::hash<T>, typename E = std::equal_to<T>, typename A = std::allocator<T>, typename... Args> | |
void | push (const std::unordered_set< T, H, E, A > &value, Args &&... args) |
Push an unordered set into the JSON document. More... | |
template<typename... Args> | |
void | push (const std::variant< Args... > &value) |
Push a variant object into the JSON document. More... | |
bool | remove (const std::string &key) |
std::vector< std::string > | keys () const |
ConfigurationArrayIterator | begin () const |
ConfigurationArrayIterator | end () const |
template<> | |
void MC_RTC_UTILS_DLLAPI | operator() (const std::string &key, std::string &v) const |
Specialized version to lift ambiguity. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from mc_rtc::Configuration | |
static Configuration | rootArray () |
Returns a Configuration with an array as root entry. More... | |
static Configuration | fromData (const std::string &data) |
Static constructor to load from JSON data. More... | |
static Configuration | fromData (const char *data) |
Static constructor to load from JSON data (C overload) More... | |
static Configuration | fromYAMLData (const std::string &data) |
Static constructor to load from YAML data. More... | |
static Configuration | fromYAMLData (const char *data) |
Static constructor to load from YAML data (C overload) More... | |
static Configuration | fromMessagePack (const char *data, size_t size) |
Static constructor to load from MessagePack data. More... | |
Configuration object that keeps track of the file it comes from
This utility saves you from keeping track of the loaded file, i.e. insteaf of
You can simply do:
mc_rtc::ConfigurationFile::ConfigurationFile | ( | const std::string & | path | ) |
Same as Configuration::Configuration(const std::string &) but the path is saved
|
inlinenoexcept |
Access the path where this configuration is stored
void mc_rtc::ConfigurationFile::reload | ( | ) |
Reload from the original file, discard unsaved work
void mc_rtc::ConfigurationFile::save | ( | ) | const |
Save to the original file
void mc_rtc::Configuration::save |
Save the configuration to a file.
If the path extension is yaml or yml then save in YAML format
path | Path to the configuration file |
pretty | Writes a human-readable file, defaults to true |