13 #include <SpaceVecAlg/SpaceVecAlg>
16 #include <spdlog/fmt/fmt.h>
25 #include <string_view>
26 #include <unordered_set>
32 #if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER)
33 # if __GNUC__ > 8 || (__GNUC__ == 8 && __GNUC_MINOR__ > 2)
34 # define MC_RTC_USE_VARIANT_WORKAROUND 0
36 # define MC_RTC_USE_VARIANT_WORKAROUND 1
39 # define MC_RTC_USE_VARIANT_WORKAROUND 0
59 static void save(
const T &) {}
78 typename std::enable_if<
81 static std::true_type
test(T * p);
84 static std::false_type
test(...);
89 decltype(_has_configuration_load_object::test<T>(
nullptr))::value;
98 typename = std::enable_if_t<
99 std::is_same_v<decltype(T::fromConfiguration(std::declval<const Configuration &>())), T>>>
100 static std::true_type
test(T * p);
103 static std::false_type
test(...);
117 typename std::enable_if<
121 static std::true_type
test(T * p);
123 template<
typename T,
typename... Args>
124 static std::false_type
test(...);
127 template<
typename T,
typename... Args>
129 decltype(_has_configuration_save_object::test<T, Args...>(
nullptr))::value;
140 typename = std::enable_if_t<
141 std::is_same_v<decltype(std::declval<const T &>().toConfiguration(std::declval<Args>()...)),
Configuration>>>
142 static std::true_type
test(T * p);
144 template<
typename T,
typename... Args>
145 static std::false_type
test(...);
148 template<
typename T,
typename... Args>
150 decltype(_has_toConfiguration_method::test<T, Args...>(
nullptr))::value;
152 #if MC_RTC_USE_VARIANT_WORKAROUND
154 template<
size_t IDX,
typename... Args>
155 std::variant<Args...> to_variant(
const Configuration & c,
size_t idx);
176 bool isArray()
const noexcept;
178 size_t size()
const noexcept;
183 Json operator[](
size_t idx)
const;
185 bool isObject()
const noexcept;
187 std::vector<std::string> keys()
const noexcept;
192 Json operator[](
const std::string & key)
const;
194 std::optional<Json> find(
const std::string & key)
const;
196 bool isString()
const noexcept;
198 bool isNumeric()
const noexcept;
200 bool isInteger()
const noexcept;
202 bool isInt32()
const noexcept;
204 bool isInt64()
const noexcept;
206 bool isUInt32()
const noexcept;
208 bool isUInt64()
const noexcept;
210 bool isDouble()
const noexcept;
216 double asDouble()
const;
221 void path(std::string & out)
const noexcept;
225 std::shared_ptr<void> doc_;
257 virtual const
char * what() const noexcept override;
260 void silence() const noexcept;
263 const
std::
string & msg() const noexcept;
266 mutable
std::
string msg_;
276 MC_RTC_DEPRECATED
bool isMember(const
std::
string & key) const;
284 bool has(const
std::
string & key) const;
290 operator
bool() const;
298 operator int8_t() const;
307 operator uint8_t() const;
315 operator int16_t() const;
324 operator uint16_t() const;
332 operator int32_t() const;
341 operator uint32_t() const;
349 operator int64_t() const;
358 operator uint64_t() const;
366 operator
double() const;
378 operator
std::
string() const;
385 operator Eigen::Vector2d() const;
392 operator Eigen::Vector3d() const;
399 operator Eigen::Vector4d() const;
406 operator Eigen::Vector6d() const;
434 operator Eigen::VectorXd() const;
443 operator Eigen::Quaterniond() const;
450 operator Eigen::Matrix3d() const;
456 operator Eigen::Matrix6d() const;
462 operator Eigen::MatrixXd() const;
468 operator sva::PTransformd() const;
474 operator sva::ForceVecd() const;
480 operator sva::MotionVecd() const;
486 operator sva::ImpedanceVecd() const;
494 template<class T, class A>
495 operator
std::vector<T, A>()
const
499 std::vector<T, A> ret;
500 for(
size_t i = 0; i < v.size(); ++i) { ret.push_back(
Configuration(v[i])); }
512 template<
class T, std::
size_t N>
513 operator std::array<T, N>()
const
515 if(v.isArray() && v.size() == N)
517 std::array<T, N> ret;
518 for(
size_t i = 0; i < N; ++i) { ret[i] =
Configuration(v[i]); }
529 template<
class T1,
class T2>
530 operator std::pair<T1, T2>()
const
541 template<
typename T,
class C,
class A>
542 operator std::map<std::string, T, C, A>()
const
546 std::map<std::string, T, C, A> ret;
547 auto keys = v.keys();
548 assert(std::set<std::string>(keys.begin(), keys.end()).size() == keys.size());
549 for(
const auto & k : keys)
565 template<
typename T,
typename C = std::less<T>,
typename A = std::allocator<T>>
566 operator std::set<T, C, A>()
const
570 std::set<T, C, A> ret;
571 for(
size_t i = 0; i < v.size(); ++i)
587 template<
typename T,
typename H = std::hash<T>,
typename E = std::equal_to<T>,
typename A = std::allocator<T>>
588 operator std::unordered_set<T, H, E, A>()
const
592 std::unordered_set<T, H, E, A> ret;
593 for(
size_t i = 0; i < v.size(); ++i)
612 template<
typename... Args>
613 operator std::variant<Args...>()
const
619 #if MC_RTC_USE_VARIANT_WORKAROUND
620 return internal::to_variant<0, Args...>(v[1], idx);
622 static constexpr
auto table =
623 std::array{+[](
const Configuration & c) {
return std::variant<Args...>{c.operator Args()}; }...};
624 return table[idx](v[1]);
632 template<
typename T,
typename std::enable_if<
internal::is_
integral_v<T>,
int>::type = 0>
635 if constexpr(internal::is_like_int8_t<T>) {
return static_cast<T
>(this->
operator int8_t()); }
636 else if constexpr(internal::is_like_int16_t<T>) {
return static_cast<T
>(this->
operator int16_t()); }
637 else if constexpr(internal::is_like_int32_t<T>) {
return static_cast<T
>(this->
operator int32_t()); }
638 else if constexpr(internal::is_like_int64_t<T>) {
return static_cast<T
>(this->
operator int64_t()); }
639 else if constexpr(internal::is_like_uint8_t<T>) {
return static_cast<T
>(this->
operator uint8_t()); }
640 else if constexpr(internal::is_like_uint16_t<T>) {
return static_cast<T
>(this->
operator uint16_t()); }
641 else if constexpr(internal::is_like_uint32_t<T>) {
return static_cast<T
>(this->
operator uint32_t()); }
642 else if constexpr(internal::is_like_uint64_t<T>) {
return static_cast<T
>(this->
operator uint64_t()); }
643 else { static_assert(!std::is_same_v<T, T>,
"T is integral but has an unsupported size"); }
652 typename std::enable_if<internal::has_configuration_load_object_v<T>
653 || internal::has_static_fromConfiguration_v<T>,
658 else {
return T::fromConfiguration(*
this); }
666 explicit operator std::optional<T>()
const
670 return this->convert<T>();
748 void load(
const std::string & path);
790 void save(
const std::string & path,
bool pretty =
true)
const;
799 std::string
dump(
bool pretty =
false,
bool yaml =
false)
const;
837 std::optional<Configuration>
find(
const std::string & key)
const;
849 template<
typename... Args>
850 std::optional<Configuration>
find(
const std::string & key, Args &&... others)
const
852 auto out = find(key);
853 return out ? out->find(std::forward<Args>(others)...) : std::nullopt;
866 template<
typename T,
typename... Args>
867 std::optional<T>
find(
const std::string & key, Args &&... others)
const
869 auto maybe_cfg = find(key, std::forward<Args>(others)...);
870 if(maybe_cfg) {
return maybe_cfg->operator T(); }
886 inline bool isArray() const noexcept {
return v.isArray(); }
889 inline bool isObject() const noexcept {
return v.isObject(); }
892 inline bool isString() const noexcept {
return v.isString(); }
895 inline bool isNumeric() const noexcept {
return v.isNumeric(); }
897 inline bool isInteger() const noexcept {
return v.isInteger(); }
899 inline bool isInt32() const noexcept {
return v.isInt32(); }
901 inline bool isInt64() const noexcept {
return v.isInt64(); }
903 inline bool isUInt32() const noexcept {
return v.isUInt32(); }
905 inline bool isUInt64() const noexcept {
return v.isUInt64(); }
907 inline bool isDouble() const noexcept {
return v.isDouble(); }
927 T
at(
size_t i,
const T & v)
const
931 return (*
this)[i].convert<T>();
957 v = (*this)(key).convert<T>();
980 return (*
this)(key).convert<T>();
1023 void add(
const std::string & key,
bool value);
1029 void add(
const std::string & key, int8_t value);
1035 void add(
const std::string & key, uint8_t value);
1041 void add(
const std::string & key, int16_t value);
1047 void add(
const std::string & key, uint16_t value);
1053 void add(
const std::string & key, int32_t value);
1059 void add(
const std::string & key, uint32_t value);
1065 void add(
const std::string & key, int64_t value);
1071 void add(
const std::string & key, uint64_t value);
1077 void add(
const std::string & key,
double value);
1083 void add(
const std::string & key,
const std::string & value);
1090 void add(
const std::string & key,
const char * value);
1096 void add(
const std::string & key,
const Eigen::Vector2d & value);
1102 void add(
const std::string & key,
const Eigen::Vector3d & value);
1108 void add(
const std::string & key,
const Eigen::Vector4d & value);
1114 void add(
const std::string & key,
const Eigen::Vector6d & value);
1120 void add(
const std::string & key,
const Eigen::VectorXd & value);
1126 void add(
const std::string & key,
const Eigen::Quaterniond & value);
1132 void add(
const std::string & key,
const Eigen::Matrix3d & value);
1138 void add(
const std::string & key,
const Eigen::Matrix6d & value);
1144 void add(
const std::string & key,
const Eigen::MatrixXd & value);
1150 void add(
const std::string & key,
const sva::PTransformd & value);
1156 void add(
const std::string & key,
const sva::ForceVecd & value);
1162 void add(
const std::string & key,
const sva::MotionVecd & value);
1168 void add(
const std::string & key,
const sva::ImpedanceVecd & value);
1266 void push(
const std::string & value);
1278 void push(
const Eigen::Vector2d & value);
1284 void push(
const Eigen::Vector3d & value);
1290 void push(
const Eigen::Vector4d & value);
1296 void push(
const Eigen::Vector6d & value);
1302 void push(
const Eigen::VectorXd & value);
1308 void push(
const Eigen::Quaterniond & value);
1314 void push(
const Eigen::Matrix3d & value);
1320 void push(
const Eigen::Matrix6d & value);
1326 void push(
const Eigen::MatrixXd & value);
1332 void push(
const sva::PTransformd & value);
1338 void push(
const sva::ForceVecd & value);
1344 void push(
const sva::MotionVecd & value);
1350 void push(
const sva::ImpedanceVecd & value);
1377 template<
typename T,
1382 void push(
const T & value, Args &&... args)
1384 if constexpr(internal::has_configuration_save_object_v<T, Args...>)
1388 else { push(value.toConfiguration(std::forward<Args>(args)...)); }
1395 template<
typename T,
typename std::enable_if<
internal::is_
integral_v<T>,
int>::type = 0>
1398 if constexpr(internal::is_like_int8_t<T>) { push(
static_cast<int8_t
>(value)); }
1399 else if constexpr(internal::is_like_int16_t<T>) { push(
static_cast<int16_t
>(value)); }
1400 else if constexpr(internal::is_like_int32_t<T>) { push(
static_cast<int32_t
>(value)); }
1401 else if constexpr(internal::is_like_int64_t<T>) { push(
static_cast<int64_t
>(value)); }
1402 else if constexpr(internal::is_like_uint8_t<T>) { push(
static_cast<uint8_t
>(value)); }
1403 else if constexpr(internal::is_like_uint16_t<T>) { push(
static_cast<uint16_t
>(value)); }
1404 else if constexpr(internal::is_like_uint32_t<T>) { push(
static_cast<uint32_t
>(value)); }
1405 else if constexpr(internal::is_like_uint64_t<T>) { push(
static_cast<uint64_t
>(value)); }
1406 else { static_assert(!std::is_same_v<T, T>,
"T is integral but has an unsupported size"); }
1417 template<
typename T,
typename A = std::allocator<T>,
typename... Args>
1418 void add(
const std::string & key,
const std::vector<T, A> & value, Args &&... args)
1421 for(
const auto & vi : value) { v.
push(vi, std::forward<Args>(args)...); }
1432 template<
typename T, std::size_t N,
typename... Args>
1433 void add(
const std::string & key,
const std::array<T, N> & value, Args &&... args)
1436 for(
const auto & vi : value) { v.
push(vi, std::forward<Args>(args)...); }
1447 template<
typename T1,
typename T2,
typename... Args>
1448 void add(
const std::string & key,
const std::pair<T1, T2> & value, Args &&... args)
1451 v.
push(value.first, std::forward<Args>(args)...);
1452 v.
push(value.second, std::forward<Args>(args)...);
1463 template<
typename T,
1464 class C = std::less<std::string>,
1465 class A = std::allocator<std::pair<const std::string, T>>,
1467 void add(
const std::string & key,
const std::map<std::string, T, C, A> & value, Args &&... args)
1470 for(
const auto & el : value) { v.
add(el.first, el.second, std::forward<Args>(args)...); }
1481 template<
typename T,
typename C = std::less<T>,
typename A = std::allocator<T>,
typename... Args>
1482 void add(
const std::string & key,
const std::set<T, C, A> & value, Args &&... args)
1485 for(
const auto & v : value) { v.
push(*v, std::forward<Args>(args)...); }
1496 template<
typename T,
1497 typename H = std::hash<T>,
1498 typename E = std::equal_to<T>,
1499 typename A = std::allocator<T>,
1501 void add(
const std::string & key,
const std::unordered_set<T, H, E, A> & value, Args &&... args)
1504 for(
const auto & v : value) { v.
push(*v, std::forward<Args>(args)...); }
1517 template<
typename... Args>
1518 void add(
const std::string & key,
const std::variant<Args...> & value)
1521 v.
push(value.index());
1522 std::visit([&v](
const auto & hold) { v.
push(hold); }, value);
1531 template<
typename T,
typename std::enable_if<
internal::is_
integral_v<T>,
int>::type = 0>
1532 void add(
const std::string & key,
const T & value)
1534 if constexpr(internal::is_like_int8_t<T>) { add(key,
static_cast<int8_t
>(value)); }
1535 else if constexpr(internal::is_like_int16_t<T>) { add(key,
static_cast<int16_t
>(value)); }
1536 else if constexpr(internal::is_like_int32_t<T>) { add(key,
static_cast<int32_t
>(value)); }
1537 else if constexpr(internal::is_like_int64_t<T>) { add(key,
static_cast<int64_t
>(value)); }
1538 else if constexpr(internal::is_like_uint8_t<T>) { add(key,
static_cast<uint8_t
>(value)); }
1539 else if constexpr(internal::is_like_uint16_t<T>) { add(key,
static_cast<uint16_t
>(value)); }
1540 else if constexpr(internal::is_like_uint32_t<T>) { add(key,
static_cast<uint32_t
>(value)); }
1541 else if constexpr(internal::is_like_uint64_t<T>) { add(key,
static_cast<uint64_t
>(value)); }
1542 else { static_assert(!std::is_same_v<T, T>,
"T is integral but has an unsupported size"); }
1554 template<
typename T,
1559 void add(
const std::string & key,
const T & value, Args &&... args)
1561 if constexpr(internal::has_configuration_save_object_v<T, Args...>)
1565 else { add(key, value.toConfiguration(std::forward<Args>(args)...)); }
1572 template<
typename T,
typename A = std::allocator<T>,
typename... Args>
1573 void push(
const std::vector<T, A> & value, Args &&... args)
1576 for(
const auto & vi : value) { v.
push(vi, std::forward<Args>(args)...); }
1583 template<
typename T, std::size_t N,
typename... Args>
1584 void push(
const std::array<T, N> & value, Args &&... args)
1587 for(
const auto & vi : value) { v.
push(vi, std::forward<Args>(args)...); }
1594 template<
typename T1,
typename T2,
typename... Args>
1595 void push(
const std::pair<T1, T2> & value, Args &&... args)
1598 v.
push(value.first, std::forward<Args>(args)...);
1599 v.
push(value.second, std::forward<Args>(args)...);
1606 template<
typename T,
1607 class C = std::less<std::string>,
1608 class A = std::allocator<std::pair<const std::string, T>>,
1610 void push(
const std::map<std::string, T, C, A> & value, Args &&... args)
1613 for(
const auto & el : value) { v.
add(el.first, el.second, std::forward<Args>(args)...); }
1624 template<
typename T,
typename C = std::less<T>,
typename A = std::allocator<T>,
typename... Args>
1625 void push(
const std::set<T, C, A> & value, Args &&... args)
1628 for(
const auto & v : value) { v.
push(*v, std::forward<Args>(args)...); }
1639 template<
typename T,
1640 typename H = std::hash<T>,
1641 typename E = std::equal_to<T>,
1642 typename A = std::allocator<T>,
1644 void push(
const std::unordered_set<T, H, E, A> & value, Args &&... args)
1647 for(
const auto & v : value) { v.
push(*v, std::forward<Args>(args)...); }
1660 template<
typename... Args>
1661 void push(
const std::variant<Args...> & value)
1664 v.
push(value.index());
1665 std::visit([&v](
const auto & hold) { v.
push(hold); }, value);
1683 std::vector<std::string>
keys()
const;
1693 template<
typename T>
1696 if constexpr(std::is_same_v<T, Configuration>) {
return *
this; }
1697 else {
return this->
operator T(); }
1749 inline const std::string &
path() const noexcept {
return path_; }
1755 #if MC_RTC_USE_VARIANT_WORKAROUND
1759 template<
size_t IDX,
typename... Args>
1760 std::variant<Args...> to_variant(
const Configuration & c,
size_t idx)
1766 if(idx == IDX) {
return c.operator std::variant_alternative_t<IDX, std::variant<Args...>>(); }
1767 else {
return to_variant<IDX + 1, Args...>(c, idx); }
1785 template<
typename FormatContext>
1788 return formatter<string_view>::format(
static_cast<std::string
>(c), ctx);
MC_RTC_UTILS_DLLAPI std::ostream & operator<<(std::ostream &os, const mc_rtc::Configuration &c)
Ostream operator.
Definition: Configuration.h:1780
Definition: generic_gripper.h:15
Gains< 3 > Gains3d
Definition: Gains.h:34
Gains< 2 > Gains2d
Definition: Gains.h:33
Gains< 6 > Gains6d
Definition: Gains.h:35
constexpr bool has_static_fromConfiguration_v
Definition: Configuration.h:107
constexpr bool has_toConfiguration_method_v
Definition: Configuration.h:149
constexpr bool has_configuration_save_object_v
Definition: Configuration.h:128
constexpr bool has_configuration_load_object_v
Definition: Configuration.h:88
void error_and_throw(Args &&... args)
Definition: logging.h:47
struct MC_RTC_UTILS_DLLAPI ConfigurationArrayIterator
Definition: Configuration.h:45
struct MC_RTC_UTILS_DLLAPI Configuration
Definition: Configuration.h:46
Definition: Configuration.h:1702
ConfigurationArrayIterator(const Configuration &conf)
bool operator!=(const ConfigurationArrayIterator &rhs) const
Configuration operator*()
ConfigurationArrayIterator & operator++()
Configuration conf
Definition: Configuration.h:1709
const Configuration operator*() const
Configuration object that keeps track of the file it comes from
Definition: Configuration.h:1736
ConfigurationFile(const std::string &path)
const std::string & path() const noexcept
Definition: Configuration.h:1749
static void save()
Definition: Configuration.h:66
static void load(const mc_rtc::Configuration &)
Definition: Configuration.h:65
Definition: Configuration.h:56
static void load(const mc_rtc::Configuration &)
Definition: Configuration.h:57
static void save(const T &)
Definition: Configuration.h:59
Exception thrown by this class when something bad occurs.
Definition: Configuration.h:237
void silence() const noexcept
Exception(const std::string &msg, const Configuration &c)
Constructor.
Definition: Configuration.h:252
Exception(const std::string &msg, const Json &v)
Constructor.
Simplify access to values hold within a JSON file.
Definition: Configuration.h:166
size_t size() const
If the stored value is an array, returns its size, otherwise returns 0.
void push(const Eigen::Vector4d &value)
Insert a Eigen::Vector4d element into an array.
static Configuration fromYAMLData(const char *data)
Static constructor to load from YAML data (C overload)
void push(const Configuration &value)
Push a Configuration element into an array.
void add(const std::string &key, const std::array< T, N > &value, Args &&... args)
Add an array into the JSON document.
Definition: Configuration.h:1433
void toMessagePack(MessagePackBuilder &builder) const
Append to an existing MessagePackBuilder.
void add(const std::string &key, const Eigen::Vector6d &value)
Add a Eigen::Vector6d element to the Configuration.
void loadData(const std::string &data)
Load data from a JSON string.
Configuration(const char *path)
Constructor using a file path (C-style string)
bool isUInt64() const noexcept
Definition: Configuration.h:905
void push(const Eigen::Quaterniond &value)
Insert a Eigen::Quaterniond element into an array.
void add(const std::string &key, const Configuration &value)
Add another Configuration to the Configuration.
void push(uint64_t value)
Insert a uint64_t element into an array.
void add(const std::string &key, int64_t value)
Add a int64_t element to the Configuration.
void push(const Eigen::Matrix3d &value)
Insert a Eigen::Matrix3d element into an array.
void push(int64_t value)
Insert a int64_t element int64_to an array.
void add(const std::string &key, const std::vector< T, A > &value, Args &&... args)
Add a vector into the JSON document.
Definition: Configuration.h:1418
void push(int8_t value)
Insert a int8_t element int8_to an array.
bool empty() const
Returns true if the underlying array or underlying object is empty.
static Configuration fromYAMLData(const std::string &data)
Static constructor to load from YAML data.
void push(const std::variant< Args... > &value)
Push a variant object into the JSON document.
Definition: Configuration.h:1661
void push(bool value)
Insert a bool element into an array.
void push(const std::unordered_set< T, H, E, A > &value, Args &&... args)
Push an unordered set into the JSON document.
Definition: Configuration.h:1644
Configuration add(const std::string &key)
Create an empty object in the Configuration.
void add(const std::string &key, double value)
Add a double element to the Configuration.
void add(const std::string &key, const Eigen::Matrix3d &value)
Add a Eigen::Matrix3d element to the Configuration.
void push(int16_t value)
Insert a int16_t element int16_to an array.
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.
Definition: Configuration.h:1467
void push(const T &value)
Definition: Configuration.h:1396
void add(const std::string &key, const sva::MotionVecd &value)
Add an sva::MotionVecd element to the Configuration.
void push(int32_t value)
Insert a int32_t element int32_to an array.
void add(const std::string &key, const Eigen::Vector2d &value)
Add a Eigen::Vector2d element to the Configuration.
void push(const Eigen::VectorXd &value)
Insert a Eigen::VectorXd element into an array.
void push_null()
Insert a null value into an array.
T operator()(const std::string &key, const T &v) const
Retrieve a given value stored within the configuration with a default value.
Definition: Configuration.h:976
void add(const std::string &key, const Eigen::Quaterniond &value)
Add a Eigen::Quaterniond element to the Configuration.
void operator()(const std::string &key, T &v) const
Retrieve and store a given value stored within the configuration .
Definition: Configuration.h:953
void push(const sva::ForceVecd &value)
Insert an sva::ForceVecd element into an array.
void add(const std::string &key, const std::string &value)
Add a std::string element to the Configuration.
void add(const std::string &key, const Eigen::Matrix6d &value)
Add a Eigen::Matrix6d element to the Configuration.
void add(const std::string &key, uint8_t value)
Add a uint8_t element to the Configuration.
ConfigurationArrayIterator end() const
std::optional< Configuration > find(const std::string &key, Args &&... others) const
Return the Configuration entry at (key, others...) if it exists, std::nullopt otherwise.
Definition: Configuration.h:850
Configuration()
Creates an empty configuration.
void push(uint8_t value)
Insert a uint8_t element into an array.
void push(const T &value, Args &&... args)
User-defined conversion.
Definition: Configuration.h:1382
void push(const std::pair< T1, T2 > &value, Args &&... args)
Push a pair into the JSON document.
Definition: Configuration.h:1595
void add(const std::string &key, bool value)
Add a bool element to the Configuration.
void push(uint32_t value)
Insert a uint32_t element into an array.
std::vector< std::string > keys() const
void load(const mc_rtc::Configuration &config)
Load data from another Configuration object.
void push(const Eigen::Vector3d &value)
Insert a Eigen::Vector3d element into an array.
bool isObject() const noexcept
Returns true if the underlying value is an object.
Definition: Configuration.h:889
bool isNumeric() const noexcept
Returns true if the underlying value is numeric.
Definition: Configuration.h:895
void save(const std::string &path, bool pretty=true) const
Save the configuration to a file.
void push(const std::array< T, N > &value, Args &&... args)
Push an array into the JSON document.
Definition: Configuration.h:1584
Configuration object()
Push an empty object.
void add(const std::string &key, uint64_t value)
Add a uint64_t element to the Configuration.
bool isInt64() const noexcept
Definition: Configuration.h:901
static Configuration fromMessagePack(const char *data, size_t size)
Static constructor to load from MessagePack data.
void push(const Eigen::Vector6d &value)
Insert a Eigen::Vector6d element into an array.
bool operator==(const char *rhs) const
Non-template version for C-style strings comparison.
std::optional< T > find(const std::string &key, Args &&... others) const
Return the Configuration entry at (key, others...) if it exists, std::nullopt otherwise.
Definition: Configuration.h:867
std::optional< Configuration > find(const std::string &key) const
Returns the Configuration entry if it exists, std::nullopt otherwise.
Configuration array(const std::string &key, size_t size=0)
Create an empty array in the Configuration.
void push(const sva::ImpedanceVecd &value)
Insert an sva::ImpedanceVecd element into an array.
Configuration array(size_t reserve=0)
Push an empty array.
bool isArray() const noexcept
Returns true if the underlying value is an array.
Definition: Configuration.h:886
void add(const std::string &key, uint32_t value)
Add a uint32_t element to the Configuration.
void add(const std::string &key, const Eigen::Vector3d &value)
Add a Eigen::Vector3d element to the Configuration.
T at(size_t i, const T &v) const
Retrieve a given value from a JSON array.
Definition: Configuration.h:927
void add(const std::string &key, int32_t value)
Add a int32_t element to the Configuration.
void add(const std::string &key, const T &value, Args &&... args)
User-defined conversion.
Definition: Configuration.h:1559
void add(const std::string &key, const T &value)
Definition: Configuration.h:1532
void add_null(const std::string &key)
Add a null element to the configuration.
bool isUInt32() const noexcept
Definition: Configuration.h:903
void add(const std::string &key, const sva::ForceVecd &value)
Add an sva::ForceVecd element to the Configuration.
void add(const std::string &key, const std::variant< Args... > &value)
Add a variant object into the JSON document.
Definition: Configuration.h:1518
void push(const std::vector< T, A > &value, Args &&... args)
Push a vector into the JSON document.
Definition: Configuration.h:1573
bool isDouble() const noexcept
Definition: Configuration.h:907
void add(const std::string &key, const Eigen::VectorXd &value)
Add a Eigen::VectorXd element to the Configuration.
void push(const Eigen::Matrix6d &value)
Insert a Eigen::Matrix6d element into an array.
bool operator==(const T &rhs) const
Compare stored values with given value.
Definition: Configuration.h:1000
void loadYAMLData(const std::string &data)
Load data from a YAML string.
void add(const std::string &key, const sva::ImpedanceVecd &value)
Add an sva::ImpedanceVecd element to the Configuration.
static Configuration rootArray()
Returns a Configuration with an array as root entry.
void push(const std::set< T, C, A > &value, Args &&... args)
Push a set into the JSON document.
Definition: Configuration.h:1625
void push(const std::map< std::string, T, C, A > &value, Args &&... args)
Push a string-indexed map into the JSON document.
Definition: Configuration.h:1610
bool isString() const noexcept
Returns true if the underlying value is a string.
Definition: Configuration.h:892
void push(const sva::MotionVecd &value)
Insert an sva::MotionVecd element into an array.
void add(const std::string &key, uint16_t value)
Add a uint16_t element to the Configuration.
void add(const std::string &key, const Eigen::Vector4d &value)
Add a Eigen::Vector4d element to the Configuration.
size_t toMessagePack(std::vector< char > &data) const
Convert to MessagePack.
bool isInt32() const noexcept
Definition: Configuration.h:899
void add(const std::string &key, const std::set< T, C, A > &value, Args &&... args)
Add a set into the JSON document.
Definition: Configuration.h:1482
void push(const sva::PTransformd &value)
Insert an sva::PTransformd element into an array.
void add(const std::string &key, const char *value)
Add a const char* element to the Configuration, Behaves like std::string.
void load(const std::string &path)
Load more data into the configuration.
void push(const Eigen::Vector2d &value)
Insert a Eigen::Vector2d element into an array.
static Configuration fromData(const std::string &data)
Static constructor to load from JSON data.
void push(const Eigen::MatrixXd &value)
Insert a Eigen::MatrixXd element into an array.
Configuration operator()(const std::string &key) const
Returns a Entry value stored within the configuration.
void add(const std::string &key, int16_t value)
Add a int16_t element to the Configuration.
void add(const std::string &key, int8_t value)
Add a int64_t element to the Configuration.
void push(uint16_t value)
Insert a uint16_t element into an array.
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.
Definition: Configuration.h:1501
void push(const char *value)
Insert a const char * element into an array Behaves like push(std::string)
ConfigurationArrayIterator begin() const
static Configuration fromData(const char *data)
Static constructor to load from JSON data (C overload)
bool remove(const std::string &key)
Configuration(const std::string &path)
Constructor using a file path.
bool isInteger() const noexcept
Definition: Configuration.h:897
void push(const std::string &value)
Insert a std::string element into an array.
void add(const std::string &key, const sva::PTransformd &value)
Add an sva::PTransformd element to the Configuration.
Configuration operator[](size_t i) const
If the stored value is an array, return a Configuration element for the i-th element.
void add(const std::string &key, const std::pair< T1, T2 > &value, Args &&... args)
Add a pair into the JSON document.
Definition: Configuration.h:1448
void add(const std::string &key, const Eigen::MatrixXd &value)
Add an Eigen::MatrixXd element to the Configuration.
void push(double value)
Insert a double element into an array.
std::string dump(bool pretty=false, bool yaml=false) const
Dump the configuration into a string.
Definition: MessagePackBuilder.h:87
Definition: Configuration.h:76
static std::true_type test(T *p)
static std::false_type test(...)
Definition: Configuration.h:114
static std::false_type test(...)
static std::true_type test(T *p)
Definition: Configuration.h:96
static std::false_type test(...)
static std::true_type test(T *p)
Definition: Configuration.h:136
static std::false_type test(...)
static std::true_type test(T *p)
#define MC_RTC_UTILS_DLLAPI
Definition: utils_api.h:50