From 255b5174c4f162006d564327fb54f48bbd7ddc09 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 3 May 2016 02:07:40 +0200 Subject: [PATCH] add a const method to check for existing key/value properties handy to lookup up XMLNodes with "id" == ID w/o allocating memory. --- libs/pbd/pbd/xml++.h | 6 ++++-- 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(this)->property(n); } - const XMLProperty* property(const std::string& n) const { return const_cast(this)->property(n); } + const XMLProperty* property(const char* n) const { return const_cast(this)->property(n); } + const XMLProperty* property(const std::string& n) const { return const_cast(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::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) {