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;
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)");