-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigManager.h
70 lines (57 loc) · 1.63 KB
/
ConfigManager.h
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
#pragma once
#include <io.h>
#include "textfile.h"
#include <rapidxml.hpp>
#include <string>
#include <unordered_map>
#include "xmlHelper.h"
#include "Renderer.h"
using namespace std;
using namespace rapidxml;
class Renderer;
class ConfigManager
{
private:
string getFolder(const string& str) const
{
unsigned pos1 = str.rfind('/');
unsigned pos2 = str.rfind('\\');
unsigned pos = pos1 < pos2 ? pos1 : pos2;
if(pos < str.size())
return str.substr(0, pos);
return "";
}
string rootFolder;
string currentPath;
unordered_map<string, pair<xml_document<>*, char*>> path_doc;
Renderer* renderer;
xml_node<>* findNode(const string& filePath, const string& nodeTag, const string& nodeName);
xml_node<>* findNode(xml_node<>* root, const string& nodeTag, const string& nodeName);
pair<string, string> getPathAndName(xml_node<>* node);
void clear()
{
for(unordered_map<string, pair<xml_document<>*, char*>>::iterator it=path_doc.begin(); it!=path_doc.end(); it++)
{
delete (it->second).first;
free(it->second.second);
}
path_doc.clear();
}
SceneObject* generateSceneObject(xml_node<>* nodeObj, xml_node<>* nodeMat, SimpleShape* shape = NULL);
public:
string getFullPath(const string& fn) const
{
if(access(fn.c_str(), 0) == 0)
return fn;
string fullPath = getFolder(rootFolder + "/" + currentPath) + "/" + fn;
if(access(fullPath.c_str(), 0) == 0)
return fullPath;
fullPath = rootFolder + "/" + fn;
if(access(fullPath.c_str(), 0) == 0)
return fullPath;
return "";
}
ConfigManager(Renderer* renderer);
void load(const string &configFilePath);
string getRootPath() const { return rootFolder; }
};