6 #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH 7 #define DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH 12 #include <boost/any.hpp> 13 #include <boost/format.hpp> 14 #include <boost/function/function1.hpp> 15 #include <boost/function/function2.hpp> 16 #include <boost/lexical_cast.hpp> 17 #include <boost/tuple/tuple.hpp> 19 #include <dynamic-graph/eigen-io.h> 21 #include "dynamic-graph/exception-signal.h" 22 #include "dynamic-graph/signal-caster.h" 23 #include <dynamic-graph/dynamic-graph-api.h> 33 class DefaultCastRegisterer :
public SignalCastRegisterer {
35 DefaultCastRegisterer()
36 : SignalCastRegisterer(typeid(T), disp,
cast, trace) {}
38 static boost::any
cast(std::istringstream &iss);
40 static void disp(
const boost::any &
object, std::ostream &os) {
41 os << boost::any_cast<T>(object) << std::endl;
44 static void trace(
const boost::any &
object, std::ostream &os) {
56 boost::format fmt(
"failed to serialize %s ");
82 static T
cast(std::istringstream &) {
throw 1; }
83 static void disp(
const T &, std::ostream &) {
throw 1; }
84 static void trace(
const T &t, std::ostream &os) { disp(t, os); }
88 static boost::any cast_(std::istringstream &stringValue) {
89 return boost::any_cast<T>(
cast(stringValue));
91 static void disp_(
const boost::any &t, std::ostream &os) {
92 disp(boost::any_cast<T>(t), os);
94 static void trace_(
const boost::any &t, std::ostream &os) {
95 trace(boost::any_cast<T>(t), os);
112 #define DG_SIGNAL_CAST_DECLARATION(TYPE) \ 113 ::dynamicgraph::SignalCastRegisterer sotCastRegisterer_##TYPE( \ 114 typeid(TYPE), SignalCast<TYPE>::disp_, SignalCast<TYPE>::cast_, \ 115 SignalCast<TYPE>::trace_) 117 #define DG_SIGNAL_CAST_DECLARATION_NAMED(TYPE, NAME) \ 118 ::dynamicgraph::SignalCastRegisterer sotCastRegisterer_##NAME( \ 119 typeid(TYPE), SignalCast<TYPE>::disp_, SignalCast<TYPE>::cast_, \ 120 SignalCast<TYPE>::trace_) 125 #define DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, CAST, DISP, TRACE) \ 126 template <> class SignalCast<TYPE> { \ 128 static TYPE cast(std::istringstream &iss) CAST \ 129 static void disp(TYPE const &t, std::ostream &os) DISP \ 130 static void trace(TYPE const &t, std::ostream &os) TRACE public \ 131 : static boost::any cast_(std::istringstream &stringValue) { \ 132 return boost::any_cast<TYPE>(cast(stringValue)); \ 134 static void disp_(const boost::any &t, std::ostream &os) { \ 135 disp(boost::any_cast<TYPE>(t), os); \ 137 static void trace_(const boost::any &t, std::ostream &os) { \ 138 trace(boost::any_cast<TYPE>(t), os); \ 146 #define DG_SIGNAL_CAST_DEFINITION_HPP(TYPE) \ 147 DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, ;, ;, { disp(t, os); }) 153 #define DG_SIGNAL_CAST_DEFINITION_TRACE_HPP(TYPE, TRACE) \ 154 DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, \ 160 { os << t << std::endl; }, TRACE) 165 #define DG_SIGNAL_CAST_DEFINITION(TYPE) \ 166 DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, \ 172 { os << t << std::endl; }, { disp(t, os); }) 177 #define DG_SIGNAL_CAST_DEFINITION_TRACE(TYPE) \ 178 DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, \ 184 { os << t << std::endl; }, \ 190 #define DG_ADD_CASTER(TYPE, ID) \ 191 ::dynamicgraph::SignalCastRegisterer sotCastRegisterer_##ID( \ 192 typeid(TYPE), SignalCast<TYPE>::disp_, SignalCast<TYPE>::cast_, \ 193 SignalCast<TYPE>::trace_) 195 #endif // #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH Exceptions raised when an error related to signals happen.
static boost::any cast(std::istringstream &iss)