Return configuration nodes in entry order
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
15b4789015
commit
78fd5716b3
|
@ -33,7 +33,9 @@ bool Configuration::addEntry(const std::string &entry) {
|
|||
if(entry.empty() || entry[0] == '#'){
|
||||
return false;
|
||||
}
|
||||
std::string fullKey;
|
||||
std::string currentKey;
|
||||
fullKey.reserve(32);
|
||||
currentKey.reserve(16);
|
||||
|
||||
uint32_t state = 0;
|
||||
|
@ -47,10 +49,14 @@ bool Configuration::addEntry(const std::string &entry) {
|
|||
if(!currentKey.empty()){
|
||||
currentNode = ¤tNode->getOrCreateSubNode(currentKey);
|
||||
|
||||
fullKey += currentKey;
|
||||
|
||||
currentKey.clear();
|
||||
|
||||
if(c == ' ' || c == '\t'){
|
||||
state = 1;
|
||||
}else{
|
||||
fullKey += ".";
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
@ -78,6 +84,9 @@ bool Configuration::addEntry(const std::string &entry) {
|
|||
if(i == (entry.size() - 1)){
|
||||
currentKey += c;
|
||||
currentNode->value = currentKey;
|
||||
if(std::find(orderedNodes.begin(), orderedNodes.end(), fullKey) == orderedNodes.end()){
|
||||
orderedNodes.emplace_back(fullKey);
|
||||
}
|
||||
}else if((c == ' ' || c == '\t') && currentKey.empty()){
|
||||
|
||||
} else {
|
||||
|
@ -141,14 +150,11 @@ void Configuration::getAllEntriesForNode(std::vector<std::string> &entries, cons
|
|||
std::vector<std::string> Configuration::getAllEntries() const {
|
||||
std::vector<std::string> entries;
|
||||
|
||||
for(const auto& n : mainNode.possibleNodes){
|
||||
if(n.type == ConfigurationNode::Type::Node){
|
||||
getAllEntriesForNode(entries, n, n.name + ".");
|
||||
}
|
||||
for(const auto& key : orderedNodes){
|
||||
auto& v = getEntry(key);
|
||||
entries.push_back(key + " " + v.getTypeString() + " " + v.value);
|
||||
}
|
||||
|
||||
std::sort(entries.begin(), entries.end());
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ public:
|
|||
};
|
||||
|
||||
ConfigurationNode mainNode = ConfigurationNode("");
|
||||
std::vector<std::string> orderedNodes;
|
||||
|
||||
std::vector<std::string> getAllEntries() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue