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,
* 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
#
### 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)
/*
* 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;