PIValueTree::childValue method

This commit is contained in:
2023-04-24 19:03:36 +03:00
parent 0f19719a98
commit f503e85507
2 changed files with 11 additions and 0 deletions

View File

@@ -119,6 +119,16 @@ void PIValueTree::applyValues(const PIValueTree & root, bool recursive) {
}
PIVariant PIValueTree::childValue(const PIString & child_name, const PIVariant & default_value, bool * exists) const {
if (!contains(child_name)) {
if (exists) *exists = false;
return default_value;
}
return child(child_name).value();
if (exists) *exists = true;
}
bool PIValueTree::contains(const PIString & name) const {
if (_is_null) return true;
for (const auto & c: _children)

View File

@@ -92,6 +92,7 @@ public:
const PIVector<PIValueTree> & children() const { return _children; }
void clearChildren() { _children.clear(); }
PIVariant childValue(const PIString & child_name, const PIVariant & default_value = PIVariant(), bool * exists = nullptr) const;
bool contains(const PIString & name) const;
bool contains(const PIStringList & path) const;