39 #include "../internal/DataSource.hpp" 40 #include "../ExecutionEngine.hpp" 43 #include "../Service.hpp" 45 #include "../TaskContext.hpp" 46 #include "../internal/mystd.hpp" 50 #include <boost/lambda/lambda.hpp> 53 using namespace detail;
55 using boost::tuples::get;
69 std::map<const StateInterface*, StateInterface*> statemapping;
71 ret->_text = this->_text;
72 ret->setName( this->_name,
false);
79 ret->setService( this->object->copy(ret, replacements, instantiate) );
82 for ( VisibleWritableValuesMap::const_iterator i = parametervalues.begin();
83 i != parametervalues.end(); ++i )
87 assert( ret->getService()->getValue( i->first ) );
88 ret->parametervalues[i->first] = ret->getService()->getValue( i->first );
94 for ( ChildList::const_iterator i = getChildren().begin(); i != getChildren().end(); ++i )
97 assert( dynamic_cast<ParsedStateMachine*>( i->get() ) == static_cast<ParsedStateMachine*>( i->get() ));
104 newmachine->setParent( ret );
108 if (this->getInitCommand()) {
109 ret->setInitCommand( this->getInitCommand()->copy(replacements) );
117 for ( TransitionMap::const_iterator i = stateMap.begin(); i != stateMap.end(); ++i )
119 if( statemapping.find( i->first ) == statemapping.end() && i->first != 0 ) {
121 ret->addState( cpy );
122 statemapping[i->first] = cpy;
127 for ( TransitionMap::const_iterator i = stateMap.begin(); i != stateMap.end(); ++i )
129 assert( statemapping.find( i->first ) != statemapping.end() );
131 for ( TransList::const_iterator j = i->second.begin(); j != i->second.end(); ++j )
134 assert( statemapping.find( j->get<1>() ) != statemapping.end() );
136 int rank = j->get<2>();
137 int line = j->get<3>();
138 boost::shared_ptr<ProgramInterface> transprog( j->get<4>() );
140 transprog.reset( j->get<4>()->copy(replacements) );
141 ret->transitionSet(fromState, toState, condition, transprog, rank, line );
146 for ( EventMap::const_iterator i = eventMap.begin(); i != eventMap.end(); ++i )
148 assert( statemapping.find( i->first ) != statemapping.end() );
150 for ( EventList::const_iterator j = i->second.begin(); j != i->second.end(); ++j )
153 string ename = j->get<1>();
154 vector<DataSourceBase::shared_ptr> origargs( j->get<2>() );
155 vector<DataSourceBase::shared_ptr> newargs;
156 for ( vector<DataSourceBase::shared_ptr>::const_iterator vit = origargs.begin();
157 vit != origargs.end(); ++vit)
158 newargs.push_back( (*vit)->copy(replacements) );
164 tprog.reset( tgraph->copy(replacements) );
169 eprog.reset( egraph->copy(replacements) );
173 ret->createEventTransition(sp, ret->getService()->getOwner()->engine(), ename, newargs, fromState, toState, condition, tprog, elseState, eprog );
179 for ( PreConditionMap::const_iterator i = precondMap.begin(); i != precondMap.end(); ++i )
181 assert( statemapping.find( i->first ) != statemapping.end() );
184 int line = i->second.second;
185 ret->preconditionSet( tgtState, condition, line );
189 ret->setFinalState( statemapping[ getFinalState() ]);
190 ret->setInitialState( statemapping[ getInitialState() ]);
196 this->smStatus = Status::unloaded;
197 if ( this->isLoaded() ){
198 getEngine()->removeFunction(
this);
202 for ( TransitionMap::iterator i = stateMap.begin();
203 i != stateMap.end(); ++i )
206 for ( TransitionMap::iterator i = stateMap.begin();
207 i != stateMap.end(); ++i )
208 for ( TransList::iterator i2 = i->second.begin(); i2 != i->second.end(); ++i2 )
209 delete get<0>( *i2 );
212 for ( EventMap::iterator i = eventMap.begin();
213 i != eventMap.end(); ++i )
214 for ( EventList::iterator i2 = i->second.begin(); i2 != i->second.end(); ++i2 )
215 delete get<4>( *i2 );
222 _text.reset(
new string(
"No Text Set.") );
231 if (
object->getParent() &&
object->getParent()->hasService(
object->getName() ) ){
232 assert(
object ==
object->getParent()->getService(
object->getName() ) );
233 object->getParent()->removeService(
object->getName() );
276 if ( recursive ==
false )
281 std::string subname = name +
"." + (*i)->getName();
311 return copy->
getName() == name;
bool inState(const std::string &name)
A hierarchical StateMachine which is loaded in the Program Processor.
std::map< std::string, base::AttributeBase * > VisibleWritableValuesMap
boost::shared_ptr< StateMachineService > StateMachineServicePtr
boost::shared_ptr< ParsedStateMachine > ParsedStateMachinePtr
std::string getText() const
void setName(const std::string &name, bool recursive)
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
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
std::vector< std::string > getParameterNames() const
VisibleWritableValuesMap parametervalues
void addParameter(const std::string &name, base::AttributeBase *var)
void setService(boost::shared_ptr< StateMachineService > tc)
virtual ~ParsedStateMachine()
boost::shared_ptr< StateMachineService > object
boost::shared_ptr< Service > ServicePtr
boost::shared_ptr< StateMachineService > getService() const
StateInterface * currentState() const
static std::ostream & endl(std::ostream &__os)
ParsedStateMachinePtr copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &replacements, bool instantiate=false) const
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)
boost::shared_ptr< std::string > _text
base::AttributeBase * getParameter(const std::string &name) const
VisibleWritableValuesMap getParameters() const
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
const ChildList & getChildren() const