PIValueTree improvements: methods with path (recursive), forEachRecursive()
PIValueTreeConvertions::fromTextFile now can include other files and handle ${} substitutions
This commit is contained in:
@@ -127,9 +127,10 @@ PIValueTree prepareFromText(const PIValueTree & root) {
|
||||
|
||||
PIValueTree PIValueTreeConversions::fromText(PIIODevice * device) {
|
||||
PIValueTree ret;
|
||||
PIMap<PIString, PIString> substitutions;
|
||||
if (!device) return ret;
|
||||
PIString base_path;
|
||||
if (device->isTypeOf<PIFile>()) base_path = PIFile::FileInfo(device->path()).dir();
|
||||
if (device->isTypeOf<PIFile>()) base_path = PIFile::FileInfo(device->path()).dir().replaceAll('\\', '/');
|
||||
PIIOTextStream ts(device);
|
||||
PIString line, comm;
|
||||
PIVariant value;
|
||||
@@ -165,6 +166,7 @@ PIValueTree PIValueTreeConversions::fromText(PIIODevice * device) {
|
||||
if (ind > 0)
|
||||
if (line[ind - 1] == '\\') continue;
|
||||
cind = ind;
|
||||
break;
|
||||
}
|
||||
if (cind >= 0) {
|
||||
comm = line.takeMid(cind + 1);
|
||||
@@ -198,26 +200,32 @@ PIValueTree PIValueTreeConversions::fromText(PIIODevice * device) {
|
||||
path << line.takeLeft(ind).split('.').trim();
|
||||
line.cutLeft(1).trim();
|
||||
if (path.front() == "include") {
|
||||
/*name = line.mid(ind + 1).trimmed();
|
||||
PIConfig * iconf = new PIConfig(name, incdirs);
|
||||
//piCout << "include" << name << iconf->dev;
|
||||
if (!iconf->dev) {
|
||||
delete iconf;
|
||||
} else {
|
||||
inc_devs << iconf;
|
||||
includes << iconf << iconf->includes;
|
||||
updateIncludes();
|
||||
PIString include = line.trimmed();
|
||||
if (!PIFile::FileInfo(include).isAbsolute()) {
|
||||
include = base_path + "/" + include.replaceAll('\\', '/');
|
||||
include.replaceAll("//", '/');
|
||||
}
|
||||
other.back() = src;*/
|
||||
PIValueTree inc_vt = PIValueTreeConversions::fromTextFile(include);
|
||||
inc_vt.forEachRecursive(
|
||||
[&substitutions](const PIValueTree & v, const PIString & fn) { substitutions[fn] = v.value().toString(); });
|
||||
path.clear();
|
||||
}
|
||||
} else {
|
||||
line.clear();
|
||||
continue;
|
||||
}
|
||||
// piCout << path << line << comm;
|
||||
if (path.isEmpty()) {
|
||||
line.clear();
|
||||
continue;
|
||||
}
|
||||
PIValueTree & leaf(ret[path]);
|
||||
leaf.setComment(comm);
|
||||
leaf.setValue(unmask(line));
|
||||
line = unmask(line);
|
||||
for (const auto & s: substitutions)
|
||||
line.replaceAll("${" + s.first + "}", s.second);
|
||||
leaf.setValue(line);
|
||||
substitutions[path.join('.')] = leaf.value().toString();
|
||||
if (!path.contains(_attribute_))
|
||||
if (!leaf.contains({_attribute_, "type"})) leaf[_attribute_].addChild({"type", type});
|
||||
line.clear();
|
||||
|
||||
Reference in New Issue
Block a user