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
Showing with 1302 additions and 734 deletions
// Copyright 2010 Thomas Moulard.
//
#include <dynamic-graph/debug.h>
#include <dynamic-graph/eigen-io.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/linear-algebra.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/signal.h>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <string>
#include "signal-cast-register-test.h"
#include "signal-cast-registerer-libA.hh"
#include "signal-cast-registerer-libB.hh"
#define BOOST_TEST_MODULE signal_cast_registerer
#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>
#include <iostream>
using boost::test_tools::output_test_stream;
typedef Eigen::VectorXd Vector;
typedef Eigen::MatrixXd Matrix;
// Check standard double cast registerer.
BOOST_AUTO_TEST_CASE(standard_double_registerer) {
dynamicgraph::Signal<double, int> mySignal("out");
typedef std::pair<std::string, std::string> test_t;
std::vector<test_t> values;
values.push_back(std::make_pair("42.0", "42"));
values.push_back(std::make_pair("42.5", "42.5"));
values.push_back(std::make_pair("-12.", "-12"));
// Double special values.
// FIXME: these tests are failing :(
values.push_back(std::make_pair("inf", "inf"));
values.push_back(std::make_pair("-inf", "-inf"));
values.push_back(std::make_pair("nan", "nan"));
BOOST_FOREACH (const test_t &test, values) {
// Set
std::istringstream value(test.first);
mySignal.set(value);
// Get
{
output_test_stream output;
mySignal.get(output);
BOOST_CHECK_EQUAL(output.str(), test.second);
}
// Trace
{
output_test_stream output;
mySignal.trace(output);
BOOST_CHECK_EQUAL(output.str(), test.second);
}
}
// Check invalid values.
// FIXME: this test is failing for now.
std::istringstream value("This is not a valid double.");
BOOST_CHECK_THROW(mySignal.set(value), std::exception);
}
// Check a custom cast registerer for Boost uBLAS vectors.
BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
dynamicgraph::Signal<dynamicgraph::Vector, int> myVectorSignal("vector");
// Print the signal name.
{
output_test_stream output;
output << myVectorSignal;
BOOST_CHECK(output.is_equal("Sig:vector (Type Cst)"));
}
for (unsigned int i = 0; i < 5; ++i) {
Vector v = Vector::Unit(5, i);
std::ostringstream os;
os << v;
std::istringstream ss("[5](" + os.str() + ")");
// Set signal value.
myVectorSignal.set(ss);
// Print out signal value.
output_test_stream output;
myVectorSignal.get(output);
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()));
}
// Catch Exception of ss (not good input)
// ss[0] != "["
try {
std::istringstream ss("test");
myVectorSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[0] != \"[\"";
}
// ss[1] != %i
try {
std::istringstream ss("[test");
myVectorSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[1] != %i";
}
// ss[2] != "]"
try {
std::istringstream ss("[5[");
myVectorSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[2] != \"]\"";
}
// ss[3] != "("
try {
std::istringstream ss("[5]test");
myVectorSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[3] != \"(\"";
}
// ss[4] != ' ' || ','
try {
std::istringstream ss("[5](1, ");
myVectorSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[4] != \" \" || \",\"";
}
// ss[-1] != ")"
try {
std::istringstream ss("[5](1,2,3,4,5]");
myVectorSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[-1] != \")\"";
}
try {
output_test_stream output;
myVectorSignal.trace(output);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[-1] != \")\"";
}
}
BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
dynamicgraph::Signal<dynamicgraph::Matrix, int> myMatrixSignal("matrix");
// Print the signal name.
{
output_test_stream output;
output << myMatrixSignal;
BOOST_CHECK(output.is_equal("Sig:matrix (Type Cst)"));
}
// Catch Exception of ss (not good input)
// ss[0] != "["
try {
std::istringstream ss("test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[0] != \"[\"";
}
// ss[1] != %i
try {
std::istringstream ss("[test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[1] != %i";
}
// ss[2] != ","
try {
std::istringstream ss("[5[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[2] != \",\"";
}
// ss[3] != %i
try {
std::istringstream ss("[5,c");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[3] != %i";
}
// ss[4] != "]"
try {
std::istringstream ss("[5,3[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[4] != \"]\"";
}
// ss[5] != "("
try {
std::istringstream ss("[5,3]test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \"(\"";
}
// ss[6] != "("
try {
std::istringstream ss("[5,3](test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[6] != \"(\"";
}
// ss[8] != " " || ","
try {
std::istringstream ss("[5,3]((1,");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[8] != \" \" || \",\"";
}
// ss[6+n] != ")"
try {
std::istringstream ss("[5,3]((1,2,3]");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << ("ss[6+n] != \")\"");
}
// ss[-3] != ")"
try {
std::istringstream ss("[5,1]((1)(2)(3[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \")\"";
}
// ss[-3] != ")"
try {
std::istringstream ss("[5,1]((1)(2)(3)[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \")\"";
}
// ss[-1]!= ")"
try {
std::istringstream ss("[3,1]((1)(2),(3)[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \")\" and ignore \",\"";
}
//[...]((...))
}
// Copyright 2010 Thomas Moulard.
//
#include <dynamic-graph/debug.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/signal.h>
#include <boost/foreach.hpp>
#include <iostream>
#include <string>
#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>
#include <boost/test/unit_test_suite.hpp>
#include <string>
using boost::test_tools::output_test_stream;
typedef dynamicgraph::SignalTimeDependent<double, int> sigDouble_t;
typedef dynamicgraph::SignalTimeDependent<std::string, int> sigString_t;
using namespace dynamicgraph;
using std::cout;
template <class T>
class DummyClass {
public:
std::string proname;
std::list<sigDouble_t *> inputsig;
std::list<sigString_t *> inputsigV;
explicit DummyClass(const std::string &n)
: proname(n), res(), call(), timedata() {}
T &fun(T &res, int t) {
++call;
timedata = t;
BOOST_FOREACH (sigDouble_t *ptr, inputsig) ptr->access(timedata);
BOOST_FOREACH (sigString_t *ptr, inputsigV) ptr->access(timedata);
res = (*this)();
return res;
}
void add(sigDouble_t &sig) { inputsig.push_back(&sig); }
void add(sigString_t &sig) { inputsigV.push_back(&sig); }
T operator()();
T res;
int call;
int timedata;
};
template <>
double DummyClass<double>::operator()() {
res = call * timedata;
return res;
}
template <>
std::string DummyClass<std::string>::operator()() {
std::ostringstream oss;
oss << call * timedata;
return oss.str();
}
template <class T>
T DummyClass<T>::operator()() {
return this->res;
}
BOOST_AUTO_TEST_CASE(normal_cst_test) {
SignalPtr<double, int> sigNotPlug(NULL, "sigNotPlug");
const SignalPtr<double, int> cstSigNotPlug(NULL, "sigNotPlug");
try {
sigNotPlug.getPtr();
} catch (ExceptionSignal &e) {
cout << "Error catch" << std::endl;
}
// Test getPtr without plug
/// This create a ExceptionSignal::NOT_INITIALIZED
bool res = false;
try {
// Signal<double, int> * r =
sigNotPlug.getPtr();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
}
BOOST_CHECK(res);
/// Testing const getPtr() interface: no plug case
try {
cstSigNotPlug.getPtr();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
}
BOOST_CHECK(res);
/// Test needUpdate without plug
res = (sigNotPlug.needUpdate(5) == false);
BOOST_CHECK(res);
sigNotPlug.getTime();
output_test_stream output;
sigNotPlug.display(output);
cstSigNotPlug.display(output);
/// Testing getAbsatractPtr() interface: no plug
res = false;
try {
sigNotPlug.getAbstractPtr();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
}
BOOST_CHECK(res);
/// Testing const getAbstractPtr() interface: no plug case
try {
cstSigNotPlug.getAbstractPtr();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
}
BOOST_CHECK(res);
try {
sigNotPlug.checkCompatibility();
} catch (...) {
}
BOOST_CHECK(res);
}
BOOST_AUTO_TEST_CASE(normal_test) {
Signal<double, int> sig("sig");
Signal<int, int> sigint("sig");
Signal<std::string, int> sigstr("sig_str");
SignalPtr<double, int> sigPtrA(NULL, "sigPtrA"), sigPtrB(NULL, "sigPtrB");
SignalPtr<double, int> sigPtrAbstract(NULL, "sigPtrAbstract");
DummyClass<double> pro3("pro3");
sig.setConstant(1.56);
sig.recompute(2);
std::string name = "sig";
sig.getClassName(name);
std::string test = "test";
try {
sig.getClassName(test);
} catch (ExceptionSignal &e) {
e.getExceptionName();
}
BOOST_CHECK(true);
sigPtrA.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2));
sigPtrA.recompute(3);
/// Plugging signal.
SignalBase<int> &sigRef = sig, sigBase("sigBase");
SignalBase<int> &sigPtrARef = sigPtrA, &sigPtrBRef = sigPtrB,
&sigPtrAbstractRef = sigPtrAbstract;
sigPtrARef.plug(0);
sigPtrARef.plug(&sigRef);
sigPtrBRef.plug(&sigPtrARef);
/// Try to plug an incompatible signal.
/// leave
bool res = false;
try {
sigPtrARef.plug(&sigstr);
} catch (const ExceptionSignal &aes) {
res = (aes.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// Plug the signal.
sigPtrAbstractRef.plug(&sigRef);
sigPtrA.getPtr();
BOOST_CHECK(true);
try {
sigPtrARef.checkCompatibility();
} catch (const ExceptionSignal &aes) {
/// Should be NOT_INITIALIZED becase the last plug
/// on sigstr failed.
res = (aes.getCode() == ExceptionSignal::NOT_INITIALIZED);
} catch (const std::exception &e) {
std::cout << "Standard Exception:" << e.what() << std::endl;
} catch (...) {
std::cout << "Anything else: " << std::endl;
}
sigPtrA.needUpdate(5);
BOOST_CHECK(true);
int ltime = sigPtrA.getTime();
sigPtrA.getPluged();
sigPtrA(ltime);
BOOST_CHECK(true);
sigPtrB.getPtr();
/// Test sigPtrAbstract with a normal plug.
res = false;
try {
sigPtrAbstract.getAbstractPtr();
} catch (ExceptionSignal &aes) {
/// Should be NOT_INITIALIZED becase the last plug
/// on sigstr failed.
std::cout << "Code: " << aes.getCode() << std::endl;
res = (aes.getCode() == ExceptionSignal::NOT_INITIALIZED);
} catch (...) {
std::cout << "Anything else with sigPtrAbstract.getAbstractPtr()"
<< std::endl;
}
BOOST_CHECK(true);
/// Test the case where the plug ref is zero.
sigPtrAbstractRef.plug(0);
BOOST_CHECK(true);
assert(sigRef.isPlugged() != true);
SignalBase<int> *t = sigRef.getPluged();
// assert(sigPtrA.get()=false);
// TODO Can't check if the constant change
sigPtrA.setConstantDefault(1.2);
// getconstant
sigPtrA.setConstantDefault();
// getconstant
sigPtrA.setConstant(3.4);
// getconstant
double tab_D[2];
tab_D[0] = 1.2;
tab_D[1] = 3.4;
sigPtrA.setReference(tab_D, NULL);
sigPtrA.access(5);
output_test_stream output;
sigPtrA.display(output);
sigPtrA.setReferenceNonConstant(tab_D, NULL);
sigPtrA.access(5);
sigPtrA.display(output);
// getreference
sigPtrA.operator=(1.2);
// getconstant
sigPtrA.displayDependencies(output);
cout << t << std::endl;
cout << "Sig = ";
sigRef.get(cout);
cout << std::endl;
cout << "SigPtrA = ";
sigPtrARef.get(cout);
cout << std::endl;
cout << "SigPtrB = ";
sigPtrBRef.get(cout);
cout << std::endl;
sigPtrA.unplug();
}
BOOST_AUTO_TEST_CASE(plug_signal_string) {
Signal<std::string, int> outSig("output");
SignalPtr<std::string, int> inSig(NULL, "input");
Signal<dynamicgraph::Vector, int> outSigVec("outputVec");
SignalPtr<dynamicgraph::Vector, int> inSigVec(NULL, "inputVec");
std::string str("two words");
outSig.setConstant(str);
inSig.plug(&outSig);
inSig.recompute(1);
std::ostringstream os1;
inSig.get(os1);
std::string res(os1.str());
BOOST_CHECK(res == str);
dynamicgraph::Vector aVec;
aVec.resize(5);
aVec(0) = 1.0;
aVec(1) = 2.0;
aVec(2) = 3.0;
aVec(3) = 4.0;
aVec(4) = 5.0;
outSigVec.setConstant(aVec);
inSigVec.plug(&outSigVec);
inSigVec.recompute(1);
output_test_stream output;
inSigVec.get(output);
BOOST_CHECK(output.is_equal("1 2 3 4 5"));
Signal<std::string, int> s("signal");
std::ostringstream os2;
s.setConstant(str);
os2.clear();
s.get(os2);
res = os2.str();
std::cout << "res=" << res << std::endl;
BOOST_CHECK(res == str);
}
BOOST_AUTO_TEST_CASE(set_signal_string) {
Signal<std::string, int> s("signal");
std::string str("");
std::ostringstream os;
os << str;
std::istringstream value(os.str());
try {
s.set(value);
} catch (const std::exception &exc) {
std::cout << exc.what() << std::endl;
BOOST_CHECK(!(bool)("Tentative to set signal to empty string"));
}
}
// Copyright 2010 Thomas Moulard.
//
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/signal.h>
#include <boost/foreach.hpp>
#include <iostream>
#define BOOST_TEST_MODULE signal_time_dependent
#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;
typedef dynamicgraph::SignalTimeDependent<double, int> sigDouble_t;
typedef dynamicgraph::SignalTimeDependent<std::string, int> sigString_t;
template <class T>
class DummyClass {
public:
std::string proname;
std::list<sigDouble_t *> inputsig;
std::list<sigString_t *> inputsigV;
explicit DummyClass(const std::string &n)
: proname(n), res(), call(), timedata() {}
T &fun(T &res, int t) {
++call;
timedata = t;
BOOST_FOREACH (sigDouble_t *ptr, inputsig) ptr->access(timedata);
BOOST_FOREACH (sigString_t *ptr, inputsigV) ptr->access(timedata);
res = (*this)();
return res;
}
void add(sigDouble_t &sig) { inputsig.push_back(&sig); }
void add(sigString_t &sig) { inputsigV.push_back(&sig); }
T operator()();
T res;
int call;
int timedata;
};
template <>
double DummyClass<double>::operator()() {
res = call * timedata;
return res;
}
template <>
std::string DummyClass<std::string>::operator()() {
std::ostringstream oss;
oss << call * timedata;
return oss.str();
}
template <class T>
T DummyClass<T>::operator()() {
return this->res;
}
BOOST_AUTO_TEST_CASE(signaltimedependent) {
DummyClass<double> pro1("pro1"), pro3("pro3"), pro5("pro5");
DummyClass<std::string> pro2("pro2"), pro4("pro4"), pro6("pro6");
sigDouble_t sig5("Sig5");
sigString_t sig6("Sig6");
sigString_t sig4(sig5, "Sig4");
sigString_t sig2(sig4 << sig4 << sig4 << sig6, "Sig2");
sigDouble_t sig3(sig2 << sig5 << sig6, "Sig3");
sigDouble_t sig1(boost::bind(&DummyClass<double>::fun, &pro1, _1, _2),
sig2 << sig3, "Sig1");
sigDouble_t sig7("Sig7");
sig2.setFunction(boost::bind(&DummyClass<std::string>::fun, &pro2, _1, _2));
sig3.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2));
sig4.setFunction(boost::bind(&DummyClass<std::string>::fun, &pro4, _1, _2));
sig5.setFunction(boost::bind(&DummyClass<double>::fun, &pro5, _1, _2));
sig6.setFunction(boost::bind(&DummyClass<std::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(dynamicgraph::TimeDependency<int>::ALWAYS_READY);
sig6.setDependencyType(dynamicgraph::TimeDependency<int>::BOOL_DEPENDENT);
sig5.setPeriodTime(3);
assert(sig5.getPeriodTime() == 3);
sig6.setReady();
{
output_test_stream output;
sig1.displayDependencies(output);
BOOST_CHECK(
output.is_equal("-- Sig:Sig1 (Type Fun) (t=0 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=0 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=TRUE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=0 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=TRUE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=0 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=TRUE)\n"
" |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"));
}
BOOST_CHECK(sig1.needUpdate(2));
sig1.access(2);
{
output_test_stream output;
sig1.displayDependencies(output);
BOOST_CHECK(
output.is_equal("-- Sig:Sig1 (Type Fun) (t=2 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=2 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=2 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=2 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"));
}
sig2.access(4);
{
output_test_stream output;
sig1.displayDependencies(output);
BOOST_CHECK(
output.is_equal("-- Sig:Sig1 (Type Fun) (t=2 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=2 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"));
}
sig1.access(4);
{
output_test_stream output;
sig1.displayDependencies(output);
BOOST_CHECK(
output.is_equal("-- Sig:Sig1 (Type Fun) (t=4 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=4 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"));
}
sig1.needUpdate(6);
sig1.needUpdate(6);
output_test_stream output;
sig1.writeGraph(output);
BOOST_CHECK(output.is_equal(""));
sig1.removeDependency(sig3);
BOOST_CHECK(true);
const double &avalue = sig1(6);
output << avalue;
BOOST_CHECK(true);
/// Verify check compatibility
try {
sig1.checkCompatibility();
}
// catch(double e)
catch (...) {
std::cout << "Message: test \n";
}
BOOST_CHECK(true);
}
/* 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 2010, Olivier Stasse, JRL, CNRS/AIST
#
# This file is part of dynamic-graph.
# dynamic-graph is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# dynamic-graph is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Lesser Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with
# dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
SET(tools dg-shell)
# Configure shell launch script.
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/dg-shell-plugin.cmake
${${PROJECT_NAME}_BINARY_DIR}/tools/dg-shell-plugin)
INSTALL(
FILES
${${PROJECT_NAME}_BINARY_DIR}/tools/dg-shell-plugin
DESTINATION
bin
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)
ENDFOREACH(tool_name)
#! /bin/sh
tmp=`mktemp`
echo "-- Launching dynamic-graph C shell with default plugins"
echo "loadPlugin ${CMAKE_INSTALL_PREFIX}/lib/plugin/shell-functions.so" > $tmp
echo "loadPlugin ${CMAKE_INSTALL_PREFIX}/lib/plugin/shell-procedure.so" >> $tmp
${CMAKE_INSTALL_PREFIX}/bin/dg-shell $tmp
/*
* Copyright 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* 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 2010, Olivier Stasse, JRL, CNRS/AIST
#
# This file is part of dynamic-graph.
# dynamic-graph is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# dynamic-graph is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Lesser Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with
# dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
### 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)
LINK_DIRECTORIES(../src)
# 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)
/*
* Copyright 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
/* -------------------------------------------------------------------------- */
/* --- 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 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
/* -------------------------------------------------------------------------- */
/* --- 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 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
/* -------------------------------------------------------------------------- */
/* --- 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;
}
/*
* Copyright 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
#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;
/*
* Copyright 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
typedef boost::numeric::ublas::vector<double> vec_type;
extern vec_type vA;
/*
* Copyright 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
#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;
/*
* Copyright 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
typedef boost::numeric::ublas::vector<double> vec_type;
extern vec_type vB;