diff --git a/ctx_aut.cc b/ctx_aut.cc new file mode 100644 index 0000000..0f2b9fd --- /dev/null +++ b/ctx_aut.cc @@ -0,0 +1,63 @@ + +#include "ctx_aut.hh" + +bool CtxAut::hasState(std::string name) +{ + if (states_names.find(name) == states_names.end()) + return false; + else + return true; +} + +State CtxAut::getStateID(std::string name) +{ + if (!hasState(name)) + { + FERROR("No such state: " << name); + } + return states_names[name]; +} + +void CtxAut::addState(std::string name) +{ + if (!hasState(name)) + { + State new_state_id = states_ids.size(); + + VERB_L2("Adding state: " << name << " index=" << new_state_id); + + states_ids.push_back(name); + states_names[name] = new_state_id; + } +} + +void CtxAut::printAutomaton(void) +{ + showStates(); +} + +void CtxAut::showStates(void) +{ + cout << "# Context Automaton States:" << endl; + for (const auto &s : states_ids) + cout << " * " << s << endl; +} + +void CtxAut::pushContextEntity(Entity entity_id) +{ + tmpEntities.insert(entity_id); +} + +void CtxAut::addTransition(std::string srcStateName, std::string dstStateName) +{ + VERB_L3("Saving transition"); + + Transition new_transition; + + new_transition.src_state = getStateID(srcStateName); + new_transition.ctx = tmpEntities; + tmpEntities.clear(); + new_transition.dst_state = getStateID(dstStateName); +} + +/** EOF **/ diff --git a/ctx_aut.hh b/ctx_aut.hh new file mode 100644 index 0000000..b9b9568 --- /dev/null +++ b/ctx_aut.hh @@ -0,0 +1,45 @@ +/* + Copyright (c) 2018 + Artur Meski + + Reuse of the code or its part for any purpose + without the author's permission is strictly prohibited. +*/ + +#ifndef RS_CTX_AUT_HH +#define RS_CTX_AUT_HH + +#include +#include +#include +#include +#include +#include +#include "types.hh" +#include "macro.hh" +#include "options.hh" + +using std::cout; +using std::endl; + +class CtxAut +{ + public: + CtxAut(Options *opts) { setOptions(opts); } + bool hasState(std::string name); + void addState(std::string stateName); + State getStateID(std::string name); + void printAutomaton(void); + void showStates(void); + void addTransition(std::string srcStateName, std::string dstStateName); + void pushContextEntity(Entity entity_id); + void setOptions(Options *opts) { this->opts = opts; } + + private: + Options *opts; + StatesById states_ids; + StatesByName states_names; + Entities tmpEntities; +}; + +#endif /* RS_CTX_AUT_HH */