forked from kenygia/MooseEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenStatsReader.cpp
124 lines (118 loc) · 3.25 KB
/
GenStatsReader.cpp
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
#include "GenStatsReader.h"
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
typedef boost::tokenizer<boost::escaped_list_separator<char> > LineTokenizer;
GenStatsReader::GenStatsReader()
{
}
StatsContainer *GenStatsReader::getContainer(std::vector<StatsContainer *> &containers, std::string containerName)
{
for (int i=0; i<containers.size(); ++i) {
StatsContainer& container = *containers[i];
if (container.getArg(0) == containerName) {
return &container;
}
}
return 0;
}
std::vector<StatsContainer *> GenStatsReader::getContainersByContainerType(std::vector<StatsContainer *> &containers, std::string type)
{
std::vector<StatsContainer *> result;
for (int i=0; i<containers.size(); ++i) {
StatsContainer& container = *containers[i];
if (container.getContainerType() == type) {
result.push_back(&container);
}
}
return result;
}
std::vector<StatsContainer *> GenStatsReader::getSubclassContainers(std::vector<StatsContainer *> &containers, StatsContainer *superClass)
{
std::vector<StatsContainer *> result;
for (int i=0; i<containers.size(); ++i) {
StatsContainer& container = *containers[i];
if (container.getUsingName() == superClass->getArg(0)) {
result.push_back(&container);
}
}
return result;
}
std::vector<StatsContainer *> GenStatsReader::loadFile(std::istream& stream)
{
std::vector<StatsContainer *> containers;
if (!stream) {
return containers;
}
std::string buffer;
boost::escaped_list_separator<char> separator("",", ","\"");
StatsContainer *current = 0;
for (;;) {
buffer = "";
std::getline(stream, buffer, '\n');
if (!stream) {
break;
}
if (boost::ends_with(buffer, "\r")) {
buffer.resize(buffer.length() - 1);
}
LineTokenizer tok(buffer, separator);
int i = 0;
std::string keyword = "";
std::string last = "";
bool isBoost = false;
for(LineTokenizer::iterator it = tok.begin(); it != tok.end(); ++it) {
const std::string& token = *it;
if (keyword == "new" || keyword == "object" || (keyword == "modifier" && (token == "type" || last == "type"))) {
if (token == "boost" && i == 1) {
isBoost = true;
keyword = "boost";
} else {
if (i == 1) {
containers.push_back(new StatsContainer);
current = containers[containers.size() - 1];
current->setContainerType(token.c_str());
} else {
current->addArg(token.c_str());
}
}
} else if (keyword == "type") {
if (i == 1) {
if (current != 0) {
current->setType(token.c_str());
}
}
} else if (keyword == "data" || keyword == "param" || keyword == "modifier") {
if (i == 2) {
if (current != 0) {
current->addData(last, token);
}
}
} else if (keyword == "using") {
if (i == 1) {
if (current != 0) {
current->setUsing(getContainer(containers, token));
}
}
} else if (keyword == "prefixname") {
if (i == 1) {
current->getPrefixList().push_back(token);
}
} else if (keyword == "suffixname") {
if (i == 1) {
current->getSuffixList().push_back(token);
}
} else if (isBoost && keyword == "boost") {
if (i == 3) {
current->setBoostName(last);
current->setBoostValue(token);
}
}
if (i == 0) {
keyword = token;
}
last = token;
++i;
}
}
return containers;
}