virtual base::ActionInterface* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const { CommandComposite* res = new CommandComposite(); for (std::vector<base::ActionInterface*>::const_iterator it=vect.begin();it!=vect.end();it++) res->add( (*it)->copy(alreadyCloned) ); return res; }
void StateGraphParser::seenstatemachineend() { assert( curtemplate ); assert( ! curstate ); // reclaim the defined variables: // Check if the Initial and Final States are ok. if ( curtemplate->getInitialState() == 0 ) ORO_THROW( parse_exception_semantic_error("No initial state defined.")); if ( curtemplate->getFinalState() == 0 ) ORO_THROW( parse_exception_semantic_error("No final state defined.")); if ( curtemplate->getStateList().empty() ) ORO_THROW( parse_exception_semantic_error("No states defined in this state machine !")); // Check if all States are defined. vector<string> states = curtemplate->getStateList(); for( vector<string>::const_iterator it = states.begin(); it != states.end(); ++it) { assert( dynamic_cast<StateDescription*>( curtemplate->getState( *it ) ) ); StateDescription* sd = static_cast<StateDescription*>( curtemplate->getState( *it ) ); if ( !sd->isDefined() ) ORO_THROW( parse_exception_semantic_error("State " + *it + " not defined, but referenced to.")); } // retrieve _all_ defined variables and parameters, store them and cleanup the // valuechangeparser. valuechangeparser->store( curtemplate->getService() ); valuechangeparser->reset(); // prepend the commands for initialising the subMachine // variables.. assert( curtemplate->getInitCommand() == 0); if ( varinitcommands.size() > 1 ) { CommandComposite* comcom = new CommandComposite; for ( std::vector<ActionInterface*>::iterator i = varinitcommands.begin(); i != varinitcommands.end(); ++i ) comcom->add( *i ); curtemplate->setInitCommand( comcom ); } else if (varinitcommands.size() == 1 ) curtemplate->setInitCommand( *varinitcommands.begin() ); varinitcommands.clear(); // remove temporary subMachine peers from current task. for( StateMachine::ChildList::const_iterator it= curtemplate->getChildren().begin(); it != curtemplate->getChildren().end(); ++it ) { ParsedStateMachine* psc = dynamic_cast<ParsedStateMachine*>( it->get() ); if (psc) { // remove from parent context->provides()->removeService( psc->getService()->getName() ); } } // finally : curtemplate->finish(); delete progParser; progParser = 0; StateMachineBuilder* scb = new StateMachineBuilder( curtemplate ); machinebuilders[curmachinename] = scb; // save curmachinename for saveText. curobject.reset(); curtemplate.reset(); }
void StateGraphParser::seenmachineinstantiation() { // TODO : move this code to the ParsedStateMachine builder. // Create a full depth copy (including subMachines) // if RootMachine, make special copy which fixes attributes such // that on subsequent copy() they keep pointing to same var. // use shared_ptr to release on throw's below. ParsedStateMachinePtr nsc( curmachinebuilder->build( isroot ) ); // we stored the attributes which are params of nsc // in the build operation : machineparams_t params = nsc->getParameters(); // first run over the given parameters to see if they all exist in // the context we're instantiating... for ( machineparamvalues_t::iterator i = curinstmachineparams.begin(); i != curinstmachineparams.end(); ++i ) { machineparams_t::iterator j = params.find( i->first ); if ( j == params.end() ) ORO_THROW( parse_exception_semantic_error( "No parameter \"" + i->first + "\" in this StateMachine." ) ); } for ( machineparams_t::iterator i = params.begin(); i != params.end(); ++i ) { machineparamvalues_t::iterator j = curinstmachineparams.find( i->first ); if ( j == curinstmachineparams.end() ) ORO_THROW( parse_exception_semantic_error( "No value given for argument \"" + i->first + "\" in instantiation of this StateMachine." )); #ifndef ORO_EMBEDDED try { paraminitcommands.push_back( i->second->getDataSource()->updateAction( j->second.get() ) ); } catch( const bad_assignment& ) { throw parse_exception_semantic_error("Attempt to initialize parameter '"+i->first+"' with a value which is of a different type." ); } #else ActionInterface* ret = i->second->getDataSource()->updateAction( j->second.get()); if (ret) paraminitcommands.push_back( ret ); else return; #endif } curinstantiatedmachine = nsc; // prepend the commands for initialising the subMachine // parameters if ( paraminitcommands.size() > 0 ) { CommandComposite* comcom = new CommandComposite; for ( std::vector<ActionInterface*>::iterator i = paraminitcommands.begin(); i != paraminitcommands.end(); ++i ) comcom->add( *i ); // init the vars as last (if any), so that they can be inited by an expression containing the params : if ( curinstantiatedmachine->getInitCommand() ) comcom->add( curinstantiatedmachine->getInitCommand() ); curinstantiatedmachine->setInitCommand( comcom ); } paraminitcommands.clear(); curmachinebuilder = 0; curinstmachineparams.clear(); // set the TaskContext name to the instance name : curinstantiatedmachine->getService()->setName(curinstmachinename ); }