DiaDes  0.1
DIAgnosis of Discrete-Event System
ScenarioInfo.cc
Go to the documentation of this file.
1 
21 #include<vector>
22 #include<string>
23 #include<list>
24 #include<utils/Verbose.hh>
25 #include<utils/CmdInterface.hh>
26 #include<io/xml/automata/Simulation.hh>
27 
28 
29 using std::string;
30 using std::vector;
31 using namespace Diades::Utils;
32 using namespace Diades::Io::Xml;
33 
34 typedef enum { HELP = 0, EVENTS = 1, TIMEDEVENTS = 2,
36 
37 typedef enum { XML = 0 } Extension;
38 
39 unsigned numberOfOptions = 6;
41 
42 
44 vector<string> options(numberOfOptions);
45 vector<bool> isSet(numberOfOptions,false);
46 
47 string description= "Usage: dd-scenario-info --help |\n\t scenario.xml (--events | --timed_events | --observations | --timed_observations | --faults)\n\n\n\t Print on the standard output the information associated to the given option.";
48 
49 
51 {
52  options[HELP] = "--help";
53  options[EVENTS] = "--events";
54  options[TIMEDEVENTS] = "--timed_events";
55  options[OBSERVATIONS] = "--observations";
56  options[TIMEDOBSERVATIONS] = "--timed_observations";
57  options[FAULTS] = "--faults";
58  fileExtensions[XML] = "xml";
59 }
60 
72 int main(int argc, char ** argv)
73 {
76 
77  if(argc==1)
78  {
80  }
81  Option currentOption;
82  int index = 1;
83  if(argc==2)
84  {
85  if(getOption<Option>(argv[index],options,currentOption))
86  {
87  if(currentOption != HELP)
88  {
89  printError("Incorrect command line. Try --help.");
90  }
91  else
92  {
94  }
95  }
96  else
97  {
98  printError("Incorrect command line. Try --help.");
99  }
100  }
101  if(argc != 3)
102  {
103  printError("Incorrect number of paramters in command line. Try --help.");
104  }
105 
106 
107  string scnFile;
108 
109  if(!getOption<Option>(argv[index],options,currentOption))
110  {
111  // this should be the model file then
112  getParameter<string>(argc,argv,index,scnFile);
113  if(!fileSuffixOk(scnFile,fileExtensions[XML]))
114  {
115  printError("The scenario file'" + scnFile + "' is not a diades scenario file.");
116  }
117  }
118  else
119  {
120  ++index;
121  }
122 
123  if(!scnFile.empty())
124  {
125  // this should be an option here
126  if(!getOption<Option>(argv[index],options,currentOption))
127  {
128  printError("Unrecognized option: " + string(argv[index]));
129  }
130  }
131  else
132  {
133  // this should be the model file then
134  getParameter<string>(argc,argv,index,scnFile);
135  if(!fileSuffixOk(scnFile,fileExtensions[XML]))
136  {
137  printError("The scenario file '" + scnFile + "' is not a diades scenario file.");
138  }
139  }
140 
141  std::list< pair< boost::posix_time::time_duration,Diades::Automata::Event> > timedSimulation2;
142  std::list< pair< boost::posix_time::time_duration,Diades::Automata::Event> > observableTimedSimulation2;
143  std::list< Diades::Automata::Event > faults2;
144  loadXmlSimulation(scnFile,
145  std::back_insert_iterator< std::list< Diades::Automata::Event> >(faults2),
146  std::back_insert_iterator< std::list< pair< boost::posix_time::time_duration,Diades::Automata::Event> > >(timedSimulation2),
147  std::back_insert_iterator< std::list< pair< boost::posix_time::time_duration,Diades::Automata::Event> > >(observableTimedSimulation2));
148  switch(currentOption)
149  {
150  case HELP:
151  {
152  printError("Incorrect use of option --help.");
153  break;
154  }
155  case EVENTS:
156  {
157  for(const pair< boost::posix_time::time_duration,Diades::Automata::Event> & p : timedSimulation2)
158  {
159  std::cout << p.second << " ";
160  }
161  break;
162  }
163  case TIMEDEVENTS:
164  {
165  for(const pair< boost::posix_time::time_duration,Diades::Automata::Event> & p : timedSimulation2)
166  {
167  std::cout << p.first << " " << p.second << " ";
168  }
169  break;
170  }
171  case OBSERVATIONS:
172  {
173  for(const pair< boost::posix_time::time_duration,Diades::Automata::Event> & p : observableTimedSimulation2)
174  {
175  std::cout << p.second << " ";
176  }
177  break;
178  }
179  case TIMEDOBSERVATIONS:
180  {
181  for(const pair< boost::posix_time::time_duration,Diades::Automata::Event> & p : observableTimedSimulation2)
182  {
183  std::cout << p.first << " " << p.second << " ";
184  }
185  break;
186  }
187  case FAULTS:
188  {
189  for(const Diades::Automata::Event & evt : faults2)
190  {
191  std::cout << evt << " ";
192  }
193  break;
194  }
195  default:
196  {
197  printError("Unrecognized option: " + string(argv[index]));
198  break;
199  }
200  }
201 }
202 
void setVerboseLevel(Diades::Utils::VerboseLevel level)
Definition: Verbose.hh:135
Extension
Definition: ScenarioInfo.cc:37
unsigned numberOfOptions
Definition: ScenarioInfo.cc:39
Option
Definition: ScenarioInfo.cc:34
Option
Definition: abstract.cc:32
bool fileSuffixOk(const string &modelFile, const string &suffix)
int main(int argc, char **argv)
Definition: ScenarioInfo.cc:72
void initialiseOptions()
Definition: ScenarioInfo.cc:50
vector< string > options(numberOfOptions)
void printError(string parameter, string message)
unsigned numberOfFileExtensions
Definition: ScenarioInfo.cc:40
vector< string > fileExtensions(numberOfFileExtensions)
vector< bool > isSet(numberOfOptions, false)
string description
Definition: ScenarioInfo.cc:47
void printUsage(const po::options_description &desc)