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