Skip to content

Commit

Permalink
Introduce ConfigObject#GetAttribute()
Browse files Browse the repository at this point in the history
refs #8717
  • Loading branch information
Al2Klimov committed Apr 22, 2021
1 parent 8dc069d commit 734d4d2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/base/configobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,34 @@ class ModAttrValidationUtils final : public ValidationUtils
}
};

bool ConfigObject::GetAttribute(const String& attr, Value *result)
{
std::vector<String> tokens = attr.Split(".");
auto current (tokens.begin());
auto end (tokens.end());
Object::Ptr subTree (this);
Value branch;

for (;;) {
if (!subTree->GetOwnField(*current, &branch)) {
return false;
}

if (++current == end) {
break;
}

if (!branch.IsObject()) {
return false;
}

subTree = branch.Get<Object::Ptr>();
}

*result = std::move(branch);
return true;
}

void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool updateVersion)
{
Dictionary::Ptr original_attributes = GetOriginalAttributes();
Expand Down
1 change: 1 addition & 0 deletions lib/base/configobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ConfigObject : public ObjectImpl<ConfigObject>

ConfigObject::Ptr GetZone() const;

bool GetAttribute(const String& attr, Value *result);
void ModifyAttribute(const String& attr, const Value& value, bool updateVersion = true);
void RestoreAttribute(const String& attr, bool updateVersion = true);
bool IsAttributeModified(const String& attr) const;
Expand Down

0 comments on commit 734d4d2

Please sign in to comment.