Skip to content

Commit 7a68737

Browse files
committed
Remove SignalCaster and related class.
1 parent 7041c7d commit 7a68737

File tree

8 files changed

+11
-532
lines changed

8 files changed

+11
-532
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ SET(${PROJECT_NAME}_HEADERS
7474
include/${CUSTOM_HEADER_DIR}/signal.t.cpp
7575
include/${CUSTOM_HEADER_DIR}/time-dependency.h
7676
include/${CUSTOM_HEADER_DIR}/time-dependency.t.cpp
77+
# Kept for a brittle backward compatiblity.
7778
include/${CUSTOM_HEADER_DIR}/signal-caster.h
7879
include/${CUSTOM_HEADER_DIR}/signal-cast-helper.h
7980
include/${CUSTOM_HEADER_DIR}/all-signals.h
@@ -117,8 +118,6 @@ SET(${PROJECT_NAME}_SOURCES
117118
src/mt/process-list.cpp
118119
119120
src/signal/signal-array.cpp
120-
src/signal/signal-caster.cpp
121-
src/signal/signal-cast-helper.cpp
122121
123122
src/command/value.cpp
124123
src/command/command.cpp

include/dynamic-graph/fwd.hh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@ class OutStringStream;
2323
class PluginLoader;
2424
class PoolStorage;
2525

26-
class SignalCaster;
27-
class SignalCastRegisterer;
28-
2926
class Tracer;
3027
class TracerRealTime;
3128

32-
template <typename T> class DefaultCastRegisterer;
33-
3429
template <typename T, typename Time> class Signal;
3530

3631
template <typename Time> class SignalArray;

include/dynamic-graph/signal-cast-helper.h

Lines changed: 1 addition & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -5,175 +5,7 @@
55

66
#ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH
77
#define DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH
8-
#include <map>
9-
#include <typeinfo>
10-
#include <vector>
118

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"
17810

17911
#endif // #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH

include/dynamic-graph/signal-caster.h

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,17 @@
55
#ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HH
66
#define DYNAMIC_GRAPH_SIGNAL_CASTER_HH
77
#include <map>
8-
#include <typeinfo>
98
#include <vector>
109

11-
#include <boost/any.hpp>
1210
#include <boost/format.hpp>
13-
#include <boost/function/function1.hpp>
14-
#include <boost/function/function2.hpp>
1511
#include <boost/lexical_cast.hpp>
16-
#include <boost/tuple/tuple.hpp>
1712

1813
#include "dynamic-graph/exception-signal.h"
1914
#include <dynamic-graph/dynamic-graph-api.h>
2015
#include <dynamic-graph/linear-algebra.h>
2116
#include <dynamic-graph/eigen-io.h>
2217

2318
namespace dynamicgraph {
24-
/// This singleton class allows serialization of a number of objects into
25-
/// (disp) and from (cast) std i/o streams.
26-
///
27-
/// The transformation is done at run-time, i.e. SignalCaster
28-
/// doesn't know about the type of objects it casts to.
29-
///
30-
/// It also allows registering of user-defined casts. A cast is
31-
/// identified by the compiler. The mapping from a type to a
32-
/// serialization function is dynamic, hence it is more complex than
33-
/// a typical template-based compile-time resolve. So disp, cast and
34-
/// trace are costly functions and should be used as such.
35-
class DYNAMIC_GRAPH_DLLAPI SignalCaster {
36-
public:
37-
virtual ~SignalCaster();
38-
/// Destroy the unique instance.
39-
static void destroy();
40-
/// Typedef of displayer functions that take an encapsulated 'any'
41-
/// object and displays, cast, or trace it on an output stream
42-
/// (serialization).
43-
typedef boost::function1<boost::any, std::istringstream &> caster_type;
44-
45-
/// Get a reference to the unique object of the class.
46-
static SignalCaster *getInstance(void);
47-
/// Casts an object using a registered cast function.
48-
boost::any cast(const std::type_info &, std::istringstream &iss);
49-
/// Registers a cast.
50-
void registerCast(const std::type_info &type,
51-
caster_type caster);
52-
/// Unregister a cast.
53-
void unregisterCast(const std::type_info &type);
54-
/// Checks if there is a displayer registered with type_name.
55-
bool existsCast(const std::type_info &type) const;
56-
/// Return the list of type names registered.
57-
std::vector<std::string> listTypenames() const;
58-
59-
private:
60-
/// Container for the three cast functions.
61-
typedef boost::tuple<caster_type>
62-
cast_functions_type;
63-
64-
/// \brief Retrieve cast structure from its name.
65-
cast_functions_type &getCast(const std::string &type_name);
66-
67-
/// This map associates the typename of objects and the corresponding
68-
/// using boost::function with 'compatible' syntax
69-
std::map<std::string, cast_functions_type> functions_;
70-
71-
std::map<std::string, const std::type_info *> type_info_;
72-
73-
private:
74-
explicit SignalCaster();
75-
/// Pointer to the unique instance of the class.
76-
static SignalCaster *instance_;
77-
};
78-
79-
/// The SignalCast registerer class. Can be used to automatically
80-
/// register a cast when instanced somewhere in a cpp file. Pass the
81-
/// typeid () of the type you want to register a cast to as the first
82-
/// argument. The code is provided here so the class does not need
83-
/// to be exported.
84-
class DYNAMIC_GRAPH_DLLAPI SignalCastRegisterer {
85-
public:
86-
inline SignalCastRegisterer(const std::type_info &type,
87-
SignalCaster::caster_type caster) {
88-
SignalCaster::getInstance()->registerCast(type, caster);
89-
}
90-
};
91-
9219
/// Template class used to serialize a signal value.
9320
template <typename T> struct signal_disp {
9421
inline static void run (const T &value, std::ostream &os) { os << value << '\n'; }

src/signal/signal-cast-helper.cpp

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)