5 #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HH 6 #define DYNAMIC_GRAPH_SIGNAL_CASTER_HH 11 #include <boost/format.hpp> 12 #include <boost/lexical_cast.hpp> 25 inline static void disp(
const T &value, std::ostream &os) { os << value; }
27 inline static T
cast(std::istringstream &is) {
32 "failed to serialize " + is.str());
37 inline static void trace(
const T &value, std::ostream &os) { os << value; }
43 inline static void disp(
const T &, std::ostream &) {
44 throw std::logic_error(
"this disp is not implemented.");
46 inline static T
cast(std::istringstream &) {
47 throw std::logic_error(
"this cast is not implemented.");
49 inline static void trace(
const T &, std::ostream &) {
50 throw std::logic_error(
"this trace is not implemented.");
59 template <
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
62 Eigen::
Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>>
64 Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>> {
65 typedef Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
69 static const Eigen::IOFormat row_format(
70 Eigen::StreamPrecision, Eigen::DontAlignCols,
" ",
" ",
"",
"",
"",
"");
71 os << value.format(row_format);
75 static const Eigen::IOFormat row_format(Eigen::StreamPrecision,
76 Eigen::DontAlignCols,
"\t",
"\t",
78 os << value.format(row_format);
83 template <
typename _Scalar,
int _Options>
86 typedef Eigen::Quaternion<_Scalar, _Options>
quat_type;
89 inline static void disp(
const quat_type &value, std::ostream &os) {
93 inline static quat_type
cast(std::istringstream &is) {
97 inline static void trace(
const quat_type &value, std::ostream &os) {
106 inline static std::string
cast(std::istringstream &iss) {
return iss.str(); }
123 inline static double cast(std::istringstream &iss) {
124 std::string tmp(iss.str());
127 return std::numeric_limits<double>::quiet_NaN();
128 else if (tmp ==
"inf" || tmp ==
"+inf")
129 return std::numeric_limits<double>::infinity();
130 else if (tmp ==
"-inf")
131 return -1. * std::numeric_limits<double>::infinity();
134 return boost::lexical_cast<
double>(tmp);
135 }
catch (boost::bad_lexical_cast &) {
136 boost::format fmt(
"failed to serialize %s (to double)");
static T cast(std::istringstream &)
static void disp(const quat_type &value, std::ostream &os)
Class used for I/O operations in Signal<T,Time>
static void disp(const matrix_type &value, std::ostream &os)
static T cast(std::istringstream &is)
deserialize a signal value.
Eigen::Matrix< _Scalar, 4, 1, _Options > matrix_type
static double cast(std::istringstream &iss)
Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > matrix_type
Exceptions raised when an error related to signals happen.
static void trace(const quat_type &value, std::ostream &os)
Inherit from this class if tracing is not implemented for a given type.
Eigen::Quaternion< _Scalar, _Options > quat_type
static void trace(const T &, std::ostream &)
static quat_type cast(std::istringstream &is)
static std::string cast(std::istringstream &iss)
static void disp(const T &value, std::ostream &os)
serialize a signal value.
static void trace(const matrix_type &value, std::ostream &os)
static void disp(const T &, std::ostream &)
static void trace(const T &value, std::ostream &os)
write a signal value to log file