Skip to content
Snippets Groups Projects
Commit 3b87474d authored by Olivier Stasse's avatar Olivier Stasse
Browse files

Reinforce the dependant->dependent policy.

Merge the florent branch.
Makes the test_depend.cpp test works.
parent 26636b21
No related branches found
No related tags found
No related merge requests found
...@@ -76,7 +76,7 @@ class SignalBase : public boost::noncopyable ...@@ -76,7 +76,7 @@ class SignalBase : public boost::noncopyable
} }
virtual std::ostream& virtual std::ostream&
displayDependancies( std::ostream& os,const int depth=-1, displayDependencies( std::ostream& os,const int depth=-1,
std::string space="", std::string space="",
std::string next1="",std::string next2="" ) const std::string next1="",std::string next2="" ) const
{ {
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#ifndef __TIME_DEPENDANCY_HH #ifndef __TIME_DEPENDENCY_HH
#define __TIME_DEPENDANCY_HH #define __TIME_DEPENDENCY_HH
#include <list> #include <list>
#include <iostream> #include <iostream>
...@@ -36,10 +36,10 @@ template< class Time > ...@@ -36,10 +36,10 @@ template< class Time >
class TimeDependency class TimeDependency
{ {
public: public:
enum DependancyType enum DependencyType
{ {
TIME_DEPENDANT, TIME_DEPENDENT,
BOOL_DEPENDANT, BOOL_DEPENDENT,
ALWAYS_READY ALWAYS_READY
}; };
...@@ -50,14 +50,14 @@ class TimeDependency ...@@ -50,14 +50,14 @@ class TimeDependency
SignalBase< Time >& leader; SignalBase< Time >& leader;
typedef std::list< const SignalBase<Time> * > Dependancies; typedef std::list< const SignalBase<Time> * > Dependencies;
static const DependancyType DEPENDANCY_TYPE_DEFAULT = TIME_DEPENDANT; static const DependencyType DEPENDENCY_TYPE_DEFAULT = TIME_DEPENDENT;
Dependancies dependancies; Dependencies dependencies;
bool updateFromAllChildren; bool updateFromAllChildren;
static const bool ALL_READY_DEFAULT = false; static const bool ALL_READY_DEFAULT = false;
DependancyType dependancyType; DependencyType dependencyType;
Time periodTime; Time periodTime;
static const Time PERIOD_TIME_DEFAULT = 1; static const Time PERIOD_TIME_DEFAULT = 1;
...@@ -65,25 +65,25 @@ class TimeDependency ...@@ -65,25 +65,25 @@ class TimeDependency
public: public:
TimeDependency( SignalBase<Time>* sig, TimeDependency( SignalBase<Time>* sig,
const DependancyType dep = DEPENDANCY_TYPE_DEFAULT ); const DependencyType dep = DEPENDENCY_TYPE_DEFAULT );
TimeDependency( SignalBase<Time>* sig, TimeDependency( SignalBase<Time>* sig,
const SignalArray_const<Time>& arr, const SignalArray_const<Time>& arr,
const DependancyType dep = DEPENDANCY_TYPE_DEFAULT ); const DependencyType dep = DEPENDENCY_TYPE_DEFAULT );
~TimeDependency( void ) {} ~TimeDependency( void ) {}
void addDependancy( const SignalBase<Time>& sig ); void addDependency( const SignalBase<Time>& sig );
void removeDependancy( const SignalBase<Time>& sig ); void removeDependency( const SignalBase<Time>& sig );
void clearDependancy( void ); void clearDependency( void );
virtual std::ostream & writeGraph(std::ostream &os) const; virtual std::ostream & writeGraph(std::ostream &os) const;
std::ostream& displayDependancies( std::ostream& os,const int depth=-1, std::ostream& displayDependencies( std::ostream& os,const int depth=-1,
std::string space="", std::string space="",
std::string next1="",std::string next2="" ) const; std::string next1="",std::string next2="" ) const;
bool needUpdate( const Time& t1 ) const; bool needUpdate( const Time& t1 ) const;
void setDependancyType( DependancyType dep ) { dependancyType = dep; } void setDependencyType( DependencyType dep ) { dependencyType = dep; }
void setNeedUpdateFromAllChildren( const bool b = true ){ updateFromAllChildren=b; } void setNeedUpdateFromAllChildren( const bool b = true ){ updateFromAllChildren=b; }
bool getNeedUpdateFromAllChildren( void ) const { return updateFromAllChildren; } bool getNeedUpdateFromAllChildren( void ) const { return updateFromAllChildren; }
...@@ -98,4 +98,4 @@ class TimeDependency ...@@ -98,4 +98,4 @@ class TimeDependency
#include <dynamic-graph/time-dependency.t.cpp> #include <dynamic-graph/time-dependency.t.cpp>
#endif /* #ifndef __TIME_DEPENDANCY_HH */ #endif /* #ifndef __TIME_DEPENDENCY_HH */
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#ifndef __TIME_DEPENDANCY_TCPP #ifndef __TIME_DEPENDENCY_TCPP
#define __TIME_DEPENDANCY_TCPP #define __TIME_DEPENDENCY_TCPP
#include <dynamic-graph/time-dependency.h> #include <dynamic-graph/time-dependency.h>
...@@ -31,30 +31,30 @@ namespace dynamicgraph { ...@@ -31,30 +31,30 @@ namespace dynamicgraph {
#define VP_TEMPLATE_DEBUG_MODE 0 #define VP_TEMPLATE_DEBUG_MODE 0
#include <dynamic-graph/debug.h> #include <dynamic-graph/debug.h>
#define __TIME_DEPENDANCY_INIT(sig,dep) \ #define __TIME_DEPENDENCY_INIT(sig,dep) \
leader(*sig) \ leader(*sig) \
,dependancies() \ ,dependencies() \
,updateFromAllChildren(ALL_READY_DEFAULT) \ ,updateFromAllChildren(ALL_READY_DEFAULT) \
,dependancyType(dep) \ ,dependencyType(dep) \
,periodTime(PERIOD_TIME_DEFAULT) ,periodTime(PERIOD_TIME_DEFAULT)
template< class Time > template< class Time >
TimeDependency<Time>:: TimeDependency<Time>::
TimeDependency( SignalBase<Time> *sig TimeDependency( SignalBase<Time> *sig
,const DependancyType dep ) ,const DependencyType dep )
:__TIME_DEPENDANCY_INIT(sig,dep) :__TIME_DEPENDENCY_INIT(sig,dep)
{} {}
template< class Time > template< class Time >
TimeDependency<Time>:: TimeDependency<Time>::
TimeDependency( SignalBase<Time> * sig TimeDependency( SignalBase<Time> * sig
,const SignalArray_const<Time>& ar ,const SignalArray_const<Time>& ar
,const DependancyType dep ) ,const DependencyType dep )
:__TIME_DEPENDANCY_INIT(sig,dep) :__TIME_DEPENDENCY_INIT(sig,dep)
{ {
for( unsigned int i=0;i<ar.getSize();++i ) for( unsigned int i=0;i<ar.getSize();++i )
{addDependancy( ar[i] ); } {addDependency( ar[i] ); }
return ; return ;
} }
...@@ -62,22 +62,22 @@ TimeDependency( SignalBase<Time> * sig ...@@ -62,22 +62,22 @@ TimeDependency( SignalBase<Time> * sig
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
template< class Time > template< class Time >
void TimeDependency<Time>:: void TimeDependency<Time>::
addDependancy( const SignalBase<Time>& sig ) addDependency( const SignalBase<Time>& sig )
{ {
dependancies.push_front(&sig); dependencies.push_front(&sig);
} }
template< class Time > template< class Time >
void TimeDependency<Time>:: void TimeDependency<Time>::
removeDependancy( const SignalBase<Time>& sig ) removeDependency( const SignalBase<Time>& sig )
{ {
dependancies.remove(&sig); dependencies.remove(&sig);
} }
template< class Time > template< class Time >
void TimeDependency<Time>:: void TimeDependency<Time>::
clearDependancy( void ) clearDependency( void )
{ {
dependancies.clear(); dependencies.clear();
} }
template< class Time > template< class Time >
...@@ -90,12 +90,12 @@ needUpdate( const Time& t1 ) const ...@@ -90,12 +90,12 @@ needUpdate( const Time& t1 ) const
if( leader.getReady() ) { dgTDEBUGOUT(15);return true; } if( leader.getReady() ) { dgTDEBUGOUT(15);return true; }
if( lastAskForUpdate ) { dgTDEBUGOUT(15);return true; } if( lastAskForUpdate ) { dgTDEBUGOUT(15);return true; }
switch( dependancyType ) switch( dependencyType )
{ {
case ALWAYS_READY: case ALWAYS_READY:
{ dgTDEBUGOUT(15);return true; } { dgTDEBUGOUT(15);return true; }
case BOOL_DEPENDANT: break; case BOOL_DEPENDENT: break;
case TIME_DEPENDANT: case TIME_DEPENDENT:
{ {
if( t1<leader.getTime()+periodTime ) if( t1<leader.getTime()+periodTime )
{ dgTDEBUGOUT(15);return false; } { dgTDEBUGOUT(15);return false; }
...@@ -104,8 +104,8 @@ needUpdate( const Time& t1 ) const ...@@ -104,8 +104,8 @@ needUpdate( const Time& t1 ) const
}; };
bool res = updateFromAllChildren; bool res = updateFromAllChildren;
const typename Dependancies::const_iterator itend=dependancies.end(); const typename Dependencies::const_iterator itend=dependencies.end();
for( typename Dependancies::const_iterator it=dependancies.begin();it!=itend;++it ) for( typename Dependencies::const_iterator it=dependencies.begin();it!=itend;++it )
{ {
const SignalBase<Time> &sig = **it; const SignalBase<Time> &sig = **it;
dgTDEBUG(15)<< "Ask update for "<< sig <<std::endl; dgTDEBUG(15)<< "Ask update for "<< sig <<std::endl;
...@@ -128,10 +128,10 @@ writeGraph( std::ostream & os) const ...@@ -128,10 +128,10 @@ writeGraph( std::ostream & os) const
std::string LeaderLocalName; std::string LeaderLocalName;
std::string LeaderNodeName; std::string LeaderNodeName;
leader.ExtractNodeAndLocalNames(LeaderLocalName,LeaderNodeName); leader.ExtractNodeAndLocalNames(LeaderLocalName,LeaderNodeName);
if (dependancies.size()!=0) if (dependencies.size()!=0)
{ {
const typename Dependancies::const_iterator itend=dependancies.end(); const typename Dependencies::const_iterator itend=dependencies.end();
for( typename Dependancies::const_iterator it=dependancies.begin();it!=itend;++it ) for( typename Dependencies::const_iterator it=dependencies.begin();it!=itend;++it )
{ {
std::string itLocalName,itNodeName; std::string itLocalName,itNodeName;
(*it)->ExtractNodeAndLocalNames(itLocalName,itNodeName); (*it)->ExtractNodeAndLocalNames(itLocalName,itNodeName);
...@@ -144,31 +144,31 @@ writeGraph( std::ostream & os) const ...@@ -144,31 +144,31 @@ writeGraph( std::ostream & os) const
template< class Time > template< class Time >
std::ostream& TimeDependency<Time>:: std::ostream& TimeDependency<Time>::
displayDependancies( std::ostream& os,const int depth, displayDependencies( std::ostream& os,const int depth,
std::string space, std::string space,
std::string next1,std::string next2 ) const std::string next1,std::string next2 ) const
{ {
leader.SignalBase<Time>::displayDependancies(os,depth,space,next1,next2)<<" ("; leader.SignalBase<Time>::displayDependencies(os,depth,space,next1,next2)<<" (";
switch( dependancyType ) switch( dependencyType )
{ {
case ALWAYS_READY: os<<"A"; break; case ALWAYS_READY: os<<"A"; break;
case BOOL_DEPENDANT: os << "ready=" << ((leader.getReady())?"TRUE":"FALSE"); break; case BOOL_DEPENDENT: os << "ready=" << ((leader.getReady())?"TRUE":"FALSE"); break;
case TIME_DEPENDANT: case TIME_DEPENDENT:
os <<"t="<<leader.getTime() <<" (/"<<periodTime<<") " ; os <<"t="<<leader.getTime() <<" (/"<<periodTime<<") " ;
break; break;
}; };
os<<")"; //<<std::endl; os<<")"; //<<std::endl;
{ {
const typename Dependancies::const_iterator itend=dependancies.end(); const typename Dependencies::const_iterator itend=dependencies.end();
for( typename Dependancies::const_iterator it=dependancies.begin();it!=itend;++it ) for( typename Dependencies::const_iterator it=dependencies.begin();it!=itend;++it )
if( depth!=0 ) if( depth!=0 )
{ {
os<<std::endl; os<<std::endl;
std::string ajout = "|"; std::string ajout = "|";
std::string ajout2 = "|"; std::string ajout2 = "|";
typename Dependancies::const_iterator it2=it; it2++; typename Dependencies::const_iterator it2=it; it2++;
if( it2==dependancies.end() ) { ajout = "`"; ajout2= " "; } if( it2==dependencies.end() ) { ajout = "`"; ajout2= " "; }
(*it)->displayDependancies( os,depth-1,space+next2+" ",ajout,ajout2 ); (*it)->displayDependencies( os,depth-1,space+next2+" ",ajout,ajout2 );
} }
else else
{ os<<std::endl<<space<<" `-- ..."; break; } { os<<std::endl<<space<<" `-- ..."; break; }
...@@ -178,6 +178,6 @@ displayDependancies( std::ostream& os,const int depth, ...@@ -178,6 +178,6 @@ displayDependancies( std::ostream& os,const int depth,
} // namespace dynamicgraph } // namespace dynamicgraph
#endif /* #ifndef __TIME_DEPENDANCY_TCPP */ #endif /* #ifndef __TIME_DEPENDENCY_TCPP */
...@@ -238,7 +238,7 @@ commandLine( const std::string& cmdLine,std::istringstream& cmdArgs,std::ostream ...@@ -238,7 +238,7 @@ commandLine( const std::string& cmdLine,std::istringstream& cmdArgs,std::ostream
string sig; cmdArgs>>sig; string sig; cmdArgs>>sig;
cmdArgs >> ws; int depth=-1; cmdArgs >> ws; int depth=-1;
if( cmdArgs.good() ) { cmdArgs >> depth; } if( cmdArgs.good() ) { cmdArgs >> depth; }
getSignal(sig) .displayDependancies( os,depth ); os<<endl; getSignal(sig) .displayDependencies( os,depth ); os<<endl;
} }
else else
{ {
......
...@@ -133,23 +133,24 @@ int main( void ) ...@@ -133,23 +133,24 @@ int main( void )
pro3.add(sig5); pro3.add(sig5);
pro3.add(sig6); pro3.add(sig6);
sig5.setDependancyType(TimeDependency<int>::ALWAYS_READY); sig5.setDependencyType(TimeDependency<int>::ALWAYS_READY);
sig6.setDependancyType(TimeDependency<int>::BOOL_DEPENDANT); sig6.setDependencyType(TimeDependency<int>::BOOL_DEPENDENT);
sig6.setReady(); sig6.setReady();
sig1.displayDependancies(cout)<<endl; sig1.displayDependencies(cout)<<endl;
cout << "Needs update?"<< endl << sig1.needUpdate(2) << endl; cout << "Needs update?" << endl
<< sig1.needUpdate(2) << endl;
dgDEBUG(1) << "Access sig1(2) "<<endl; dgDEBUG(1) << "Access sig1(2) "<<endl;
sig1.access(2); sig1.access(2);
sig1.displayDependancies(cout)<<endl; sig1.displayDependencies(cout) << endl;
dgDEBUG(1) << "Access sig2(4) "<<endl; dgDEBUG(1) << "Access sig2(4) "<<endl;
sig2.access(4); sig2.access(4);
sig1.displayDependancies(cout)<<endl; sig1.displayDependencies(cout)<<endl;
dgDEBUG(1) << "Access sig1(4) "<<endl; dgDEBUG(1) << "Access sig1(4) "<<endl;
sig1.access(4); sig1.access(4);
sig1.displayDependancies(cout)<<endl; sig1.displayDependencies(cout)<<endl;
sig1.needUpdate(6); sig1.needUpdate(6);
sig1.needUpdate(6); sig1.needUpdate(6);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment