Skip to content
GitLab
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
9cba6ea9
Commit
9cba6ea9
authored
Feb 25, 2020
by
Joseph Mirabel
Browse files
Remove method trace from DefaultCastRegisterer
parent
0131dbda
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/dynamic-graph/signal-cast-helper.h
View file @
9cba6ea9
...
...
@@ -33,17 +33,13 @@ template <typename T>
class
DefaultCastRegisterer
:
public
SignalCastRegisterer
{
public:
DefaultCastRegisterer
()
:
SignalCastRegisterer
(
typeid
(
T
),
disp
,
cast
,
trace
)
{}
:
SignalCastRegisterer
(
typeid
(
T
),
disp
,
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
;
}
static
void
trace
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
)
{
disp
(
object
,
os
);
}
};
/// A default version of the caster, to serialize directly from
...
...
@@ -81,7 +77,6 @@ template <class T> class SignalCast {
public:
static
T
cast
(
std
::
istringstream
&
)
{
throw
1
;
}
static
void
disp
(
const
T
&
,
std
::
ostream
&
)
{
throw
1
;
}
static
void
trace
(
const
T
&
t
,
std
::
ostream
&
os
)
{
disp
(
t
,
os
);
}
public:
// adapter functions for SignalCast
...
...
@@ -91,9 +86,6 @@ public:
static
void
disp_
(
const
boost
::
any
&
t
,
std
::
ostream
&
os
)
{
disp
(
boost
::
any_cast
<
T
>
(
t
),
os
);
}
static
void
trace_
(
const
boost
::
any
&
t
,
std
::
ostream
&
os
)
{
trace
(
boost
::
any_cast
<
T
>
(
t
),
os
);
}
private:
SignalCast
()
{}
...
...
include/dynamic-graph/signal-caster.h
View file @
9cba6ea9
...
...
@@ -42,20 +42,16 @@ public:
typedef
boost
::
function2
<
void
,
const
boost
::
any
&
,
std
::
ostream
&>
displayer_type
;
typedef
boost
::
function1
<
boost
::
any
,
std
::
istringstream
&>
caster_type
;
typedef
boost
::
function2
<
void
,
const
boost
::
any
&
,
std
::
ostream
&>
tracer_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
);
/// Traces an object using a registered trace function.
void
trace
(
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
,
caster_type
caster
,
tracer_type
tracer
);
caster_type
caster
);
/// Unregister a cast.
void
unregisterCast
(
const
std
::
type_info
&
type
);
/// Checks if there is a displayer registered with type_name.
...
...
@@ -65,7 +61,7 @@ public:
private:
/// Container for the three cast functions.
typedef
boost
::
tuple
<
displayer_type
,
caster_type
,
tracer_type
>
typedef
boost
::
tuple
<
displayer_type
,
caster_type
>
cast_functions_type
;
/// \brief Retrieve cast structure from its name.
...
...
@@ -92,9 +88,8 @@ class DYNAMIC_GRAPH_DLLAPI SignalCastRegisterer {
public:
inline
SignalCastRegisterer
(
const
std
::
type_info
&
type
,
SignalCaster
::
displayer_type
displayer
,
SignalCaster
::
caster_type
caster
,
SignalCaster
::
tracer_type
tracer
)
{
SignalCaster
::
getInstance
()
->
registerCast
(
type
,
displayer
,
caster
,
tracer
);
SignalCaster
::
caster_type
caster
)
{
SignalCaster
::
getInstance
()
->
registerCast
(
type
,
displayer
,
caster
);
}
};
...
...
src/signal/signal-caster.cpp
View file @
9cba6ea9
...
...
@@ -28,8 +28,7 @@ void SignalCaster::destroy() {
void
SignalCaster
::
registerCast
(
const
std
::
type_info
&
type
,
SignalCaster
::
displayer_type
displayer
,
SignalCaster
::
caster_type
caster
,
SignalCaster
::
tracer_type
tracer
)
{
SignalCaster
::
caster_type
caster
)
{
if
(
existsCast
(
type
))
{
// If type name has already been registered for same type, do not throw.
if
(
type_info_
[
type
.
name
()]
!=
&
type
)
{
...
...
@@ -45,7 +44,7 @@ void SignalCaster::registerCast(const std::type_info &type,
throw
ExceptionSignal
(
ExceptionSignal
::
GENERIC
,
os
.
str
());
}
}
functions_
[
type
.
name
()]
=
cast_functions_type
(
displayer
,
caster
,
tracer
);
functions_
[
type
.
name
()]
=
cast_functions_type
(
displayer
,
caster
);
type_info_
[
type
.
name
()]
=
&
type
;
}
...
...
@@ -75,10 +74,6 @@ void SignalCaster::disp(const boost::any &object, std::ostream &os) {
getCast
(
object
.
type
().
name
()).
get
<
0
>
()(
object
,
os
);
}
void
SignalCaster
::
trace
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
)
{
getCast
(
object
.
type
().
name
()).
get
<
2
>
()(
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
=
...
...
tests/signal-cast-registerer.cpp
View file @
9cba6ea9
...
...
@@ -35,8 +35,7 @@ struct EigenCastRegisterer_V : public dynamicgraph::SignalCastRegisterer {
typedef
Vector
bnuVector
;
EigenCastRegisterer_V
()
:
SignalCastRegisterer
(
typeid
(
bnuVector
),
dispVector
,
castVector
,
traceVector
)
{}
:
SignalCastRegisterer
(
typeid
(
bnuVector
),
dispVector
,
castVector
)
{}
static
boost
::
any
castVector
(
std
::
istringstream
&
iss
)
{
bnuVector
res
;
...
...
@@ -51,13 +50,6 @@ struct EigenCastRegisterer_V : public dynamicgraph::SignalCastRegisterer {
os
<<
v
(
i
)
<<
" "
;
os
<<
" ];"
<<
std
::
endl
;
}
static
void
traceVector
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
)
{
const
bnuVector
&
v
=
boost
::
any_cast
<
bnuVector
>
(
object
);
for
(
int
i
=
0
;
i
<
v
.
size
();
++
i
)
os
<<
v
(
i
)
<<
" "
;
os
<<
std
::
endl
;
}
};
template
<
typename
Derived
>
...
...
@@ -65,8 +57,7 @@ struct EigenCastRegisterer_M : public dynamicgraph::SignalCastRegisterer {
typedef
Matrix
bnuMatrix
;
EigenCastRegisterer_M
()
:
SignalCastRegisterer
(
typeid
(
bnuMatrix
),
dispMatrix
,
castMatrix
,
traceMatrix
)
{}
:
SignalCastRegisterer
(
typeid
(
bnuMatrix
),
dispMatrix
,
castMatrix
)
{}
static
boost
::
any
castMatrix
(
std
::
istringstream
&
iss
)
{
bnuMatrix
res
;
...
...
@@ -78,11 +69,6 @@ struct EigenCastRegisterer_M : public dynamicgraph::SignalCastRegisterer {
const
bnuMatrix
&
m
=
boost
::
any_cast
<
bnuMatrix
>
(
object
);
os
<<
m
<<
std
::
endl
;
}
static
void
traceMatrix
(
const
boost
::
any
&
object
,
std
::
ostream
&
os
)
{
const
bnuMatrix
&
m
=
boost
::
any_cast
<
bnuMatrix
>
(
object
);
os
<<
m
<<
std
::
endl
;
}
};
EigenCastRegisterer_V
myVectorCast
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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