4 #include <boost/property_tree/ptree.hpp> 5 #include <boost/property_tree/xml_parser.hpp> 6 #include <boost/foreach.hpp> 7 #include <utils/CmdInterface.hh> 27 string description=
"Usage: dd-convert-supremica [--help | automaton.xml] \n\t Print the component described in the xml file (export of supremica) in the 'des_comp' format.";
43 int main(
int argc,
char * argv[])
54 unsigned numberOfObservables = 0;
56 string nonObservables;
57 unsigned numberOfNonObservables = 0;
59 unsigned stateNumber = 0;
63 unsigned transNumber = 0;
66 using boost::property_tree::ptree;
68 read_xml(filename,pt);
70 map<unsigned,string> mapStates;
71 map<unsigned,string> mapEvents;
75 BOOST_FOREACH(ptree::value_type
const& v, pt.get_child(
"Automata"))
77 if(v.first ==
"<xmlattr>")
83 if(v.first ==
"Automaton")
85 BOOST_FOREACH(ptree::value_type
const& v2, v.second.get_child(
""))
88 if(v2.first ==
"<xmlattr>")
90 std::cout << v2.second.get<std::string>(
"name") << std::endl;
94 if(v2.first ==
"Events")
96 BOOST_FOREACH(ptree::value_type
const& evt, v2.second.get_child(
""))
98 BOOST_FOREACH(ptree::value_type
const& evtAttr, evt.second.get_child(
""))
102 if(evtAttr.second.count(
"observable") != 0)
104 if( evtAttr.second.get<
bool>(
"observable") )
106 observables +=
"o" + evtAttr.second.get<std::string>(
"id") +
" ";
107 mapEvents[evtAttr.second.get<
unsigned>(
"id")] =
"o" + evtAttr.second.get<std::string>(
"id");
108 ++numberOfObservables;
112 nonObservables +=
"u" + evtAttr.second.get<std::string>(
"id") +
" ";
113 mapEvents[evtAttr.second.get<
unsigned>(
"id")] =
"u" + evtAttr.second.get<std::string>(
"id");
114 ++numberOfNonObservables;
121 observables +=
"o" + evtAttr.second.get<std::string>(
"id") +
" ";
122 mapEvents[evtAttr.second.get<
unsigned>(
"id")] =
"o" + evtAttr.second.get<std::string>(
"id");
123 ++numberOfObservables;
126 if(evtAttr.second.count(
"controllable") != 0)
140 if(v2.first ==
"States")
142 BOOST_FOREACH(ptree::value_type
const& state, v2.second.get_child(
""))
145 BOOST_FOREACH(ptree::value_type
const& stateAttr, state.second.get_child(
""))
148 mapStates[stateAttr.second.get<
unsigned>(
"id")] =
"q" + stateAttr.second.get<
string>(
"id");
159 if(stateAttr.second.count(
"initial") != 0)
161 if(stateAttr.second.get<
bool>(
"initial"))
163 initialState =
"q" + stateAttr.second.get<std::string>(
"id");
167 otherStates +=
"q" + stateAttr.second.get<std::string>(
"id") +
" ";
174 otherStates +=
"q" + stateAttr.second.get<std::string>(
"id") +
" ";
180 if(v2.first ==
"Transitions")
182 BOOST_FOREACH(ptree::value_type
const& transition, v2.second.get_child(
""))
185 BOOST_FOREACH(ptree::value_type
const& transAttr, transition.second.get_child(
""))
188 transitions += mapStates[transAttr.second.get<
unsigned>(
"source")] +
" -> " + mapStates[transAttr.second.get<
unsigned>(
"dest")] +
" " + mapEvents[transAttr.second.get<
unsigned>(
"event")] +
"\n";
202 std::cout << stateNumber << std::endl;
203 std::cout << initialState <<
" " << otherStates << std::endl;
204 std::cout << 0 << std::endl;
205 std::cout << numberOfNonObservables << std::endl;
206 std::cout << nonObservables << std::endl;
207 std::cout << 0 << std::endl;
208 std::cout << numberOfObservables << std::endl;
209 std::cout << observables << std::endl;
210 std::cout << transNumber << std::endl;
211 std::cout << transitions << std::endl;
217 list<string> modelFiles;
225 while( index < argc )
228 if(getOption<Option>(argv[index],
options,currentOption))
230 if(
isSet[currentOption])
232 printError(
"The option '" +
options[currentOption] +
"' occurs at least twice.");
237 isSet[currentOption] =
true;
239 switch(currentOption)
252 vector<string>::const_iterator it =
256 printError(
"Unrecognized file extension in file name: " +
string(argv[index]));
264 modelFiles.push_back(
string(argv[index]));
271 if(modelFiles.size() >1)
273 printError(
"Too many xml files, one only is allowed");
276 if(modelFiles.size() == 0)
278 printError(
"No xml files, one only is mandatory");
281 filename = modelFiles.front();
InputIterator getFileExtension(const std::basic_string< CharType, CharTraits > &fileName, InputIterator begin, InputIterator end)
void printError(string parameter, string message)
void printUsage(const po::options_description &desc)