|
5 | 5 |
|
6 | 6 | #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH
|
7 | 7 | #define DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH
|
8 |
| -#include <map> |
9 |
| -#include <typeinfo> |
10 |
| -#include <vector> |
11 | 8 |
|
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> |
18 |
| - |
19 |
| -#include <dynamic-graph/eigen-io.h> |
20 |
| - |
21 |
| -#include "dynamic-graph/exception-signal.h" |
22 |
| -#include "dynamic-graph/signal-caster.h" |
23 |
| -#include <dynamic-graph/dynamic-graph-api.h> |
24 |
| - |
25 |
| -namespace dynamicgraph { |
26 |
| - |
27 |
| -/* --- NON GENERIC CASTER ------------------------------------------------- */ |
28 |
| - |
29 |
| -/// This class can be used to register default casts, i.e. casts |
30 |
| -/// already supported by the object to an std::iostream through the |
31 |
| -/// operators >> and << . |
32 |
| -template <typename T> |
33 |
| -class DefaultCastRegisterer : public SignalCastRegisterer { |
34 |
| -public: |
35 |
| - DefaultCastRegisterer() |
36 |
| - : SignalCastRegisterer(typeid(T), cast) {} |
37 |
| - |
38 |
| - static boost::any cast(std::istringstream &iss); |
39 |
| -}; |
40 |
| - |
41 |
| -/// A default version of the caster, to serialize directly from |
42 |
| -/// std::in. |
43 |
| -template <typename T> |
44 |
| -boost::any DefaultCastRegisterer<T>::cast(std::istringstream &iss) { |
45 |
| - T inst; |
46 |
| - iss >> inst; |
47 |
| - if (iss.fail()) { |
48 |
| - boost::format fmt("failed to serialize %s "); |
49 |
| - fmt % iss.str(); |
50 |
| - throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); |
51 |
| - } |
52 |
| - return inst; |
53 |
| -} |
54 |
| - |
55 |
| -/* --- GENERIC CASTER ----------------------------------------------------- */ |
56 |
| -/*! |
57 |
| - * This class is only used to group together static functions who differ by |
58 |
| - * a template parameter. It is never actually instanced |
59 |
| - * (the private constructor |
60 |
| - * makes sure of that). |
61 |
| - * Typical use of this class is to add the caster in the dg graph: |
62 |
| - * dynamicgraph::SignalCastRegisterer sotCastRegisterer_TYPE |
63 |
| - * (typeid(TYPE), |
64 |
| - * SignalCast<TYPE>::disp_, |
65 |
| - * SignalCast<TYPE>::cast_, |
66 |
| - * SignalCast<TYPE>::trace_); |
67 |
| -
|
68 |
| - * NMSD: I don't really understand the use of this additional class. IMHO |
69 |
| - * (comme on dit), it should be possible to rewrite the same-spec macros |
70 |
| - * using specialization of the template class DefaultCastRegisterer. No? |
71 |
| - */ |
72 |
| -template <class T> class SignalCast { |
73 |
| -public: |
74 |
| - static T cast(std::istringstream &) { throw 1; } |
75 |
| - |
76 |
| -public: |
77 |
| - // adapter functions for SignalCast |
78 |
| - static boost::any cast_(std::istringstream &stringValue) { |
79 |
| - return boost::any_cast<T>(cast(stringValue)); |
80 |
| - } |
81 |
| - |
82 |
| -private: |
83 |
| - SignalCast() {} |
84 |
| -}; |
85 |
| - |
86 |
| -} // namespace dynamicgraph |
87 |
| - |
88 |
| -/* -------------------------------------------------------------------------- */ |
89 |
| -/* --- MACROS --------------------------------------------------------------- */ |
90 |
| -/* -------------------------------------------------------------------------- */ |
91 |
| - |
92 |
| -/* Declaration macro: one instance of each class needs to be present in |
93 |
| - * order for casts to be registered. |
94 |
| - */ |
95 |
| - |
96 |
| -#define DG_SIGNAL_CAST_DECLARATION(TYPE) \ |
97 |
| - ::dynamicgraph::SignalCastRegisterer sotCastRegisterer_##TYPE( \ |
98 |
| - typeid(TYPE), SignalCast<TYPE>::disp_, SignalCast<TYPE>::cast_, \ |
99 |
| - SignalCast<TYPE>::trace_) |
100 |
| - |
101 |
| -#define DG_SIGNAL_CAST_DECLARATION_NAMED(TYPE, NAME) \ |
102 |
| - ::dynamicgraph::SignalCastRegisterer sotCastRegisterer_##NAME( \ |
103 |
| - typeid(TYPE), SignalCast<TYPE>::disp_, SignalCast<TYPE>::cast_, \ |
104 |
| - SignalCast<TYPE>::trace_) |
105 |
| - |
106 |
| -/* Standard definition macros: the three functions can be specified |
107 |
| - * in the macros. To define then in the cpp, just put ';' in the args. |
108 |
| - */ |
109 |
| -#define DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, CAST, DISP, TRACE) \ |
110 |
| - template <> class SignalCast<TYPE> { \ |
111 |
| - public: \ |
112 |
| - static TYPE cast(std::istringstream &iss) CAST \ |
113 |
| - static void disp(TYPE const &t, std::ostream &os) DISP \ |
114 |
| - static void trace(TYPE const &t, std::ostream &os) TRACE public \ |
115 |
| - : static boost::any cast_(std::istringstream &stringValue) { \ |
116 |
| - return boost::any_cast<TYPE>(cast(stringValue)); \ |
117 |
| - } \ |
118 |
| - static void disp_(const boost::any &t, std::ostream &os) { \ |
119 |
| - disp(boost::any_cast<TYPE>(t), os); \ |
120 |
| - } \ |
121 |
| - static void trace_(const boost::any &t, std::ostream &os) { \ |
122 |
| - trace(boost::any_cast<TYPE>(t), os); \ |
123 |
| - } \ |
124 |
| - } |
125 |
| - |
126 |
| -/* Standard definition macros: the functions <cast> and <disp> have |
127 |
| - * to be implemented in the cpp files. The function <trace> is |
128 |
| - * implemented as a proxy on <disp>. |
129 |
| - */ |
130 |
| -#define DG_SIGNAL_CAST_DEFINITION_HPP(TYPE) \ |
131 |
| - DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, ;, ;, { disp(t, os); }) |
132 |
| - |
133 |
| -/* Lazy definition: <cast> and <disp> are to proxys on the standard |
134 |
| - * std input (>>) and output (<<). The function <trace> has to be |
135 |
| - * implemented in the cpp. |
136 |
| - */ |
137 |
| -#define DG_SIGNAL_CAST_DEFINITION_TRACE_HPP(TYPE, TRACE) \ |
138 |
| - DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, \ |
139 |
| - { \ |
140 |
| - TYPE res; \ |
141 |
| - iss >> res; \ |
142 |
| - return res; \ |
143 |
| - }, \ |
144 |
| - { os << t << std::endl; }, TRACE) |
145 |
| - |
146 |
| -/* Lazy lazy definition: the three functions are implemented as |
147 |
| - * proxys on std::io operation. |
148 |
| - */ |
149 |
| -#define DG_SIGNAL_CAST_DEFINITION(TYPE) \ |
150 |
| - DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, \ |
151 |
| - { \ |
152 |
| - TYPE res; \ |
153 |
| - iss >> res; \ |
154 |
| - return res; \ |
155 |
| - }, \ |
156 |
| - { os << t << std::endl; }, { disp(t, os); }) |
157 |
| - |
158 |
| -/* Lazy definition of <cast> and <disp> with implementation of |
159 |
| - * <trace> in the cpp. |
160 |
| - */ |
161 |
| -#define DG_SIGNAL_CAST_DEFINITION_TRACE(TYPE) \ |
162 |
| - DG_SIGNAL_CAST_FULL_DEFINITION(TYPE, \ |
163 |
| - { \ |
164 |
| - TYPE res; \ |
165 |
| - iss >> res; \ |
166 |
| - return res; \ |
167 |
| - }, \ |
168 |
| - { os << t << std::endl; }, \ |
169 |
| - ;) |
170 |
| - |
171 |
| -/* Macro to add the define SignalCast in the dg graph. Typical use is: |
172 |
| - * DG_ADD_CASTER( Matrix,matrix ) |
173 |
| - */ |
174 |
| -#define DG_ADD_CASTER(TYPE, ID) \ |
175 |
| - ::dynamicgraph::SignalCastRegisterer sotCastRegisterer_##ID( \ |
176 |
| - typeid(TYPE), SignalCast<TYPE>::disp_, SignalCast<TYPE>::cast_, \ |
177 |
| - SignalCast<TYPE>::trace_) |
| 9 | +#pragma warning "This file is now useless" |
178 | 10 |
|
179 | 11 | #endif // #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH
|
0 commit comments