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
e3eeee49
Commit
e3eeee49
authored
Feb 25, 2020
by
Joseph Mirabel
Browse files
Make signal_disp templated
parent
9cba6ea9
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/dynamic-graph/signal-caster.h
View file @
e3eeee49
...
...
@@ -93,13 +93,26 @@ public:
}
};
/// Global signal cast template (helper) functions
///
/// Using these avoid using the typeid () operator and keeps the
/// implementation details hidden.
template
<
typename
T
>
void
signal_disp
(
const
T
&
value
,
std
::
ostream
&
os
)
{
SignalCaster
::
getInstance
()
->
disp
(
value
,
os
);
/// Template class used to serialize a signal value.
template
<
typename
T
>
struct
signal_disp
{
inline
static
void
run
(
const
T
&
value
,
std
::
ostream
&
os
)
{
os
<<
value
<<
'\n'
;
}
};
/// Template specialization of signal_disp for Eigen objects
template
<
typename
_Scalar
,
int
_Rows
,
int
_Cols
,
int
_Options
,
int
_MaxRows
,
int
_MaxCols
>
struct
signal_disp
<
Eigen
::
Matrix
<
_Scalar
,
_Rows
,
_Cols
,
_Options
,
_MaxRows
,
_MaxCols
>
>
{
inline
static
void
run
(
const
Eigen
::
Matrix
<
_Scalar
,
_Rows
,
_Cols
,
_Options
,
_MaxRows
,
_MaxCols
>
&
value
,
std
::
ostream
&
os
)
{
static
const
Eigen
::
IOFormat
row_format
(
Eigen
::
StreamPrecision
,
Eigen
::
DontAlignCols
,
" "
,
" "
,
""
,
""
,
""
,
""
);
os
<<
value
.
format
(
row_format
);
}
};
/// Template specialization of signal_disp for std::string.
/// Do not print '\n' at the end.
template
<
>
struct
signal_disp
<
std
::
string
>
{
inline
static
void
run
(
const
std
::
string
&
value
,
std
::
ostream
&
os
)
{
os
<<
value
;
}
};
template
<
typename
T
>
T
signal_cast
(
std
::
istringstream
&
iss
)
{
return
boost
::
any_cast
<
T
>
(
SignalCaster
::
getInstance
()
->
cast
(
typeid
(
T
),
iss
));
...
...
include/dynamic-graph/signal.t.cpp
View file @
e3eeee49
...
...
@@ -35,7 +35,7 @@ void Signal<T, Time>::set(std::istringstream &stringValue) {
template
<
class
T
,
class
Time
>
void
Signal
<
T
,
Time
>::
get
(
std
::
ostream
&
os
)
const
{
signal_disp
<
T
>
(
this
->
accessCopy
(),
os
);
signal_disp
<
T
>
::
run
(
this
->
accessCopy
(),
os
);
}
template
<
class
T
,
class
Time
>
...
...
tests/signal-cast-registerer.cpp
View file @
e3eeee49
...
...
@@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
output_test_stream
output
;
myVectorSignal
.
get
(
output
);
boost
::
format
fmt
(
"
[
%d %d %d %d %d
];
\n
"
);
boost
::
format
fmt
(
"%d %d %d %d %d"
);
fmt
%
(
i
==
0
)
%
(
i
==
1
)
%
(
i
==
2
)
%
(
i
==
3
)
%
(
i
==
4
);
BOOST_CHECK
(
output
.
is_equal
(
fmt
.
str
()));
...
...
tests/signal-ptr.cpp
View file @
e3eeee49
...
...
@@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(plug_signal_string) {
inSigVec
.
recompute
(
1
);
output_test_stream
output
;
inSigVec
.
get
(
output
);
BOOST_CHECK
(
output
.
is_equal
(
"1
\n
2
\n
3
\n
4
\n
5
\n
"
));
BOOST_CHECK
(
output
.
is_equal
(
"1
2 3 4 5
"
));
Signal
<
std
::
string
,
int
>
s
(
"signal"
);
std
::
ostringstream
os2
;
...
...
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