RTC Toolkit 5.0.0
Loading...
Searching...
No Matches
modelBuilderBase.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_MODELBUILDERBASE_HPP
14#define RTCTK_COMPONENTFRAMEWORK_MODELBUILDERBASE_HPP
15
21
22#include <fstream>
23#include <iostream>
24#include <map>
25#include <tuple>
26#include <vector>
27
29
36public:
38 : sm("StateMachine"), mm(sm), m_engine(engine) {
39 }
40
41 virtual ~ModelBuilderBase() = default;
42
44 auto& logger = GetLogger("rtctk");
45 LOG4CPLUS_DEBUG(logger, "StateMachine.DEBUG\n" + Export(sm, "debug").str());
46 LOG4CPLUS_DEBUG(logger, "StateMachine.SCXML\n" + Export(sm, "scxml").str());
47
48 // TODO: validate model
49
50 m_engine.RegisterModel("model", Export(sm, "scxml").str());
51 }
52
53 void ExportModel(const std::string& file_name) {
54 auto ends_with = [](const std::string& value, const std::string& ending) {
55 if (ending.size() > value.size()) {
56 return false;
57 }
58 return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
59 };
60
61 if (ends_with(file_name, "scxml")) {
62 std::ofstream out(file_name);
63 out << Export(sm, "scxml").str();
64 } else if (ends_with(file_name, "puml")) {
65 std::ofstream out(file_name);
66 out << Export(sm, "puml").str();
67 } else if (ends_with(file_name, "smcat")) {
68 std::ofstream out(file_name);
69 out << Export(sm, "smcat").str();
70 } else if (ends_with(file_name, "debug")) {
71 std::ofstream out(file_name);
72 out << Export(sm, "debug").str();
73 } else {
74 CII_THROW(RtctkException, "Unsupported export format: '" + file_name + "'");
75 }
76 }
77
81};
82
83} // namespace rtctk::componentFramework
84
85#endif
Base class of the ModelBuilder.
Definition modelBuilderBase.hpp:35
ModelBuilderBase(StateMachineEngine &engine)
Definition modelBuilderBase.hpp:37
StateMachineEngine & m_engine
Definition modelBuilderBase.hpp:80
ModelManipulator mm
Definition modelBuilderBase.hpp:79
void RegisterModel()
Definition modelBuilderBase.hpp:43
void ExportModel(const std::string &file_name)
Definition modelBuilderBase.hpp:53
StateMachine sm
Definition modelBuilderBase.hpp:78
Class that provides methods to manipulate the state machine model.
Definition modelManipulator.hpp:27
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
Definition stateMachineEngine.hpp:35
void RegisterModel(const std::string &name, const std::string &model)
Register a new state machine model.
Definition stateMachineEngine.cpp:73
Logging Support Library based on log4cplus.
Export the state machine model in various formats.
Manipulate the in-memory state machine model.
In-memory representation of the state machine model.
Definition commandReplier.cpp:22
log4cplus::Logger & GetLogger(const std::string &name="app")
Get handle to a specific logger.
Definition logger.cpp:193
std::stringstream Export(StateMachine &sm, const std::string &format)
Export the in-memory state machine model in various formats.
Definition modelExport.cpp:582
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Wrapper around the SCXML State Machine Engine.