29 #include "../internal/DataSource.hpp" 30 #include "../ExecutionEngine.hpp" 33 #include "../Service.hpp" 35 #include "../TaskContext.hpp" 36 #include "../internal/mystd.hpp" 40 #include <boost/lambda/lambda.hpp> 43 using namespace detail;
45 using boost::tuples::get;
59 std::map<const StateInterface*, StateInterface*> statemapping;
61 ret->_text = this->_text;
62 ret->setName( this->_name,
false);
69 ret->setService( this->object->copy(ret, replacements, instantiate) );
72 for ( VisibleWritableValuesMap::const_iterator i = parametervalues.begin();
73 i != parametervalues.end(); ++i )
77 assert( ret->getService()->getValue( i->first ) );
78 ret->parametervalues[i->first] = ret->getService()->getValue( i->first );
84 for ( ChildList::const_iterator i = getChildren().begin(); i != getChildren().end(); ++i )
87 assert( dynamic_cast<ParsedStateMachine*>( i->get() ) == static_cast<ParsedStateMachine*>( i->get() ));
94 newmachine->setParent( ret );
98 if (this->getInitCommand()) {
99 ret->setInitCommand( this->getInitCommand()->copy(replacements) );
107 for ( TransitionMap::const_iterator i = stateMap.begin(); i != stateMap.end(); ++i )
109 if( statemapping.find( i->first ) == statemapping.end() && i->first != 0 ) {
111 ret->addState( cpy );
112 statemapping[i->first] = cpy;
117 for ( TransitionMap::const_iterator i = stateMap.begin(); i != stateMap.end(); ++i )
119 assert( statemapping.find( i->first ) != statemapping.end() );
121 for ( TransList::const_iterator j = i->second.begin(); j != i->second.end(); ++j )
124 assert( statemapping.find( j->get<1>() ) != statemapping.end() );
126 int rank = j->get<2>();
127 int line = j->get<3>();
128 boost::shared_ptr<ProgramInterface> transprog( j->get<4>() );
130 transprog.reset( j->get<4>()->copy(replacements) );
131 ret->transitionSet(fromState, toState, condition, transprog, rank, line );
136 for ( EventMap::const_iterator i = eventMap.begin(); i != eventMap.end(); ++i )
138 assert( statemapping.find( i->first ) != statemapping.end() );
140 for ( EventList::const_iterator j = i->second.begin(); j != i->second.end(); ++j )
143 string ename = j->get<1>();
144 vector<DataSourceBase::shared_ptr> origargs( j->get<2>() );
145 vector<DataSourceBase::shared_ptr> newargs;
146 for ( vector<DataSourceBase::shared_ptr>::const_iterator vit = origargs.begin();
147 vit != origargs.end(); ++vit)
148 newargs.push_back( (*vit)->copy(replacements) );
154 tprog.reset( tgraph->copy(replacements) );
159 eprog.reset( egraph->copy(replacements) );
163 ret->createEventTransition(sp, ret->getService()->getOwner()->engine(), ename, newargs, fromState, toState, condition, tprog, elseState, eprog );
169 for ( PreConditionMap::const_iterator i = precondMap.begin(); i != precondMap.end(); ++i )
171 assert( statemapping.find( i->first ) != statemapping.end() );
174 int line = i->second.second;
175 ret->preconditionSet( tgtState, condition, line );
179 ret->setFinalState( statemapping[ getFinalState() ]);
180 ret->setInitialState( statemapping[ getInitialState() ]);
186 this->smStatus = Status::unloaded;
187 if ( this->isLoaded() ){
188 getEngine()->removeFunction(
this);
192 for ( TransitionMap::iterator i = stateMap.begin();
193 i != stateMap.end(); ++i )
196 for ( TransitionMap::iterator i = stateMap.begin();
197 i != stateMap.end(); ++i )
198 for ( TransList::iterator i2 = i->second.begin(); i2 != i->second.end(); ++i2 )
199 delete get<0>( *i2 );
202 for ( EventMap::iterator i = eventMap.begin();
203 i != eventMap.end(); ++i )
204 for ( EventList::iterator i2 = i->second.begin(); i2 != i->second.end(); ++i2 )
205 delete get<4>( *i2 );
212 _text.reset(
new string(
"No Text Set.") );
221 if ( object->getParent() &&
object->getParent()->hasService( object->getName() ) ){
222 assert(
object == object->getParent()->getService( object->getName() ) );
223 object->getParent()->removeService( object->getName() );
230 assert( parametervalues.find( name ) == parametervalues.end() );
231 parametervalues[name] = var;
238 if( parametervalues.find( name ) == parametervalues.end() )
240 return parametervalues.find(name)->second;
245 return parametervalues;
250 return keys( parametervalues );
266 if ( recursive ==
false )
271 std::string subname = name +
"." + (*i)->getName();
301 return copy->
getName() == name;
bool inState(const std::string &name)
A hierarchical StateMachine which is loaded in the Program Processor.
boost::shared_ptr< StateMachineService > StateMachineServicePtr
boost::shared_ptr< ParsedStateMachine > ParsedStateMachinePtr
void finish()
Call this function if the state machine is parsed.
std::string getText() const
Return the text to which getLineNumber() refers.
void setName(const std::string &name, bool recursive)
Set the name of this machine.
void setText(std::string text)
This interface represents the concept of a condition which can be evaluated and return true or false...
virtual const std::string & getName() const =0
Get the name of this state.
virtual ConditionInterface * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
When copying an Orocos program, we want identical internal::DataSource's to be mapped to identical Da...
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
std::vector< std::string > getParameterNames() const
void addParameter(const std::string &name, base::AttributeBase *var)
void setService(boost::shared_ptr< StateMachineService > tc)
virtual ~ParsedStateMachine()
An attribute is a minimalistic, named placeholder for data.
boost::shared_ptr< Service > ServicePtr
boost::shared_ptr< StateMachineService > getService() const
StateInterface * currentState() const
Retrieve the current state of the state machine.
static std::ostream & endl(std::ostream &__os)
void unloading()
Informs this object that it got unloaded from an ExecutionEngine.
ParsedStateMachinePtr copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &replacements, bool instantiate=false) const
Create a copy, set instantiate to 'true' if instantiating a RootMachine.
boost::shared_ptr< StateMachine > StateMachinePtr
virtual StateInterface * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &replacementdss) const =0
std::vector< typename MapT::key_type > keys(const MapT &map)
void addChild(StateMachinePtr child)
static Logger & log()
As Instance(), but more userfriendly.
base::AttributeBase * getParameter(const std::string &name) const
VisibleWritableValuesMap getParameters() const
virtual void unloading()
Informs this object that it got unloaded from an ExecutionEngine.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
State machine created by the scripting engine which represents a parsed state machine.
A State contains an entry, run, handle and exit program.
const ChildList & getChildren() const
Get a list of all child state machines.