CSEngine
Loading...
Searching...
No Matches
XML.h
1#pragma once
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6
7#include <string>
8#include <vector>
9
10#define XML_EOF 0
11#define XML_NODE 1
12#define XML_VALUE 2
13
14class XValue : public std::string {
15public:
16 XValue();
17
18 XValue(const std::string& str);
19
20 XValue& operator=(const std::string& str);
21
22 std::vector<float> toFloatVector() const;
23
24 std::vector<int> toIntegerVector() const;
25
26 std::vector<std::string> toStringVector() const;
27};
28
29class XAttrib {
30public:
31 std::string name;
32 std::string value;
33
34 XAttrib();
35
36 XAttrib(const std::string& str);
37
38 XAttrib(const char* _name, const char* _value);
39
40 std::string toString() const;
41};
42
43class XNode {
44private:
45 const XNode* _getNode(const char* node_name) const;
46
47 const XNode* _getNodeByAttribute(const char* node_name, const char* attrib_name, const char* attrib_value) const;
48
49public:
50 XNode* parent;
51
52 std::string name;
53 XValue value;
54 std::string raw;
55 std::vector<XAttrib> attributes;
56 std::vector<XNode> children;
57
58 int sub_index = -1;
59
60 XNode();
61
62 void print() const; // print the string representation in the format: name: value ...attributes...
63 const XNode& getNode(const char* name) const;
64
65 const XNode& getChild(const char* name) const;
66
67 bool hasChild(const char* name) const;
68
69 const XAttrib& getAttribute(const char* name) const;
70
71 bool hasAttribute(const char* name) const;
72
73 const XNode& getNodeByAttribute(const char* node_name, const char* attrib_name, const char* attrib_value) const;
74 bool hasNodeByAttribute(const char* node_name, const char* attrib_name, const char* attrib_value) const;
75};
76
77class XFILE {
78private:
79// FILE* file; // the file being read
80 std::string file;
81 int file_index = 0;
82
83 int read(std::string& buffer);
84
85
86public:
87 XFILE(){}
88 XFILE(const char* str); // read the file into the node heirchy
89 const XNode* getRoot();
90 const XNode* loadBuffer(std::string buffer);
91
92 ~XFILE();
93};
Definition XML.h:29
Definition XML.h:77
Definition XML.h:43
Definition XML.h:14