Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cberge/dynamic-graph
  • ostasse/dynamic-graph
  • gsaurel/dynamic-graph
  • stack-of-tasks/dynamic-graph
4 results
Show changes
/* Copyright 2019, LAAS-CNRS
*
* Olivier Stasse
*
*/
#include <unistd.h>
#include <dynamic-graph/process-list.hh>
#include <fstream>
#include <iostream>
#include <sstream>
#define BOOST_TEST_MODULE debug - trace
#if BOOST_VERSION >= 105900
#include <boost/test/tools/output_test_stream.hpp>
#else
#include <boost/test/output_test_stream.hpp>
#endif
#include <boost/test/unit_test.hpp>
using boost::test_tools::output_test_stream;
BOOST_AUTO_TEST_CASE(testMt) {
dynamicgraph::CPU::System aSystem;
// create and open a character archive for output
std::ofstream ofs("cpu_state.dat");
boost::archive::text_oarchive oa(ofs);
oa << aSystem;
for (unsigned int i = 0; i < 10; i++) {
usleep(100000);
aSystem.readProcStat();
}
}
// Copyright 2011 Florent Lamiraux, Thomas Moulard.
//
#include "dynamic-graph/value.h"
#include <dynamic-graph/exception-factory.h>
#include <iostream>
#define BOOST_TEST_MODULE value
#include <boost/version.hpp>
#if BOOST_VERSION >= 105900
#include <boost/test/tools/output_test_stream.hpp>
#else
#include <boost/test/output_test_stream.hpp>
#endif
#include <boost/test/unit_test.hpp>
using boost::test_tools::output_test_stream;
namespace dg = dynamicgraph;
BOOST_AUTO_TEST_CASE(value_none) {
using dg::command::Value;
Value value1;
Value value(value1);
// Similar to NaN != NaN
BOOST_CHECK(!(value1 == value));
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=unknown, value="));
}
}
BOOST_AUTO_TEST_CASE(value_bool) {
using dg::command::Value;
bool abool1(false);
Value value1(abool1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=bool, value=0"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=bool, value=0"));
}
}
BOOST_AUTO_TEST_CASE(value_exceptions) {
using dg::command::Value;
Value value1;
dg::command::EitherType anet(value1);
output_test_stream output, output2;
// Check if the exception is working when calling intValue
// while we are having a none.
bool res = false;
try {
int aInt(anet);
aInt++; // silence unused variable warnings to have a stable release in the
// ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
output << aea.getExceptionName();
output2 << aea.what();
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
BOOST_CHECK(output.is_equal("Abstract"));
BOOST_CHECK(output2.is_equal("value is not an int"));
// Check if the exception is working when calling boolValue
// while we are having a none.
res = false;
try {
bool abool(anet);
abool = !abool; // silence unused variable warnings to have a stable
// release in the ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling unsignedintValue
// while we are having a none.
res = false;
try {
unsigned int aint(anet);
aint++; // silence unused variable warnings to have a stable release in the
// ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling doubleValue
// while we are having a none.
res = false;
try {
double adouble(anet);
adouble++; // silence unused variable warnings to have a stable release in
// the ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling floatValue
// while we are having a none.
res = false;
try {
float afloat(anet);
afloat++; // silence unused variable warnings to have a stable release in
// the ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling stringValue
// while we are having a none.
res = false;
try {
std::string astring(anet);
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling vectorValue
// while we are having a none.
res = false;
try {
dg::Vector avector;
avector = anet;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling matrixXdValue
// while we are having a none.
res = false;
try {
Eigen::MatrixXd amatrixXd;
amatrixXd = anet;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling matrix4dValue
// while we are having a none.
res = false;
try {
Eigen::Matrix4d amatrix4d;
amatrix4d = anet;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
}
BOOST_AUTO_TEST_CASE(value_unsigned_int) {
using dg::command::Value;
unsigned int aint1(5);
Value value1(aint1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=unsigned int, value=5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=unsigned int, value=5"));
}
}
BOOST_AUTO_TEST_CASE(value_int) {
using dg::command::Value;
int aint1(5);
Value value1(aint1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=int, value=5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=int, value=5"));
}
}
BOOST_AUTO_TEST_CASE(value_float) {
using dg::command::Value;
float afloat1(0.5);
Value value1(afloat1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=float, value=0.5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=float, value=0.5"));
}
}
BOOST_AUTO_TEST_CASE(value_double) {
using dg::command::Value;
double adouble1(0.5);
Value value1(adouble1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=double, value=0.5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=double, value=0.5"));
}
}
BOOST_AUTO_TEST_CASE(value_vector) {
using dg::command::Value;
dg::Vector avector1;
avector1.resize(2);
avector1[0] = 0.5;
avector1[1] = 1.5;
Value value1(avector1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=vector, value=0.5\n1.5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=vector, value=0.5\n1.5"));
}
}
BOOST_AUTO_TEST_CASE(value_string) {
using dg::command::Value;
std::string str1("value #1");
Value value1(str1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=string, value=value #1"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=string, value=value #1"));
}
std::string str2("value #2");
Value value2(str2);
value = value2;
{
output_test_stream output;
output << value2;
BOOST_CHECK(output.is_equal("Type=string, value=value #2"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=string, value=value #2"));
}
}
BOOST_AUTO_TEST_CASE(value_matrixXd) {
using dg::command::Value;
Eigen::MatrixXd avector1;
avector1.resize(2, 2);
avector1(0, 0) = 0.5;
avector1(0, 1) = 1.5;
avector1(1, 0) = 2.5;
avector1(1, 1) = 3.5;
Value value1(avector1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=matrixXd, value=0.5 1.5\n2.5 3.5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=matrixXd, value=0.5 1.5\n2.5 3.5"));
}
}
BOOST_AUTO_TEST_CASE(value_matrix4d) {
using dg::command::Value;
Eigen::Matrix4d avector1;
avector1.setZero();
avector1(0, 0) = 0.5;
avector1(0, 1) = 1.5;
avector1(1, 0) = 2.5;
avector1(1, 1) = 3.5;
Value value1(avector1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(
output.is_equal("Type=matrix4d, value=0.5 1.5 0 0\n"
"2.5 3.5 0 0\n 0 0 0 0\n"
" 0 0 0 0"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(
output.is_equal("Type=matrix4d, value=0.5 1.5 0 0\n"
"2.5 3.5 0 0\n 0 0 0 0\n"
" 0 0 0 0"));
}
}
BOOST_AUTO_TEST_CASE(value_values) {
using namespace dynamicgraph::command;
std::string s1("value #1");
double d1 = 0.3;
Value vs1(s1);
Value vd1(d1);
Values values;
values.push_back(vs1);
values.push_back(vd1);
Value vvalues(values);
BOOST_CHECK_EQUAL(vvalues.type(), Value::VALUES);
{ // Const ref
const Values &vs = vvalues.constValuesValue();
BOOST_CHECK_EQUAL(vs.size(), values.size());
BOOST_CHECK(vs == values);
}
{
// Cast does not work.
// dg::command::EitherType eitherType (vvalues);
// Values vs = static_cast<Values>(eitherType);
// BOOST_CHECK_EQUAL(vs.size(), values.size());
// BOOST_CHECK(vs == values);
} { // Constructor
Value vvs(vvalues);
BOOST_CHECK(vvs == vvalues);
}
{
output_test_stream output;
output << vvalues;
BOOST_CHECK(
output.is_equal("Type=values, value=[ "
"Value(Type=string, value=value #1), "
"Value(Type=double, value=0.3), "
"]"));
}
}
#
# Copyright
#
### tools
SET(tools
test_shell
)
### Configure shell launch script
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/shell.sh.cmake
${${PROJECT_NAME}_BINARY_DIR}/tools/shell.sh)
INSTALL(
FILES
${${PROJECT_NAME}_BINARY_DIR}/tools/shell.sh
DESTINATION
bin/${PROJECT_NAME}
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ )
FOREACH(tool_name ${tools})
SET(EXECUTABLE_NAME ${tool_name})
ADD_DEFINITIONS(-DDEBUG=2)
ADD_EXECUTABLE(${EXECUTABLE_NAME}
${tool_name}.cpp)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../include
)
LINK_DIRECTORIES(${${PROJECT_NAME}_BINARY_DIR}/lib)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
${PROJECT_NAME})
IF(UNIX)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} dl)
ENDIF(UNIX)
INSTALL(TARGETS ${tool_name}
DESTINATION bin/${PROJECT_NAME})
ENDFOREACH(tool_name)
\ No newline at end of file
echo "-- Launching dynamic-graph C shell with default plugins"
echo "loadPlugin ${CMAKE_INSTALL_PREFIX}/lib/plugin/shell-functions.so" > ./default_script
echo "loadPlugin ${CMAKE_INSTALL_PREFIX}/lib/plugin/shell-procedure.so" >> ./default_script
${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME}/test_shell default_script
\ No newline at end of file
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-JAPAN, Tsukuba, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: test_shell.cc
* Project: DYNAMIC-GRAPH
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include <dynamic-graph/entity.h>
#include <dynamic-graph/plugin-loader.h>
#include <dynamic-graph/interpreter.h>
#include <dynamic-graph/debug.h>
#include <sstream>
using namespace std;
using namespace dynamicgraph;
extern std::ofstream debugfile;
int main( int argc,char** argv )
{
dgDEBUGIN(15);
dgDEBUG(5) << " Loading..." << endl;
PluginLoader pl;
g_shell.referencePluginLoader( &pl );
int fileIdx;
try
{
for( fileIdx=1;fileIdx<argc;++fileIdx )
{
std::istringstream script( argv[fileIdx] );
cout << "Run "<< argv[fileIdx] << endl;
g_shell.cmd( "run",script,cout );
}
}
catch( exception& e )
{
cout << "!! In file <" << argv[fileIdx] << "> : " << e.what() <<endl;
}
catch ( const char* str ) {
cout << "!! In file <" << argv[fileIdx] << "> : "
<< "Unknown exception " << str << endl;
}
catch( ... ){ dgDEBUG(5) << "!! Unknown! " <<endl ; }
while(1)
{
try
{
dgDEBUG(5) << "Run shell." << endl;
g_shell.shell(cin,cout);
dgDEBUG(5) << "Shell over." << endl;
if( cin.eof() ) break;
}
catch( exception& e )
{
cout << "!! " << e.what() <<endl;
}
catch( ... ){ dgDEBUG(5) << "!! Unknown! " <<endl ; }
}
dgDEBUGOUT(15);
return 0;
}
#
# Copyright
#
### tests
SET(tests_exe
test_pool
test_depend
test_signalcast)
SET(tests_libs
test_signalcast_libA
test_signalcast_libB
)
SET(test_signalcast_additional_libs ${test_libs})
ADD_DEFINITIONS(-DDEBUG=2)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../include
)
LINK_DIRECTORIES(${${PROJECT_NAME}_BINARY_DIR}/lib)
# Additional tests
FOREACH(test_name ${tests_libs})
SET(LIBRARY_NAME ${test_name})
ADD_LIBRARY(${LIBRARY_NAME}
SHARED
${test_name}.cpp)
TARGET_LINK_LIBRARIES(${LIBRARY_NAME}
${PROJECT_NAME})
ENDFOREACH(test_name)
FOREACH(test_name ${tests_exe})
SET(EXECUTABLE_NAME ${test_name})
ADD_EXECUTABLE(${EXECUTABLE_NAME}
${test_name}.cpp)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
${PROJECT_NAME})
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
${${test_name}_additional_libs})
ADD_TEST(NAME ${test_name} COMMAND ${test_name})
ENDFOREACH(test_name)
\ No newline at end of file
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet VISTA / IRISA, 2003
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: test_categorie.cc
* Project: Traces
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id: test_boost.cpp,v 1.1.1.1 2006-07-03 05:17:37 nmansard Exp $
*
* Description
* ============
*
* Test la classe CategorieTrace.
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
// #include <dynamic-graph/all-signals.h>
#include <dynamic-graph/signal.h>
#include <dynamic-graph/signal-time-dependent.h>
//#include <sot/TimeDependency.h>
#include <dynamic-graph/debug.h>
#include <iostream>
#include <string>
using namespace std;
using namespace dynamicgraph;
template< class Res=double >
class DummyClass
{
public:
std::string proname;
list< SignalTimeDependent<double,int>* > inputsig;
list< SignalTimeDependent<string,int>* > inputsigV;
public:
DummyClass( const std::string& n ) : proname(n),res(),appel(0),timedata(0) {}
Res& fun( Res& res,int t)
{
appel++; timedata=t;
cout << "Inside " << proname << " -> " << this
<< endl;
for( list< SignalTimeDependent<double,int>* >::iterator it=inputsig.begin();
it!=inputsig.end();++it )
{
cout << *(*it) << endl;
(*it)->access(timedata);
}
for( list< SignalTimeDependent<string,int>* >::iterator it=inputsigV.begin();
it!=inputsigV.end();++it )
{ cout << *(*it) << endl; (*it)->access(timedata);}
return res=(*this)();
}
void add( SignalTimeDependent<double,int>& sig )
{ inputsig.push_back(&sig); }
void add( SignalTimeDependent<string,int>& sig )
{ inputsigV.push_back(&sig); }
Res operator() ( void );
Res res;
int appel;
int timedata;
};
template< class Res >
Res DummyClass<Res>::operator() (void)
{ return this->res; }
template<>
double DummyClass<double>::operator() (void)
{
res=appel*timedata; return res;
}
template<>
string DummyClass<string>::operator() (void)
{
ostringstream oss;
oss << appel*timedata;
return oss.str();
}
int main( void )
{
DummyClass<double> pro1("pro1"),pro3("pro3"),pro5("pro5");
DummyClass<string> pro2("pro2"),pro4("pro4"),pro6("pro6");
SignalTimeDependent<double,int> sig5("Sig5");
SignalTimeDependent<string,int> sig6("Sig6");
SignalTimeDependent<string,int> sig4(sig5,"Sig4");
SignalTimeDependent<string,int> sig2(sig4<<sig4<<sig4<<sig6,"Sig2");
SignalTimeDependent<double,int> sig3(sig2<<sig5<<sig6,"Sig3");
SignalTimeDependent<double,int> sig1( boost::bind(&DummyClass<double>::fun,&pro1,_1,_2),
sig2<<sig3,"Sig1");
// cout << "--- Test Array ------ "<<endl;
// SignalArray<int> tarr(12);
// tarr<<sig3<<sig2;//+sig2+sig3;
// dispArray(sig4<<sig2<<sig3);
// dispArray(tarr);
sig2.setFunction( boost::bind(&DummyClass<string>::fun,&pro2,_1,_2) );
sig3.setFunction( boost::bind(&DummyClass<double>::fun,&pro3,_1,_2) );
sig4.setFunction( boost::bind(&DummyClass<string>::fun,&pro4,_1,_2) );
sig5.setFunction( boost::bind(&DummyClass<double>::fun,&pro5,_1,_2) );
sig6.setFunction( boost::bind(&DummyClass<string>::fun,&pro6,_1,_2) );
pro1.add(sig2);
pro1.add(sig3);
pro2.add(sig4);
pro2.add(sig4);
pro2.add(sig4);
pro3.add(sig2);
pro4.add(sig5);
pro2.add(sig6);
pro3.add(sig5);
pro3.add(sig6);
sig5.setDependencyType(TimeDependency<int>::ALWAYS_READY);
sig6.setDependencyType(TimeDependency<int>::BOOL_DEPENDENT);
sig6.setReady();
sig1.displayDependencies(cout)<<endl;
cout << "Needs update?" << endl
<< sig1.needUpdate(2) << endl;
dgDEBUG(1) << "Access sig1(2) "<<endl;
sig1.access(2);
sig1.displayDependencies(cout) << endl;
dgDEBUG(1) << "Access sig2(4) "<<endl;
sig2.access(4);
sig1.displayDependencies(cout)<<endl;
dgDEBUG(1) << "Access sig1(4) "<<endl;
sig1.access(4);
sig1.displayDependencies(cout)<<endl;
sig1.needUpdate(6);
sig1.needUpdate(6);
return 0;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-JAPAN, Tsukuba, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: test_entity.cc
* Project: dynamicGraph
* Author: François Bleibel
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include <string>
#include <iostream>
#include <cstdlib>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/debug.h>
#include <dynamic-graph/pool.h>
#include <memory>
using namespace std;
using namespace dynamicgraph;
class MyEntity
: public Entity
{
public:
MyEntity(const std::string& name);
public: /* --- ENTITY INHERITANCE --- */
static const std::string CLASS_NAME;
virtual void display( std::ostream& os ) const;
virtual const std::string& getClassName( void ) const { return CLASS_NAME; }
protected:
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MyEntity,"MyEntity");
MyEntity::MyEntity(const std::string& name)
: Entity(name){
}
void MyEntity::display(std::ostream& os ) const {
os << "Hello! My name is " << getName() << " !" << endl;
}
int main() {
MyEntity myEntity("MyEntity");
cout << "-- Pool.list" << endl;
g_pool.commandLine("pool", "list", *auto_ptr<istringstream>(new istringstream("")), cout);
Entity& e = g_pool.getEntity("MyEntity");
cout << "-- Display" << endl;
e.display(cout);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-JAPAN, Tsukuba, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: test_entity.cc
* Project: dynamicGraph
* Author: François Bleibel
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include <string>
#include <iostream>
#include <cstdlib>
#include <memory>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/debug.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/signal.h>
// only included because we will define new casts here. Not needed in general.
#include <dynamic-graph/signal-caster.h>
#include "test_signalcast_libA.h"
#include "test_signalcast_libB.h"
using namespace std;
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;
}
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
class BoostNumericsCastRegisterer
: public SignalCastRegisterer
{
typedef boost::numeric::ublas::vector<double> bnuVector;
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( unsigned int i=0;i<v.size();++i ) 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( unsigned int i=0;i<v.size();++i ) os << v(i) << " ";
os << std::endl;
}
public:
BoostNumericsCastRegisterer(void)
: SignalCastRegisterer(typeid(bnuVector),dispVector,castVector,traceVector) {}
};
BoostNumericsCastRegisterer myVectorCast;
int main() {
using namespace boost::numeric::ublas;
Signal<double, int> mySignal("out");
istringstream value("42.0");
cout << "[cast] Setting signal value to " << value.str() << endl;
mySignal.set(value); // use "set" operation
cout << "[disp] The value read is ";
mySignal.get(cout);
cout << "[trace] Printing out trace: ";
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);
std::ostringstream os;
os << v;
std::istringstream ss(os.str());
myVectorSignal.set(ss);
// print out signal value
try{myVectorSignal.get(cout);}
catch( const ExceptionAbstract & exp ) { cout << exp << std::endl; }
cout << endl;
}
// check the following: "typeid of vA is different from typeid of vB
// in different shared libraries""
cout << "-- check typeid equality in shared libs" << endl;
if(typeid(vA) == typeid(vB)) {
cout << "The types of vA (libA.so) and vB (libB.so) are equal" << endl;
} else {
cout << "The types of vA (libA.so) and vB (libB.so) are different" << endl;
}
cout << "-- check type *name* equality in shared libs with type:" << endl
<< " " << typeid(vA).name() << endl;
if( !strcmp(typeid(vA).name(), typeid(vB).name()) ) {
cout << "The type names of vA (libA.so) and vB (libB.so) are equal" << endl;
} else {
cout << "The type names of vA (libA.so) and vB (libB.so) are different" << endl;
}
return 0;
}
#include <string>
#include <iostream>
#include <cstdlib>
#include <memory>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/debug.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/signal.h>
#include <dynamic-graph/signal-caster.h>
#include "test_signalcast_libA.h"
using namespace dynamicgraph;
using namespace std;
vec_type vA;
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
typedef boost::numeric::ublas::vector<double> vec_type;
extern vec_type vA;
#include <string>
#include <iostream>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/debug.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/signal.h>
#include <dynamic-graph/signal-caster.h>
#include "test_signalcast_libB.h"
using namespace dynamicgraph;
using namespace std;
vec_type vB;
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
typedef boost::numeric::ublas::vector<double> vec_type;
extern vec_type vB;