-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigLoader.hh
More file actions
136 lines (103 loc) · 2.58 KB
/
ConfigLoader.hh
File metadata and controls
136 lines (103 loc) · 2.58 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef GZBRIDGE_CONFIG_LOADER_HH_
#define GZBRIDGE_CONFIG_LOADER_HH_
#include <map>
#include <vector>
#include <cassert>
#include <string>
#include <iostream>
namespace gzweb
{
class ConfigNode;
class ConfigLoader
{
public:
static void loadAllFiles(ConfigLoader* c, const std::string& path);
ConfigLoader(const std::string& fileEnding);
virtual ~ConfigLoader();
std::string m_fileEnding;
// For a line like
// entity animals/dog
// {
// ...
// }
// The type is "entity" and the name is "animals/dog"
// Or if animal/dog was not there then name is ""
virtual ConfigNode *getConfigScript (const std::string &name);
virtual std::map <std::string, ConfigNode*> getAllConfigScripts ();
virtual void parseScript(std::ifstream &stream);
protected:
float m_LoadOrder;
// like "*.object"
std::map <std::string, ConfigNode*> m_scriptList;
enum Token
{
TOKEN_Text,
TOKEN_NewLine,
TOKEN_OpenBrace,
TOKEN_CloseBrace,
TOKEN_EOF,
};
Token tok, lastTok;
std::string tokVal, lastTokVal;
void _parseNodes(std::ifstream &stream, ConfigNode *parent);
void _nextToken(std::ifstream &stream);
void _skipNewLines(std::ifstream &stream);
virtual void clearScriptList();
};
class ConfigNode
{
public:
ConfigNode(ConfigNode *parent, const std::string &name = "untitled");
~ConfigNode();
inline void setName(const std::string &name)
{
this->m_name = name;
}
inline std::string &getName()
{
return m_name;
}
inline void addValue(const std::string &value)
{
m_values.push_back(value);
}
inline void clearValues()
{
m_values.clear();
}
inline std::vector<std::string> &getValues()
{
return m_values;
}
inline const std::string &getValue(unsigned int index = 0)
{
assert(index < m_values.size());
return m_values[index];
}
ConfigNode *addChild(const std::string &name = "untitled", bool replaceExisting = false);
ConfigNode *findChild(const std::string &name, bool recursive = false);
inline std::vector<ConfigNode*> &getChildren()
{
return m_children;
}
inline ConfigNode *getChild(unsigned int index = 0)
{
assert(index < m_children.size());
return m_children[index];
}
void setParent(ConfigNode *newParent);
inline ConfigNode *getParent()
{
return m_parent;
}
private:
std::string m_name;
std::vector<std::string> m_values;
std::vector<ConfigNode*> m_children;
ConfigNode *m_parent;
int m_lastChildFound; //The last child node's index found with a call to findChild()
std::vector<ConfigNode*>::iterator _iter;
bool _removeSelf;
};
}
#endif