14 #include<boost/program_options.hpp> 21 #include"../AutomataInterface.hh" 29 namespace Poptions = boost::program_options;
37 const string program(
"dd-project");
53 Poptions::options_description & desc,
54 Poptions::variables_map & vm)
57 (
"help,h",
"produce help message")
58 (
"file,f", Poptions::value< string >(),
"automaton file (.aut/.ddaut format)")
59 (
"output,o", Poptions::value< string >(),
"outfile name (.aut/.ddaut format)")
60 (
"event,e", Poptions::value<std::vector< string > >(),
"a list of events to project")
61 (
"noevent,n", Poptions::value<std::vector< string > >(),
"a list of events not to project")
63 Poptions::positional_options_description p;
65 Poptions::store(Poptions::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
86 template<
typename FsmType,
90 std::vector<Event> & events,
91 std::vector<Event> & noevents,
92 std::vector<Event> & projectedEvents)
102 std::sort(noevents.begin(), noevents.end());
105 auto fsmEvents = fsm.events();
106 std::sort(fsmEvents.begin(), fsmEvents.end());
107 std::set_difference(fsmEvents.begin(), fsmEvents.end(), noevents.begin(), noevents.end(),
108 std::inserter(projectedEvents, projectedEvents.begin()));
113 auto fsmEvents = fsm.events();
114 std::sort(events.begin(), events.end());
115 std::sort(fsmEvents.begin(), fsmEvents.end());
116 std::set_intersection(fsmEvents.begin(), fsmEvents.end(), events.begin(), events.end(),
117 std::inserter(projectedEvents, projectedEvents.begin()));
119 std::vector<Event> intersection;
120 std::sort(noevents.begin(), noevents.end());
121 std::set_intersection(projectedEvents.begin(), projectedEvents.end(),
124 std::inserter(intersection, intersection.begin()));
125 if(!intersection.empty())
144 projectAut(
const std::string & fileName,
const std::string & output,
145 std::vector<std::string> & events,
146 std::vector<std::string> & noevents)
150 ifstream file(fileName.c_str());
166 std::vector<AutEventId> projectedEvents;
170 projectedEvents.begin(), projectedEvents.end());
174 return printCommandLineError(
Msg(
"Error when analysing the events/noevents to project, they are incompatible please check them \n are they BOTH empty? \n Is an event part of both sets? \n events are %1%,\n noevents are %2%")
175 %
toStream(events.begin(), events.end()) %
toStream(noevents.begin(), noevents.end()));
194 const std::vector<std::string> & events,
195 const std::vector<std::string> & noevents,
197 std::vector<DdAutEventId> & projectedEvents)
199 std::vector<DdAutEventId> eventIds;
200 std::vector<DdAutEventId> noeventIds;
201 std::for_each(events.begin(), events.end(),
202 [&](
const std::string & event)
206 eventIds.push_back(eManager.
eventId(event));
209 std::for_each(noevents.begin(), noevents.end(),
210 [&](
const std::string & event)
214 noeventIds.push_back(eManager.
eventId(event));
232 std::vector<std::string> & events,
233 std::vector<std::string> & noevents)
239 ifstream file(fileName.c_str());
260 return printCommandLineError(
Msg(
"Error when loading the 'ddaut descriptor of the finite automaton file %1%") % fileName);
264 std::vector<DdAutEventId> projectedEvents;
270 project(fa, projectedFA, sManager, sManagerProj, projectionLabels, projectedEvents.begin(), projectedEvents.end());
274 return printCommandLineError(
Msg(
"Error when analysing the events/noevents to project, they are incompatible please check them \n are they BOTH empty? \n Is an event part of both sets? \n events are %1%,\n noevents are %2%")
275 %
toStream(events.begin(), events.end()) %
toStream(noevents.begin(), noevents.end()));
285 return printCommandLineError(
Msg(
"Error when loading the 'ddaut descriptor of the finite state machine file %1%") % fileName);
288 std::vector<DdAutEventId> projectedEvents;
294 project(fsm, projectedFsm, sManager, sManagerProj, projectionLabels, projectedEvents.begin(), projectedEvents.end());
298 return printCommandLineError(
Msg(
"Error when analysing the events/noevents to project, they are incompatible please check them \n are they BOTH empty? \n Is an event part of both sets? \n events are %1%,\n noevents are %2%")
299 %
toStream(events.begin(), events.end()) %
toStream(noevents.begin(), noevents.end()));
316 projectFsm(
const std::string & fileName,
const std::string & output,
317 std::vector<std::string> & events,
318 std::vector<std::string> & noevents)
322 return printCommandLineError(
Msg(
"Expecting a filename but I did not get anything. Use dd-project --help for documentation."));
326 return projectAut(fileName, output, events, noevents);
332 return projectDdaut(fileName, output, events, noevents);
351 std::string fileName, output;
352 std::vector<std::string> events;
353 std::vector<std::string> noevents;
356 Poptions::options_description desc(
"Options");
357 Poptions::variables_map vm;
365 fileName = vm[
"file"].as<std::string>();
367 if(vm.count(
"output"))
369 output = vm[
"output"].as<std::string>();
371 if(vm.count(
"event"))
373 events = vm[
"event"].as<std::vector < std::string >> ();
375 if(vm.count(
"noevent"))
377 noevents = vm[
"noevent"].as<std::vector < std::string >> ();
380 catch(Poptions::required_option & e)
384 catch(Poptions::error & e)
388 return projectFsm(fileName, output, events, noevents);
size_t writeAut(const Diades::Automata::Experimental::AutFsm &fsm, const std::string &output, const FileSuffixes &suffixes)
StateMachine< AutStateId, AutEventId > AutFsm
bool hasEvent(const Event &event) const
StatePropertyManager< DdAutStateLabel, DdAutStateId > DdAutStateManager
ConstAcceptorIterator acceptorEnd() const
size_t writeFiniteAutomaton(const Diades::Automata::Experimental::ConstManagedDdAutFA &mfa, const std::string &output, const FileSuffixes &suffixes)
bool fsmFromDescriptor(const DdAutFileDescriptor &descriptor, DdAutFsm &fsm, DdAutStateManager &sManager, DdAutEventManager &eManager)
const size_t ERROR_UNHANDLED_EXCEPTION
size_t printCommandLineError(const string &msg)
bool faFromDescriptor(const DdAutFileDescriptor &descriptor, DdAutFA &fa, DdAutStateManager &sManager, DdAutEventManager &eManager)
ConstAcceptorIterator acceptorBegin() const
EventId eventId(const Event &event)
FileSuffixes suffixes({"aut", "ddaut"})
int main(int argc, char **argv)
data structure that gathers an Fsm, a StateManager and a EventManager
void project(const Trace &source, const set< Event::Id > &projectedEvents, Trace &target)
vector< string > options(numberOfOptions)
data structure that gathers an FA, a StateManager and a EventManager
bool match(const std::string &fileName, const std::string &suffix) const
DdAutFsm::EventPropertyId Event
void initialiseOptions(int argc, char *argv[], Poptions::options_description &desc, Poptions::variables_map &vm)
Diades::Utils::ToStream< InputIterator, Diades::Utils::AlwaysTrue< typename InputIterator::reference > > toStream(InputIterator first, InputIterator last)
bool getProjectedEvents(const FsmType &fsm, std::vector< Event > &events, std::vector< Event > &noevents, std::vector< Event > &projectedEvents)
size_t writeFiniteStateMachine(const Diades::Automata::Experimental::ConstManagedDdAutFsm &mfsm, const std::string &output, const FileSuffixes &suffixes)
size_t projectDdaut(const std::string &fileName, const std::string &output, std::vector< std::string > &events, std::vector< std::string > &noevents)
EventManager< DdAutEventLabel, DdAutEventId > DdAutEventManager
bool fromAutFile(std::istream &stream, AutFsm &fsm)
StateMachine< DdAutStateId, DdAutEventId > DdAutFsm
const string program("dd-project")
size_t projectFsm(const std::string &fileName, const std::string &output, std::vector< std::string > &events, std::vector< std::string > &noevents)
virtual bool readStream(std::istream &stream)
size_t projectAut(const std::string &fileName, const std::string &output, std::vector< std::string > &events, std::vector< std::string > &noevents)
void printUsage(const po::options_description &desc)