1
This commit is contained in:
parent
cdab528313
commit
58dd5bb850
@ -11,14 +11,31 @@ namespace a8
|
||||
static std::vector<std::pair<std::string, int>>* fields = nullptr;
|
||||
if (!fields) {
|
||||
fields = new std::vector<std::pair<std::string, int>>();
|
||||
int last_id = -1;
|
||||
const char* p = ::GetEnumString<T>();
|
||||
while (*p) {
|
||||
if (*p == '_' || isalpha(*p)) {
|
||||
const char* p_key_begin = p++;
|
||||
while (*p == '_' || isalpha(*p) || isalnum(*p)) { ++p; }
|
||||
const char* p_key_end = p - 1;
|
||||
std::string key(p_key_begin, p_key_end + 1);
|
||||
|
||||
while (*p != '=') { ++p; }
|
||||
while (*p && *p != '=' && *p != ',') { ++p; }
|
||||
if (!*p) {
|
||||
fields->push_back(std::make_pair
|
||||
(key,
|
||||
++last_id
|
||||
)
|
||||
);
|
||||
break;
|
||||
} else if (*p == ',') {
|
||||
fields->push_back(std::make_pair
|
||||
(key,
|
||||
++last_id
|
||||
)
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
++p;
|
||||
while (!isalnum(*p)) { ++p; }
|
||||
@ -26,11 +43,11 @@ namespace a8
|
||||
while (isalnum(*p)) { ++p; }
|
||||
const char* p_val_end = p - 1;
|
||||
|
||||
std::string key(p_key_begin, p_key_end + 1);
|
||||
std::string val(p_val_begin, p_val_end + 1);
|
||||
last_id = a8::XValue(val);
|
||||
fields->push_back(std::make_pair
|
||||
(key,
|
||||
a8::XValue(val).GetInt()));
|
||||
last_id));
|
||||
//printf("%s=%s\n", key.c_str(), val.c_str());
|
||||
} else {
|
||||
++p;
|
||||
@ -40,4 +57,16 @@ namespace a8
|
||||
return fields;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::string GetEnumName(int id, T* t = nullptr)
|
||||
{
|
||||
auto fields = GetEnumFields<T>();
|
||||
for (auto& pair : *fields) {
|
||||
if (pair.second == id) {
|
||||
return pair.first;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user