Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
dynamic-graph
Commits
6fe68723
Commit
6fe68723
authored
Feb 25, 2020
by
Joseph Mirabel
Browse files
Remove DefaultCastRegisterer::disp
parent
e3eeee49
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/dynamic-graph/signal-cast-helper.h
View file @
6fe68723
...
...
@@ -33,13 +33,9 @@ template <typename T>
class
DefaultCastRegisterer
:
public
SignalCastRegisterer
{
public:
DefaultCastRegisterer
()
:
SignalCastRegisterer
(
typeid
(
T
),
disp
,
cast
)
{}
:
SignalCastRegisterer
(
typeid
(
T
),
cast
)
{}
static
boost
::
any
cast
(
std
::
istringstream
&
iss
);
static
void
disp
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
)
{
os
<<
boost
::
any_cast
<
T
>
(
object
)
<<
std
::
endl
;
}
};
/// A default version of the caster, to serialize directly from
...
...
@@ -76,16 +72,12 @@ boost::any DefaultCastRegisterer<T>::cast(std::istringstream &iss) {
template
<
class
T
>
class
SignalCast
{
public:
static
T
cast
(
std
::
istringstream
&
)
{
throw
1
;
}
static
void
disp
(
const
T
&
,
std
::
ostream
&
)
{
throw
1
;
}
public:
// adapter functions for SignalCast
static
boost
::
any
cast_
(
std
::
istringstream
&
stringValue
)
{
return
boost
::
any_cast
<
T
>
(
cast
(
stringValue
));
}
static
void
disp_
(
const
boost
::
any
&
t
,
std
::
ostream
&
os
)
{
disp
(
boost
::
any_cast
<
T
>
(
t
),
os
);
}
private:
SignalCast
()
{}
...
...
include/dynamic-graph/signal-caster.h
View file @
6fe68723
...
...
@@ -39,18 +39,14 @@ public:
/// Typedef of displayer functions that take an encapsulated 'any'
/// object and displays, cast, or trace it on an output stream
/// (serialization).
typedef
boost
::
function2
<
void
,
const
boost
::
any
&
,
std
::
ostream
&>
displayer_type
;
typedef
boost
::
function1
<
boost
::
any
,
std
::
istringstream
&>
caster_type
;
/// Get a reference to the unique object of the class.
static
SignalCaster
*
getInstance
(
void
);
/// Displays an object using a registered displayer function.
void
disp
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
);
/// Casts an object using a registered cast function.
boost
::
any
cast
(
const
std
::
type_info
&
,
std
::
istringstream
&
iss
);
/// Registers a cast.
void
registerCast
(
const
std
::
type_info
&
type
,
displayer_type
displayer
,
void
registerCast
(
const
std
::
type_info
&
type
,
caster_type
caster
);
/// Unregister a cast.
void
unregisterCast
(
const
std
::
type_info
&
type
);
...
...
@@ -61,7 +57,7 @@ public:
private:
/// Container for the three cast functions.
typedef
boost
::
tuple
<
displayer_type
,
caster_type
>
typedef
boost
::
tuple
<
caster_type
>
cast_functions_type
;
/// \brief Retrieve cast structure from its name.
...
...
@@ -87,9 +83,8 @@ private:
class
DYNAMIC_GRAPH_DLLAPI
SignalCastRegisterer
{
public:
inline
SignalCastRegisterer
(
const
std
::
type_info
&
type
,
SignalCaster
::
displayer_type
displayer
,
SignalCaster
::
caster_type
caster
)
{
SignalCaster
::
getInstance
()
->
registerCast
(
type
,
displayer
,
caster
);
SignalCaster
::
getInstance
()
->
registerCast
(
type
,
caster
);
}
};
...
...
src/signal/signal-cast-helper.cpp
View file @
6fe68723
...
...
@@ -61,13 +61,6 @@ DefaultCastRegisterer<std::string>::cast(std::istringstream &iss) {
return
inst
;
}
// for std::string, do not add std::endl at the end of the stream.
template
<
>
inline
void
DefaultCastRegisterer
<
std
::
string
>::
disp
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
)
{
os
<<
boost
::
any_cast
<
std
::
string
>
(
object
);
}
/// Registers useful casts
namespace
{
DefaultCastRegisterer
<
double
>
double_reg
;
...
...
src/signal/signal-caster.cpp
View file @
6fe68723
...
...
@@ -27,7 +27,6 @@ void SignalCaster::destroy() {
}
void
SignalCaster
::
registerCast
(
const
std
::
type_info
&
type
,
SignalCaster
::
displayer_type
displayer
,
SignalCaster
::
caster_type
caster
)
{
if
(
existsCast
(
type
))
{
// 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,
throw
ExceptionSignal
(
ExceptionSignal
::
GENERIC
,
os
.
str
());
}
}
functions_
[
type
.
name
()]
=
cast_functions_type
(
displayer
,
caster
);
functions_
[
type
.
name
()]
=
cast_functions_type
(
caster
);
type_info_
[
type
.
name
()]
=
&
type
;
}
...
...
@@ -70,10 +69,6 @@ SignalCaster::getCast(const std::string &type_name) {
return
it
->
second
;
}
void
SignalCaster
::
disp
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
)
{
getCast
(
object
.
type
().
name
()).
get
<
0
>
()(
object
,
os
);
}
std
::
vector
<
std
::
string
>
SignalCaster
::
listTypenames
()
const
{
std
::
vector
<
std
::
string
>
typeList
;
for
(
std
::
map
<
std
::
string
,
cast_functions_type
>::
const_iterator
iter
=
...
...
@@ -85,7 +80,7 @@ std::vector<std::string> SignalCaster::listTypenames() const {
boost
::
any
SignalCaster
::
cast
(
const
std
::
type_info
&
type
,
std
::
istringstream
&
iss
)
{
return
getCast
(
type
.
name
()).
get
<
1
>
()(
iss
);
return
getCast
(
type
.
name
()).
get
<
0
>
()(
iss
);
}
/// Singleton on the library-wide instance of SignalCaster
...
...
tests/signal-all.cpp
View file @
6fe68723
...
...
@@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(signal_caster_basics) {
double
ad
=
2.0
;
output_test_stream
output
;
try
{
a
sig
_caster
->
disp
(
ad
,
output
);
sig
nal_disp
<
double
>::
run
(
ad
,
output
);
}
catch
(
ExceptionSignal
&
aes
)
{
res
=
(
aes
.
getCode
()
==
ExceptionSignal
::
BAD_CAST
);
}
...
...
tests/signal-cast-registerer.cpp
View file @
6fe68723
...
...
@@ -35,21 +35,13 @@ struct EigenCastRegisterer_V : public dynamicgraph::SignalCastRegisterer {
typedef
Vector
bnuVector
;
EigenCastRegisterer_V
()
:
SignalCastRegisterer
(
typeid
(
bnuVector
),
dispVector
,
castVector
)
{}
:
SignalCastRegisterer
(
typeid
(
bnuVector
),
castVector
)
{}
static
boost
::
any
castVector
(
std
::
istringstream
&
iss
)
{
bnuVector
res
;
iss
>>
res
;
return
res
;
}
static
void
dispVector
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
)
{
const
bnuVector
&
v
=
boost
::
any_cast
<
bnuVector
>
(
object
);
os
<<
"[ "
;
for
(
int
i
=
0
;
i
<
v
.
size
();
++
i
)
os
<<
v
(
i
)
<<
" "
;
os
<<
" ];"
<<
std
::
endl
;
}
};
template
<
typename
Derived
>
...
...
@@ -57,18 +49,13 @@ struct EigenCastRegisterer_M : public dynamicgraph::SignalCastRegisterer {
typedef
Matrix
bnuMatrix
;
EigenCastRegisterer_M
()
:
SignalCastRegisterer
(
typeid
(
bnuMatrix
),
dispMatrix
,
castMatrix
)
{}
:
SignalCastRegisterer
(
typeid
(
bnuMatrix
),
castMatrix
)
{}
static
boost
::
any
castMatrix
(
std
::
istringstream
&
iss
)
{
bnuMatrix
res
;
iss
>>
res
;
return
res
;
}
static
void
dispMatrix
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
)
{
const
bnuMatrix
&
m
=
boost
::
any_cast
<
bnuMatrix
>
(
object
);
os
<<
m
<<
std
::
endl
;
}
};
EigenCastRegisterer_V
myVectorCast
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment