Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic-graph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guilhem Saurel
dynamic-graph
Commits
2612b806
Commit
2612b806
authored
14 years ago
by
Francois Bleibel
Browse files
Options
Downloads
Patches
Plain Diff
Made DefaultSignalCaster public (exported).
Added boost::ublas::vector example to test_signalcast.
parent
793da6bb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/dynamic-graph/signal-caster.h
+12
-1
12 additions, 1 deletion
include/dynamic-graph/signal-caster.h
src/signal/signal-caster.cpp
+0
-9
0 additions, 9 deletions
src/signal/signal-caster.cpp
unitTesting/test_signalcast.cpp
+33
-2
33 additions, 2 deletions
unitTesting/test_signalcast.cpp
with
45 additions
and
12 deletions
include/dynamic-graph/signal-caster.h
+
12
−
1
View file @
2612b806
...
@@ -66,7 +66,7 @@ private:
...
@@ -66,7 +66,7 @@ private:
/// The library-wide instance of SignalCaster
/// The library-wide instance of SignalCaster
extern
DYNAMICGRAPH_EXPORT
SignalCaster
g_caster
;
extern
DYNAMICGRAPH_EXPORT
SignalCaster
g_caster
;
/*
/*
!
* The SignalCast registerer class. Can be used to automatically register a cast when
* The SignalCast registerer class. Can be used to automatically register a cast when
* instanced somewhere in a cpp file. Pass the typeid() of the type you want to
* instanced somewhere in a cpp file. Pass the typeid() of the type you want to
* register a cast to as the first argument.
* register a cast to as the first argument.
...
@@ -80,6 +80,17 @@ public:
...
@@ -80,6 +80,17 @@ public:
}
}
};
};
/*! This class can be used to register default casts, i.e. casts already supported by
* the object to an std::iostream through the operators >> and << .
*/
template
<
typename
T
>
class
DefaultCastRegisterer
:
public
SignalCastRegisterer
{
public:
DefaultCastRegisterer
()
:
SignalCastRegisterer
(
typeid
(
T
),
disp
,
cast
,
trace
)
{}
static
boost
::
any
cast
(
std
::
istringstream
&
iss
)
{
T
inst
;
iss
>>
inst
;
return
inst
;
}
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
);
}
};
/*!
/*!
* Global signal cast template (helper) functions
* Global signal cast template (helper) functions
*
*
...
...
This diff is collapsed.
Click to expand it.
src/signal/signal-caster.cpp
+
0
−
9
View file @
2612b806
...
@@ -76,15 +76,6 @@ any SignalCaster::cast(const type_info& type, istringstream& iss) {
...
@@ -76,15 +76,6 @@ any SignalCaster::cast(const type_info& type, istringstream& iss) {
/// The global instance of the caster class.
/// The global instance of the caster class.
SignalCaster
g_caster
;
SignalCaster
g_caster
;
/// Default casts, such as casts already supported by std::iostream
template
<
typename
T
>
class
DefaultCastRegisterer
:
public
SignalCastRegisterer
{
public:
DefaultCastRegisterer
()
:
SignalCastRegisterer
(
typeid
(
T
),
disp
,
cast
,
trace
)
{}
static
boost
::
any
cast
(
istringstream
&
iss
)
{
T
inst
;
iss
>>
inst
;
return
inst
;
}
static
void
disp
(
const
any
&
object
,
ostream
&
os
)
{
os
<<
any_cast
<
T
>
(
object
)
<<
endl
;;
}
static
void
trace
(
const
any
&
object
,
ostream
&
os
)
{
disp
(
object
,
os
);
}
};
/// Registers useful casts
/// Registers useful casts
namespace
{
namespace
{
DefaultCastRegisterer
<
double
>
double_reg
;
DefaultCastRegisterer
<
double
>
double_reg
;
...
...
This diff is collapsed.
Click to expand it.
unitTesting/test_signalcast.cpp
+
33
−
2
View file @
2612b806
...
@@ -25,19 +25,34 @@
...
@@ -25,19 +25,34 @@
#include
<string>
#include
<string>
#include
<iostream>
#include
<iostream>
#include
<cstdlib>
#include
<cstdlib>
#include
<memory>
#include
<dynamic-graph/factory.h>
#include
<dynamic-graph/factory.h>
#include
<dynamic-graph/entity.h>
#include
<dynamic-graph/entity.h>
#include
<dynamic-graph/debug.h>
#include
<dynamic-graph/debug.h>
#include
<dynamic-graph/pool.h>
#include
<dynamic-graph/pool.h>
#include
<dynamic-graph/signal.h>
#include
<dynamic-graph/signal.h>
// only included because we will define new casts here. Not needed in general.
#include
<
memory
>
#include
<
dynamic-graph/signal-caster.h
>
using
namespace
std
;
using
namespace
std
;
using
namespace
dynamicgraph
;
using
namespace
dynamicgraph
;
// define a new cast with a ublas vector
#include
<boost/numeric/ublas/vector.hpp>
// this header is *needed* to define iostream& operators << and >> for a ublas vector
#include
<boost/numeric/ublas/io.hpp>
typedef
boost
::
numeric
::
ublas
::
vector
<
double
>
Vector
;
// define a new cast with a type that supports streaming operators to and from it
// (this could be automated with macros)
namespace
{
DefaultCastRegisterer
<
bool
>
myBooleanCast
;
DefaultCastRegisterer
<
Vector
>
myVectorCast
;
}
int
main
()
{
int
main
()
{
using
namespace
boost
::
numeric
::
ublas
;
Signal
<
double
,
int
>
mySignal
(
"out"
);
Signal
<
double
,
int
>
mySignal
(
"out"
);
istringstream
value
(
"42.0"
);
istringstream
value
(
"42.0"
);
cout
<<
"[cast] Setting signal value to "
<<
value
.
str
()
<<
endl
;
cout
<<
"[cast] Setting signal value to "
<<
value
.
str
()
<<
endl
;
...
@@ -47,5 +62,21 @@ int main() {
...
@@ -47,5 +62,21 @@ int main() {
cout
<<
"[trace] Printing out trace: "
;
cout
<<
"[trace] Printing out trace: "
;
mySignal
.
trace
(
cout
);
mySignal
.
trace
(
cout
);
Signal
<
Vector
,
int
>
myVectorSignal
(
"vector"
);
// print out signal name
cout
<<
" "
<<
myVectorSignal
<<
endl
;
cout
<<
"[disp] Enumerating boost unit vectors"
<<
endl
;
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
unit_vector
<
double
>
v
(
5
,
i
);
myVectorSignal
.
setConstant
(
v
);
// print out signal value
cout
<<
" "
;
myVectorSignal
.
get
(
cout
);
cout
<<
endl
;
}
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment