Library: Refactor handling of comma-separated names
This commit is contained in:
parent
25749ab19f
commit
2a4cceae9e
|
@ -28,6 +28,17 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
static std::vector<std::string> getnames(const char *names)
|
||||||
|
{
|
||||||
|
std::vector<std::string> ret;
|
||||||
|
while (const char *p = std::strchr(names,',')) {
|
||||||
|
ret.push_back(std::string(names, p-names));
|
||||||
|
names = p + 1;
|
||||||
|
}
|
||||||
|
ret.push_back(names);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
Library::Library() : allocid(0)
|
Library::Library() : allocid(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -177,23 +188,15 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (nodename == "function") {
|
else if (nodename == "function") {
|
||||||
const char *name_char = node->Attribute("name");
|
const char *name = node->Attribute("name");
|
||||||
if (name_char == nullptr)
|
if (name == nullptr)
|
||||||
return Error(MISSING_ATTRIBUTE, "name");
|
return Error(MISSING_ATTRIBUTE, "name");
|
||||||
std::string name = name_char;
|
const std::vector<std::string> names(getnames(name));
|
||||||
for (;;) {
|
for (unsigned int i = 0U; i < names.size(); ++i) {
|
||||||
const std::string::size_type pos = name.find(',');
|
const Error &err = loadFunction(node, names[i], unknown_elements);
|
||||||
if (pos == std::string::npos)
|
|
||||||
break;
|
|
||||||
const Error &err = loadFunction(node, name.substr(0,pos), unknown_elements);
|
|
||||||
if (err.errorcode != ErrorCode::OK)
|
if (err.errorcode != ErrorCode::OK)
|
||||||
return err;
|
return err;
|
||||||
name.erase(0,pos+1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Error &err = loadFunction(node, name, unknown_elements);
|
|
||||||
if (err.errorcode != ErrorCode::OK)
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (nodename == "reflection") {
|
else if (nodename == "reflection") {
|
||||||
|
@ -412,7 +415,9 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
const char * const sign = node->Attribute("sign");
|
const char * const sign = node->Attribute("sign");
|
||||||
if (sign)
|
if (sign)
|
||||||
podType.sign = *sign;
|
podType.sign = *sign;
|
||||||
podtypes[name] = podType;
|
const std::vector<std::string> names(getnames(name));
|
||||||
|
for (unsigned int i = 0U; i < names.size(); ++i)
|
||||||
|
podtypes[names[i]] = podType;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (nodename == "platformtype") {
|
else if (nodename == "platformtype") {
|
||||||
|
|
Loading…
Reference in New Issue