EventManager.cpp 1.24 KB
Newer Older
1 2 3 4
#include <cstdio>
#include <cstdlib> 
#include <iostream>
#include <string>
5
#include "EventManager.h"
6 7 8 9 10
#include "../tinyxml/tinyxml.h"
#include "../IO/OutputHandler.h"

using namespace std;

11 12 13 14 15 16 17 18
/*******************
 Konstruktoren
 ******************/

EventManager::EventManager(){
    _event_times=vector<int>();
    _event_values=vector<string>();
}
19

20
void readEventsXml(string eventfile){
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    Log->Write("INFO: \tLoading and parsing the event file <%s>",eventfile.c_str());

    TiXmlDocument doc(eventfile);
    if(!doc.LoadFile()){
	Log->Write("EROOR: \t%s",doc.ErrorDesc());
	Log->Write("ERROR: \t could not parse the event file");
	exit(EXIT_FAILURE);
    }

    TiXmlElement* xMainNdoe = doc.RootElement();
    if(!xMainNode){
	Log->Write("ERROR:\tRoot element does not exist.");
	exit(EXIT_FAILURE);
    }
    
    TiXmlNode* xEvents = xMainNode->FirstChild("JPScore");
    if(!xEvents){
	Log->Write("ERROR:\tNo events found.");
	exit(EXIT_FAILURE);
    }
    
    for(TiXmlElement* e = xEvents->FirstChildElement("event"); e; e= e->NextSiblingElement("event")){
43 44 45 46 47
	_event_times.push_back(atoi(e->Attribute("time")));
	string tmp=e->Attribute("type"))+"-");
	tmp=tmp+e->Attribute("id"))+"-";
	tmp=tmp+=e->Attribute("state"));
	_event_values.push_back(tmp);
48
    }
49
}