Blame view

src/TimeTableCatalog/XMLReader.hh 1.81 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * XMLReader.hh
 *
 *  Created on: 7 août 2013
 *      Author: CS
 */

#ifndef XMLREADER_HH_
#define XMLREADER_HH_

#include "AbstractReader.hh"
#include <libxml/xmlreader.h>

namespace TimeTableCatalog {

class XMLReader: public TimeTableCatalog::AbstractReader {
public:
	XMLReader(const std::string& pPath);
	virtual ~XMLReader();

	/**
	 * Reads an XML file
	 */
	void read(TimeTable& pTT);

	/**
	 * Checks the XML tt reader is the right one. Returns false if
	 * the tt XML format is not the expected format.
	 */
	bool canRead(const std::string& pPath);

protected:

	/**
	 * Parses an XML file
	 */
	void parse(TimeTable& pTT);

	/**
	 * Processes each interested node of an XMl file.
	 */
	virtual void processNode(TimeTable& pTT, xmlTextReaderPtr reader, int &crtIndex) = 0;

	/**
	 * Checks one of the pMaxTagToRead first nodes is named pNode.
	 * Calls containsNode(xmlTextReaderPtr reader, std::string& pNode).
	 */
	bool containsNode(const std::string& pPath, std::string pNode,
			int pMaxTagToRead = 5);

	/**
	 * Processes a node and returns true if the currently processed
	 * node is nammed pNode.
	 */
	bool containsNode(xmlTextReaderPtr reader, std::string& pNode);

	/**
	 * Gets the xml expected first node name (except xml tag).
	 */
	virtual std::string getFirstNode() = 0;

	/**
	 * Steps during read : the reader first reads a start tag,
	 * then reads the tag value and then reads the end tag.
	 */
	enum READ_STEP {
		NO_TAG = 0, START_TAG = 1, TEXT = 2, END_TAG = 3
	};

	/**
	 * The previous start date of an interval, to create an interval
	 * when the stop date is read.
	 */
	double _tmpIntervalstartdate;

	/**
	 * The current tag (set when step is START_TAG).
	 */
	std::string _tmpCurrentTag;

	/**
	 * The current step.
	 */
	READ_STEP _step;
};

} /* namespace TimeTableCatalog */
#endif /* XMLREADER_HH_ */