diff options
author | Robin Gareus <robin@gareus.org> | 2016-05-03 02:07:40 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-05-03 03:03:00 +0200 |
commit | 255b5174c4f162006d564327fb54f48bbd7ddc09 (patch) | |
tree | b8157265870f0ab5cccbd5b7b520ccf524f8a87c | |
parent | c2e4cd2c6a614718c8bc6a795d56fd4e6232bd84 (diff) |
add a const method to check for existing key/value properties
handy to lookup up XMLNodes with "id" == ID w/o allocating memory.
-rw-r--r-- | libs/pbd/pbd/xml++.h | 6 | ||||
-rw-r--r-- | libs/pbd/xml++.cc | 11 |
2 files changed, 15 insertions, 2 deletions
diff --git a/libs/pbd/pbd/xml++.h b/libs/pbd/pbd/xml++.h index 0e1bd09cc2..1f8b710f3f 100644 --- a/libs/pbd/pbd/xml++.h +++ b/libs/pbd/pbd/xml++.h @@ -119,8 +119,10 @@ public: const XMLPropertyList& properties() const { return _proplist; } XMLProperty* property(const char*); XMLProperty* property(const std::string&); - const XMLProperty* property(const char* n) const { return const_cast<XMLNode*>(this)->property(n); } - const XMLProperty* property(const std::string& n) const { return const_cast<XMLNode*>(this)->property(n); } + const XMLProperty* property(const char* n) const { return const_cast<XMLNode*>(this)->property(n); } + const XMLProperty* property(const std::string& n) const { return const_cast<XMLNode*>(this)->property(n); } + + bool has_property_with_value (const std::string&, const std::string&) const; XMLProperty* add_property(const char* name, const std::string& value); XMLProperty* add_property(const char* name, const char* value = ""); diff --git a/libs/pbd/xml++.cc b/libs/pbd/xml++.cc index 6d260f2525..580ad8dc8b 100644 --- a/libs/pbd/xml++.cc +++ b/libs/pbd/xml++.cc @@ -429,6 +429,17 @@ XMLNode::property(const string& ns) return 0; } +bool +XMLNode::has_property_with_value (const string& key, const string& value) const +{ + map<string,XMLProperty*>::const_iterator iter = _propmap.find(key); + if (iter != _propmap.end()) { + const XMLProperty* p = (iter->second); + return (p && p->value() == value); + } + return false; +} + XMLProperty* XMLNode::add_property(const char* n, const string& v) { |