14 #include<unordered_map> 15 #include<boost/program_options.hpp> 23 #include"../AutomataInterface.hh" 30 namespace Poptions = boost::program_options;
54 Poptions::options_description & desc,
55 Poptions::variables_map & vm)
58 (
"help,h",
"produce help message")
59 (
"file,f", Poptions::value< string >(),
"automaton file (.aut/.ddaut format)");
60 Poptions::positional_options_description p;
62 Poptions::store(Poptions::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
74 using Path = std::vector<std::pair<State,Transition> >;
75 using TrIndexes = std::unordered_map<size_t,Transition>;
76 using StIndexes = std::unordered_map<State::NodeId,State>;
77 using Params = std::vector<std::string>;
94 std::unordered_map<Command, std::string>
cmds =
124 std::unordered_map<Command, std::string>
cmdHelp =
128 'back input-transition-id': fire the input transition with the 129 id '[input-transition-id]' from the 130 current state (check the command 'current') 131 So here we move backward but we keep the path 132 updated (it is not undo, check the command 'undo'))"}, 135 'command' : display the list of available commands in dd-run. 139 'current' : display the current state of the fsm. 140 If such a current state does not exist 145 'help' : print this message 146 'help cmd' : print help message for the command 'cmd' 148 To list the possible set of commands, use 'commands'.)" 153 'initial' : display the set of initial states of the fsm.)" 157 'next output-transition-id': fire the output transition with the 158 id '[output-transition-id]' from the 159 current state (check the command 'current'))" 163 'path': display the current path)" 167 'start state-id' : set the current state of the fsm to be the one 168 with the corresponding state-id. Erase the current 172 'quit' : quit dd-run.)" 176 'undo' : undo the last transition fire (back/next) 177 The current path is updated.)" 180 R"(unknown command: check the command list with 'commands')" 187 std::cout << cmdHelp[cmd] <<
"\n";
193 auto it = textTocmds.find(cmd);
194 if(it == textTocmds.end())
210 size_t runAut(
const std::string & fileName)
213 ifstream file(fileName.c_str());
234 std::cout <<
"dd-run: ";
236 std::getline(std::cin, cmd);
246 std::stringstream stream;
258 params.push_back(param);
293 std::cout <<
" [" << index <<
"]:" << states[transition.source().id()] <<
"-->" << states[transition.target().id()] <<
" " 310 transitions[transitions.size()]=transition;
326 transitions[transitions.size()]=transition;
338 std::cout <<
"outputs:\n";
340 std::cout <<
"inputs:\n";
347 if(params.size() != 0)
349 std::cout <<
"error: I read initial with some parameters\n";
364 std::regex regStateId(
"[[:digit:]]+");
366 if(std::regex_match(param,regStateId))
368 std::stringstream stream;
380 size_t getId(
const std::string & param,
bool & ok)
382 std::regex regStateId(
"[[:digit:]]+");
384 if(std::regex_match(param,regStateId))
386 std::stringstream stream;
406 if(params.size() != 1)
408 std::cout <<
"error: here I read start with " << params.size() <<
" parameters (should be 1)'\n";
418 auto it = states.find(stateId);
421 std::cout <<
"error: the state of id=" << stateId <<
" does not exists.\n";
425 newInitialState = it->second;
431 std::cout <<
"error: here I read 'start " << params[0] <<
"'\n";
445 if(params.size() != 1)
447 std::cout <<
"error: here I read next with " << params.size() <<
" parameters (should be 1)'\n";
453 auto transId =
getId(params[0],ok);
458 auto it = outputs.find(transId);
459 if(it==outputs.end())
461 std::cout <<
"error: the transition of id=" << transId <<
" does not exists.\n";
465 currentPath.push_back(std::make_pair(it->second.target(),it->second));
466 printCurrentState(fsm,currentPath.back().first,sManager,eManager,outputs, inputs);
471 std::cout <<
"error: here I read 'next " << params[0] <<
"'\n";
487 if(params.size() != 1)
489 std::cout <<
"error: here I read back with " << params.size() <<
" parameters (should be 1)'\n";
495 auto transId =
getId(params[0],ok);
500 auto it = inputs.find(transId);
503 std::cout <<
"error: the input transition of id=" << transId <<
" does not exists.\n";
507 currentPath.push_back(std::make_pair(it->second.source(),it->second));
508 printCurrentState(fsm,currentPath.back().first,sManager,eManager,outputs, inputs);
513 std::cout <<
"error: here I read 'back " << params[0] <<
"'\n";
523 if(params.empty() || (params.size() > 1))
535 std::cout <<
"List of available commands: ";
536 if(!textTocmds.empty())
538 auto it = textTocmds.begin();
539 while(it!=textTocmds.end())
543 std::cout << it->first <<
" ";
571 eManager,outputs,inputs,params);
582 if(currentPath.empty())
584 std::cout <<
"No current state\n";
589 sManager,eManager,outputs,inputs);
610 std::cout <<
"error: I read the command 'undo' with some parameters.\n";
615 if(!currentPath.empty())
617 currentPath.pop_back();
618 if(currentPath.empty())
620 std::cout <<
"Empty path, no initial state.\n";
626 printCurrentState(fsm,currentPath.back().first,sManager,eManager,outputs, inputs);
633 const Path & currentPath,
640 std::cout <<
"error: I read 'path' with parameters.\n";
645 if(currentPath.empty())
647 std::cout <<
"empty path.\n";
651 printState(fsm, currentPath.front().first,sManager);
652 auto it = currentPath.begin();
654 while (it!=currentPath.end())
658 if (it->second.source()==itPrev->first) {
659 std::cout <<
"\t|\n";
661 std::cout <<
"\t|\n";
662 std::cout <<
"\tv\n";
667 std::cout <<
"\t^\n";
668 std::cout <<
"\t|\n";
670 std::cout <<
"\t|\n";
682 std::cout <<
"Unknown command: use 'commands' to print the list of commands.\n";
758 commandUndo(fsm,currentPath,sManager,eManager,outputs,inputs,params);
787 ifstream file(fileName.c_str());
805 return printCommandLineError(
Msg(
"Error when converting the DdAutFileDescriptor from %1% to a Finite State Machine")%fileName);
807 std::cout <<
"Diades automaton explorer, LAAS-CNRS, Univ. Toulouse, France\n";
808 std::cout <<
"\nIf you don't know how to use it, type 'help' unless you just\n want to quit then type 'quit'.\n";
819 size_t runFsm(
const std::string & fileName)
849 int main(
int argc,
char** argv)
851 std::string fileName, output;
854 Poptions::options_description desc(
"Options");
855 Poptions::variables_map vm;
863 fileName = vm[
"file"].as<std::string>();
866 catch(Poptions::required_option & e)
870 catch(Poptions::error & e)
std::unordered_map< Command, std::string > cmdHelp
void printState(const DdAutFsm &fsm, const State &state, const DdAutStateManager &sManager)
void initialiseStates(const DdAutFsm &fsm)
size_t runFsm(const std::string &fileName)
void printCurrentState(const DdAutFsm &fsm, const State &state, const DdAutStateManager &sManager, const DdAutEventManager &eManager, TrIndexes &outputs, TrIndexes &inputs)
void commandStart(const DdAutFsm &fsm, Path ¤tPath, const DdAutStateManager &sManager, const DdAutEventManager &eManager, TrIndexes &outputs, TrIndexes &inputs, const Params ¶ms)
void commandUndo(const DdAutFsm &fsm, Path ¤tPath, const DdAutStateManager &sManager, const DdAutEventManager &eManager, TrIndexes &outputs, TrIndexes &inputs, const Params ¶ms)
StateMachine< AutStateId, AutEventId > AutFsm
size_t getId(const std::string ¶m, bool &ok)
StatePropertyManager< DdAutStateLabel, DdAutStateId > DdAutStateManager
Diades::Graph::Edge Transition
bool fsmFromDescriptor(const DdAutFileDescriptor &descriptor, DdAutFsm &fsm, DdAutStateManager &sManager, DdAutEventManager &eManager)
const size_t ERROR_UNHANDLED_EXCEPTION
size_t printCommandLineError(const string &msg)
std::map< std::string, Command > textTocmds
size_t runAut(const std::string &fileName)
void commandInitial(const DdAutFsm &fsm, const DdAutStateManager &sManager, const Params ¶ms)
void printTransition(const DdAutFsm &fsm, const Transition &transition, const DdAutEventManager &eManager, size_t index)
void printInitialStates(const DdAutFsm &fsm, const DdAutStateManager &sManager, const Params ¶ms)
vector< string > options(numberOfOptions)
size_t runDdaut(const std::string &fileName)
void printInputTransitions(const DdAutFsm &fsm, const State &state, const DdAutEventManager &eManager, TrIndexes &transitions)
Diades::Graph::Node State
OutputTransitionIterator outputTransitionBegin(State s) const
InitialStateIterator initialStateEnd() const
void commandPath(const DdAutFsm &fsm, const Path ¤tPath, const DdAutStateManager &sManager, const DdAutEventManager &eManager, const Params ¶ms)
size_t interactiveDdAut(const DdAutFsm &fsm, const DdAutStateManager &sManager, const DdAutEventManager &eManager)
StateIterator stateEnd() const
InputTransitionIterator inputTransitionBegin(State s) const
std::vector< std::pair< State, Transition > > Path
int main(int argc, char **argv)
bool match(const std::string &fileName, const std::string &suffix) const
AutFsm::Transition Transition
FileSuffixes suffixes({"aut","ddaut"})
const EventPropertyId & getEvent(Transition t) const
void printOutputTransitions(const DdAutFsm &fsm, const State &state, const DdAutEventManager &eManager, TrIndexes &transitions)
void commandCurrent(const DdAutFsm &fsm, Path ¤tPath, const DdAutStateManager &sManager, const DdAutEventManager &eManager, TrIndexes &outputs, TrIndexes &inputs)
void commandNext(const DdAutFsm &fsm, Path ¤tPath, const DdAutStateManager &sManager, const DdAutEventManager &eManager, TrIndexes &outputs, TrIndexes &inputs, const Params ¶ms)
const Event & getEvent(EventId id) const
void printHelpCommand(Command cmd)
void prompt(std::string &cmd)
void command(Command &cmd, Params ¶ms)
OutputTransitionIterator outputTransitionEnd(State s) const
InputTransitionIterator inputTransitionEnd(State s) const
std::vector< std::string > Params
State::NodeId getStateId(const std::string ¶m, bool &ok)
InitialStateIterator initialStateBegin() const
Command convertCommand(const std::string &cmd)
EventManager< DdAutEventLabel, DdAutEventId > DdAutEventManager
StateIterator stateBegin() const
void initialiseFsm(const DdAutFsm &fsm, DdAutFsm::State &newInitialState, const DdAutStateManager &sManager, const DdAutEventManager &eManager, TrIndexes &outputs, TrIndexes &inputs, const Params ¶ms)
bool fromAutFile(std::istream &stream, AutFsm &fsm)
const string program("dd-run")
StateMachine< DdAutStateId, DdAutEventId > DdAutFsm
void commandBack(const DdAutFsm &fsm, Path ¤tPath, const DdAutStateManager &sManager, const DdAutEventManager &eManager, TrIndexes &outputs, TrIndexes &inputs, const Params ¶ms)
void initialiseOptions(int argc, char *argv[], Poptions::options_description &desc, Poptions::variables_map &vm)
std::unordered_map< State::NodeId, State > StIndexes
const StatePropertyId & getStatePropertyId(State state) const
void printHelp(const Params ¶ms)
const StateProperty & getStateProperty(StatePropertyId id) const
std::unordered_map< size_t, Transition > TrIndexes
std::unordered_map< Command, std::string > cmds
void commandHelp(const Params ¶ms)
virtual bool readStream(std::istream &stream)
void printUsage(const po::options_description &desc)