15 #include<boost/program_options.hpp> 20 #include"../AutomataInterface.hh" 28 namespace Poptions = boost::program_options;
36 const string program(
"dd-ts2ddaut");
37 const string briefcomment(
": this program converts a '.ts' altarica format file to a '.ddaut' file (output file or standard output).");
52 Poptions::options_description & desc,
53 Poptions::variables_map & vm)
56 (
"help,h",
"produce help message")
57 (
"file,f", Poptions::value< string >(),
"file (.ts format)")
58 (
"output,o", Poptions::value< string >(),
"outfile name (.ddaut format)")
59 (
"dict,d", Poptions::value< string >(),
"conversion into more human-friendly manner associated with a dictionary")
60 (
"mealy,m",
"full conversion as a Mealy machine (target state content in the event)")
61 (
"update,u",
"conversion as a Mealy machine (the event contains state updates)")
62 (
"components,c",
"write ddaut components (globally consistent behaviours) extracted from the ts file if the ts file describes a synchronised system")
64 Poptions::positional_options_description p;
67 Poptions::store(Poptions::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
80 for(
size_t i = 1; i < fsms.size(); ++i)
85 std::tie(fsm,sManager,eManager) = fsms.at(i);
86 if(fsm->name().empty())
88 fsm->setName(
"_global_system");
90 std::string fileName = fsm->name() +
".ddaut";
91 ofstream out(fileName.c_str());
111 exportTsToDdAut2(
const std::string & fileName,
const std::string & output,
const std::string & dict,
115 ifstream file(fileName.c_str());
132 std::tie(fsm,sManager,eManager) = fsms.at(0);
139 for(
const auto & stateProperty : sManager->storage())
141 std::stringstream stream;
142 stream << sManager->statePropertyId(stateProperty);
145 sPrettyManager.
setStateProperty(idString, sManager->statePropertyId(stateProperty));
148 for(
const auto & event : eManager->storage())
152 ofstream out(dict.c_str());
156 for(
const auto & stateProperty : sManager->storage())
158 out << sPrettyManager.
getStateProperty( sManager->statePropertyId(stateProperty))
164 for(
const auto & eventProperty : eManager->storage())
166 out << ePrettyManager.
getEvent(eManager->eventId(eventProperty))
175 auto saved =
fsmToDdAutFile(std::cout,{*fsm,sPrettyManager,ePrettyManager});
183 ofstream out2(output.c_str());
186 auto saved =
fsmToDdAutFile(out2,{*fsm,sPrettyManager,ePrettyManager});
203 auto saved =
fsmToDdAutFile(std::cout,{*fsm,*sManager,*eManager});
211 ofstream out(output.c_str());
237 bool writeComponents)
244 return printCommandLineError(
Msg(
"Expecting an output file with a name ending with .ddaut, but I read %1%") % output);
268 std::string fileName, output, dict;
269 bool writeComponents =
false;
273 Poptions::options_description desc(
"Options");
274 Poptions::variables_map vm;
282 fileName = vm[
"file"].as<std::string> ();
284 if(vm.count(
"output"))
286 output = vm[
"output"].as<std::string>();
290 dict = vm[
"dict"].as<std::string>();
292 if(vm.count(
"components"))
294 writeComponents =
true;
297 if(vm.count(
"mealy") && !(vm.count(
"update")))
301 if(vm.count(
"update") && !(vm.count(
"mealy")))
305 if(vm.count(
"update") && vm.count(
"full"))
310 catch(Poptions::required_option & e)
314 catch(Poptions::error & e)
size_t writeDdAutComponents(ManagedTsFsms &fsms)
StatePropertyManager< DdAutStateLabel, DdAutStateId > DdAutStateManager
const size_t ERROR_UNHANDLED_EXCEPTION
bool setStateProperty(const StateProperty &stateProperty, StatePropertyId id)
size_t printCommandLineError(const string &msg)
int main(int argc, char **argv)
size_t exportTsToDdAut(const string &fileName, const string &output, const string &dict, TsConversionMode mode, bool writeComponents)
size_t exportTsToDdAut2(const std::string &fileName, const std::string &output, const std::string &dict, TsConversionMode mode, bool writeComponents)
vector< string > options(numberOfOptions)
bool setEvent(const Event &event, EventId id)
const string program("dd-ts2ddaut")
bool match(const std::string &fileName, const std::string &suffix) const
bool fromTsFile(std::istream &stream, ManagedTsFsms &fsms, TsConversionMode mode)
Load a Ts file as a DdAutFsm.
const Event & getEvent(EventId id) const
bool fsmToDdAutFile(ostream &stream, const ConstManagedDdAutFsm &mFsm)
const string briefcomment(": this program converts a '.ts' altarica format file to a '.ddaut' file (output file or standard output).")
std::shared_ptr< TsStMgr > TsStMgrPtr
EventManager< DdAutEventLabel, DdAutEventId > DdAutEventManager
FileSuffixes suffixes({"ts", "ddaut"})
std::vector< ManagedTsFsm > ManagedTsFsms
std::shared_ptr< TsEvtMgr > TsEvtMgrPtr
StateMachine< DdAutStateId, DdAutEventId > DdAutFsm
const StateProperty & getStateProperty(StatePropertyId id) const
std::shared_ptr< TsFsm > TsFsmPtr
void initialiseOptions(int argc, char *argv[], Poptions::options_description &desc, Poptions::variables_map &vm)
std::string tsPrettyEvent(const std::string &tsEvent)
void printUsage(const po::options_description &desc)