Go to the documentation of this file.
7 #include <SpaceVecAlg/SpaceVecAlg>
16 #include <type_traits>
24 struct MessagePackBuilder;
25 struct MessagePackBuilderImpl;
31 constexpr
bool is_integral_v = std::is_integral_v<T> || std::numeric_limits<std::decay_t<T>>::is_integer;
34 template<
typename RefT,
typename T>
37 static_assert(std::is_integral_v<RefT>);
38 if constexpr(is_integral_v<T>)
41 return std::numeric_limits<T>::is_signed == std::is_signed_v<RefT>
42 && std::numeric_limits<T>::max() == std::numeric_limits<RefT>::max();
65 template<
typename T,
typename =
void>
110 void write(int8_t i);
112 void write(int16_t i);
114 void write(int32_t i);
116 void write(int64_t i);
118 void write(uint8_t i);
120 void write(uint16_t i);
122 void write(uint32_t i);
124 void write(uint64_t i);
128 void write(
double d);
130 void write(
const std::string & s);
132 void write(
const char * s);
134 void write(
const char * s,
size_t len);
153 void write(
const Eigen::Vector2d & v);
159 void write(
const Eigen::Vector3d & v);
165 void write(
const Eigen::Vector4d & v);
171 void write(
const Eigen::Vector6d & v);
177 void write(
const Eigen::VectorXd & v);
179 template<
int N,
int _Options,
int _MaxRows,
int _MaxCols>
180 void write(
const Eigen::Matrix<double, N, 1, _Options, _MaxRows, _MaxCols> & v)
182 static_assert(N != -1 && N != 2 && N != 3 && N != 6,
"Should have gone to specialized function");
183 start_array(
static_cast<size_t>(N));
184 for(Eigen::Index i = 0; i < N; ++i) {
write(v(i)); }
192 void write(
const Eigen::Quaterniond & q);
198 void write(
const Eigen::Matrix3d & m);
204 void write(
const sva::PTransformd & pt);
210 void write(
const sva::ForceVecd & fv);
216 void write(
const sva::MotionVecd & mv);
222 void write(
const sva::ImpedanceVecd & mv);
231 template<
typename T,
typename std::enable_if_t<
internal::is_
integral_v<T>,
int> = 0>
234 if constexpr(internal::is_like_int8_t<T>) {
write(
static_cast<int8_t
>(number)); }
235 else if constexpr(internal::is_like_int16_t<T>) {
write(
static_cast<int16_t
>(number)); }
236 else if constexpr(internal::is_like_int32_t<T>) {
write(
static_cast<int32_t
>(number)); }
237 else if constexpr(internal::is_like_int64_t<T>) {
write(
static_cast<int64_t
>(number)); }
238 else if constexpr(internal::is_like_uint8_t<T>) {
write(
static_cast<uint8_t
>(number)); }
239 else if constexpr(internal::is_like_uint16_t<T>) {
write(
static_cast<uint16_t
>(number)); }
240 else if constexpr(internal::is_like_uint32_t<T>) {
write(
static_cast<uint32_t
>(number)); }
241 else if constexpr(internal::is_like_uint64_t<T>) {
write(
static_cast<uint64_t
>(number)); }
242 else { static_assert(!std::is_same_v<T, T>,
"T is integral but has an unsupported size"); }
246 template<
typename T,
typename = std::enable_if_t<
internal::has_write_builder_v<T>>>
264 template<
typename T,
typename A>
265 void write(
const std::vector<T, A> & v)
267 start_array(v.size());
268 for(
const auto & value : v) {
write(value); }
273 template<
typename T, std::
size_t N>
274 void write(
const std::array<T, N> & a)
277 for(
const auto & value : a) {
write(value); }
282 template<
typename T1,
typename T2>
283 void write(
const std::pair<T1, T2> & p)
292 template<
typename KeyT,
typename T,
typename C,
typename A>
293 void write(
const std::map<KeyT, T, C, A> & m)
296 for(
const auto & p : m)
305 template<
typename T,
typename C,
typename A>
306 void write(
const std::set<T, C, A> & s)
308 start_array(s.size());
309 for(
const auto & value : s) {
write(value); }
314 template<
typename... Args>
315 void write(
const std::tuple<Args...> & t)
317 start_array(
sizeof...(Args));
323 template<
typename... Args>
324 void write(
const std::variant<Args...> & value)
327 write(value.index());
328 std::visit([
this](
const auto & v) {
write(v); }, value);
333 template<
typename Type,
int Options,
typename Str
ideType>
334 void write(
const Eigen::Ref<Type, Options, StrideType> & v)
336 #if !EIGEN_VERSION_AT_LEAST(3, 2, 90)
337 using Index = Eigen::DenseIndex;
339 using Index = Eigen::Index;
341 start_array(v.size());
342 for(Index i = 0; i < v.size(); ++i) {
write(v(i)); }
353 void start_array(
size_t size);
362 void start_map(
size_t size);
374 void write_object(
const char * data,
size_t s);
387 std::unique_ptr<MessagePackBuilderImpl> impl_;
391 typename std::enable_if<i<
sizeof...(Args),
int>::type = 0>
void write_impl(
const std::tuple<Args...> & t)
393 write(std::get<i>(t));
394 write_impl<i + 1>(t);
397 template<
size_t i,
typename... Args,
typename std::enable_if<i >=
sizeof...(Args),
int>::type = 0>
398 void write_impl(
const std::tuple<Args...> &)
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
constexpr bool is_like_int32_t
Definition: MessagePackBuilder.h:53
Definition: MessagePackBuilder.h:86
constexpr bool is_like_uint64_t
Definition: MessagePackBuilder.h:63
void write(const T &number)
Definition: MessagePackBuilder.h:232
void write(const std::map< KeyT, T, C, A > &m)
Definition: MessagePackBuilder.h:293
constexpr bool is_like()
Definition: MessagePackBuilder.h:35
void write(const std::pair< T1, T2 > &p)
Definition: MessagePackBuilder.h:283
constexpr bool is_like_int16_t
Definition: MessagePackBuilder.h:51
void write(const std::tuple< Args... > &t)
Definition: MessagePackBuilder.h:315
constexpr bool is_like_uint8_t
Definition: MessagePackBuilder.h:57
constexpr bool is_like_int8_t
Definition: MessagePackBuilder.h:49
Definition: MessagePackBuilder.h:66
void write(const std::variant< Args... > &value)
Definition: MessagePackBuilder.h:324
constexpr bool is_like_uint16_t
Definition: MessagePackBuilder.h:59
void write(const Eigen::Matrix< double, N, 1, _Options, _MaxRows, _MaxCols > &v)
Definition: MessagePackBuilder.h:180
void void_t
Definition: traits.h:25
void write(const T &value)
Definition: MessagePackBuilder.h:247
auto write(T &value)
Definition: traits.h:224
constexpr bool is_like_uint32_t
Definition: MessagePackBuilder.h:61
void write(const Eigen::Ref< Type, Options, StrideType > &v)
Definition: MessagePackBuilder.h:334
void write(const std::vector< T, A > &v)
Definition: MessagePackBuilder.h:265
void write(const std::set< T, C, A > &s)
Definition: MessagePackBuilder.h:306
constexpr bool is_integral_v
Definition: MessagePackBuilder.h:31
#define MC_RTC_UTILS_DLLAPI
Definition: utils_api.h:50
constexpr bool is_like_int64_t
Definition: MessagePackBuilder.h:55
struct MC_RTC_UTILS_DLLAPI Configuration
Definition: Configuration.h:46
void write(const std::array< T, N > &a)
Definition: MessagePackBuilder.h:274