Skip to content

Commit 6fe6872

Browse files
committed
Remove DefaultCastRegisterer::disp
1 parent e3eeee4 commit 6fe6872

File tree

6 files changed

+9
-47
lines changed

6 files changed

+9
-47
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@ template <typename T>
3333
class DefaultCastRegisterer : public SignalCastRegisterer {
3434
public:
3535
DefaultCastRegisterer()
36-
: SignalCastRegisterer(typeid(T), disp, cast) {}
36+
: SignalCastRegisterer(typeid(T), cast) {}
3737

3838
static boost::any cast(std::istringstream &iss);
39-
40-
static void disp(const boost::any &object, std::ostream &os) {
41-
os << boost::any_cast<T>(object) << std::endl;
42-
}
4339
};
4440

4541
/// A default version of the caster, to serialize directly from
@@ -76,16 +72,12 @@ boost::any DefaultCastRegisterer<T>::cast(std::istringstream &iss) {
7672
template <class T> class SignalCast {
7773
public:
7874
static T cast(std::istringstream &) { throw 1; }
79-
static void disp(const T &, std::ostream &) { throw 1; }
8075

8176
public:
8277
// adapter functions for SignalCast
8378
static boost::any cast_(std::istringstream &stringValue) {
8479
return boost::any_cast<T>(cast(stringValue));
8580
}
86-
static void disp_(const boost::any &t, std::ostream &os) {
87-
disp(boost::any_cast<T>(t), os);
88-
}
8981

9082
private:
9183
SignalCast() {}

include/dynamic-graph/signal-caster.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,14 @@ class DYNAMIC_GRAPH_DLLAPI SignalCaster {
3939
/// Typedef of displayer functions that take an encapsulated 'any'
4040
/// object and displays, cast, or trace it on an output stream
4141
/// (serialization).
42-
typedef boost::function2<void, const boost::any &, std::ostream &>
43-
displayer_type;
4442
typedef boost::function1<boost::any, std::istringstream &> caster_type;
4543

4644
/// Get a reference to the unique object of the class.
4745
static SignalCaster *getInstance(void);
48-
/// Displays an object using a registered displayer function.
49-
void disp(const boost::any &object, std::ostream &os);
5046
/// Casts an object using a registered cast function.
5147
boost::any cast(const std::type_info &, std::istringstream &iss);
5248
/// Registers a cast.
53-
void registerCast(const std::type_info &type, displayer_type displayer,
49+
void registerCast(const std::type_info &type,
5450
caster_type caster);
5551
/// Unregister a cast.
5652
void unregisterCast(const std::type_info &type);
@@ -61,7 +57,7 @@ class DYNAMIC_GRAPH_DLLAPI SignalCaster {
6157

6258
private:
6359
/// Container for the three cast functions.
64-
typedef boost::tuple<displayer_type, caster_type>
60+
typedef boost::tuple<caster_type>
6561
cast_functions_type;
6662

6763
/// \brief Retrieve cast structure from its name.
@@ -87,9 +83,8 @@ class DYNAMIC_GRAPH_DLLAPI SignalCaster {
8783
class DYNAMIC_GRAPH_DLLAPI SignalCastRegisterer {
8884
public:
8985
inline SignalCastRegisterer(const std::type_info &type,
90-
SignalCaster::displayer_type displayer,
9186
SignalCaster::caster_type caster) {
92-
SignalCaster::getInstance()->registerCast(type, displayer, caster);
87+
SignalCaster::getInstance()->registerCast(type, caster);
9388
}
9489
};
9590

src/signal/signal-cast-helper.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ DefaultCastRegisterer<std::string>::cast(std::istringstream &iss) {
6161
return inst;
6262
}
6363

64-
// for std::string, do not add std::endl at the end of the stream.
65-
template <>
66-
inline void DefaultCastRegisterer<std::string>::disp(const boost::any &object,
67-
std::ostream &os) {
68-
os << boost::any_cast<std::string>(object);
69-
}
70-
7164
/// Registers useful casts
7265
namespace {
7366
DefaultCastRegisterer<double> double_reg;

src/signal/signal-caster.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ void SignalCaster::destroy() {
2727
}
2828

2929
void SignalCaster::registerCast(const std::type_info &type,
30-
SignalCaster::displayer_type displayer,
3130
SignalCaster::caster_type caster) {
3231
if (existsCast(type)) {
3332
// If type name has already been registered for same type, do not throw.
@@ -44,7 +43,7 @@ void SignalCaster::registerCast(const std::type_info &type,
4443
throw ExceptionSignal(ExceptionSignal::GENERIC, os.str());
4544
}
4645
}
47-
functions_[type.name()] = cast_functions_type(displayer, caster);
46+
functions_[type.name()] = cast_functions_type(caster);
4847
type_info_[type.name()] = &type;
4948
}
5049

@@ -70,10 +69,6 @@ SignalCaster::getCast(const std::string &type_name) {
7069
return it->second;
7170
}
7271

73-
void SignalCaster::disp(const boost::any &object, std::ostream &os) {
74-
getCast(object.type().name()).get<0>()(object, os);
75-
}
76-
7772
std::vector<std::string> SignalCaster::listTypenames() const {
7873
std::vector<std::string> typeList;
7974
for (std::map<std::string, cast_functions_type>::const_iterator iter =
@@ -85,7 +80,7 @@ std::vector<std::string> SignalCaster::listTypenames() const {
8580

8681
boost::any SignalCaster::cast(const std::type_info &type,
8782
std::istringstream &iss) {
88-
return getCast(type.name()).get<1>()(iss);
83+
return getCast(type.name()).get<0>()(iss);
8984
}
9085

9186
/// Singleton on the library-wide instance of SignalCaster

tests/signal-all.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(signal_caster_basics) {
223223
double ad = 2.0;
224224
output_test_stream output;
225225
try {
226-
asig_caster->disp(ad, output);
226+
signal_disp<double>::run(ad, output);
227227
} catch (ExceptionSignal &aes) {
228228
res = (aes.getCode() == ExceptionSignal::BAD_CAST);
229229
}

tests/signal-cast-registerer.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,27 @@ struct EigenCastRegisterer_V : public dynamicgraph::SignalCastRegisterer {
3535
typedef Vector bnuVector;
3636

3737
EigenCastRegisterer_V()
38-
: SignalCastRegisterer(typeid(bnuVector), dispVector, castVector) {}
38+
: SignalCastRegisterer(typeid(bnuVector), castVector) {}
3939

4040
static boost::any castVector(std::istringstream &iss) {
4141
bnuVector res;
4242
iss >> res;
4343
return res;
4444
}
45-
46-
static void dispVector(const boost::any &object, std::ostream &os) {
47-
const bnuVector &v = boost::any_cast<bnuVector>(object);
48-
os << "[ ";
49-
for (int i = 0; i < v.size(); ++i)
50-
os << v(i) << " ";
51-
os << " ];" << std::endl;
52-
}
5345
};
5446

5547
template <typename Derived>
5648
struct EigenCastRegisterer_M : public dynamicgraph::SignalCastRegisterer {
5749
typedef Matrix bnuMatrix;
5850

5951
EigenCastRegisterer_M()
60-
: SignalCastRegisterer(typeid(bnuMatrix), dispMatrix, castMatrix) {}
52+
: SignalCastRegisterer(typeid(bnuMatrix), castMatrix) {}
6153

6254
static boost::any castMatrix(std::istringstream &iss) {
6355
bnuMatrix res;
6456
iss >> res;
6557
return res;
6658
}
67-
68-
static void dispMatrix(const boost::any &object, std::ostream &os) {
69-
const bnuMatrix &m = boost::any_cast<bnuMatrix>(object);
70-
os << m << std::endl;
71-
}
7259
};
7360

7461
EigenCastRegisterer_V myVectorCast;

0 commit comments

Comments
 (0)