
//Option -g , for 'generate', provides the user with the bus from Warsaw to Ulan-Bator.
// - unpronouncable names
// - and driver is there only one time out of two

//allows you to verify that the 'save_XML' function works even without having created the object with load_XML.


#include<sample_classes_withXMLcode.h>

int main(int argc, char **argv)
{

  //******************* The -g option:
  bool generate=false;
  for (int k=0; k<argc; k++)
    if(!strcmp(argv[k],"-g"))
      generate=true;


  //******************* Bus creation :
  Bus theBus;		xmlParam::add_object(theBus, "bus");

  //Notice that any parameter can be added anywhere in the xml structure. Example:
  int a=5;	xmlParam::add_param_custom ( a , "value-of-a" , theBus.myself);
  //I mean, why not?


  //******************* Bus initialization procedure :


  xmlpp::DomParser parser;
  //parser.set_validate(); parser.set_substitute_entities(); //DUNNO HOW THIS WORKS...
  parser.parse_file("bus_definition.xml");
  xmlpp::Node* pNode = parser.get_document()->get_root_node();
  xmlParam::load ( theBus, pNode);

  if(generate)
  {
    cerr<<"Randomly generating the bus passengers"<<endl<<endl;
    //Then we forget about the bus we had just loaded, and generate a new one.
    srand( (unsigned)time( NULL ) );
    theBus.generate();
  }

  //********************* Bus action:

  theBus.everybody_say_Hi();

  //********************* Bus saving procedure :


  xmlpp::Document doc;
  xmlpp::Element* root=doc.create_root_node("bus-description-file");
  //doc.set_internal_subset("toto","tata",""); //HERE NEITHER...
  xmlParam::save ( theBus , root );
  doc.write_to_file_formatted("reconstructed-bus-file.xml");

  //********************* You must manually destroy the xml structure when you are through with it:
  //(of course, in this case it is useless since it is at the end of the program)

  xmlParam::delete_structure();

}






