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 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
#
### 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
${CMAKE_INSTALL_PREFIX}/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 ${CMAKE_INSTALL_PREFIX}/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( ExceptionAbstract& e )
{
cout << "!! In file <" << argv[fileIdx] << "> : " << e <<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( ExceptionAbstract& e )
{
cout << "!! " << e <<endl;
}
catch( ... ){ dgDEBUG(5) << "!! Unknown! " <<endl ; }
}
dgDEBUGOUT(15);
return 0;
}
#
# Copyright
#
### tests
SET(tests
test_pool
test_depend
test_signalcast)
FOREACH(test_name ${tests})
SET(EXECUTABLE_NAME ${test_name})
ADD_DEFINITIONS(-DDEBUG=2)
ADD_EXECUTABLE(${EXECUTABLE_NAME}
${test_name}.cpp)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../include
)
LINK_DIRECTORIES(${${PROJECT_NAME}_BINARY_DIR}/lib)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
${PROJECT_NAME}
dl)
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;
}
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 <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 <memory>
using namespace std;
using namespace dynamicgraph;
int main() {
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);
return 0;
}