summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/AttributeMap.cpp25
-rw-r--r--Swiften/Parser/Tree/ParserElement.cpp19
2 files changed, 16 insertions, 28 deletions
diff --git a/Swiften/Parser/AttributeMap.cpp b/Swiften/Parser/AttributeMap.cpp
index 1aeaf99..d508157 100644
--- a/Swiften/Parser/AttributeMap.cpp
+++ b/Swiften/Parser/AttributeMap.cpp
@@ -8,27 +8,18 @@
#include <algorithm>
#include <boost/optional.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
using namespace Swift;
-
-namespace {
- struct AttributeIs {
- AttributeIs(const Attribute& attribute) : attribute(attribute) {
- }
-
- bool operator()(const AttributeMap::Entry& o) const {
- return o.getAttribute() == attribute;
- }
-
- Attribute attribute;
- };
-}
+namespace lambda = boost::lambda;
AttributeMap::AttributeMap() {
}
std::string AttributeMap::getAttribute(const std::string& attribute, const std::string& ns) const {
- AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), AttributeIs(Attribute(attribute, ns)));
+ AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(),
+ lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, ns));
if (i == attributes.end()) {
return "";
}
@@ -38,7 +29,8 @@ std::string AttributeMap::getAttribute(const std::string& attribute, const std::
}
bool AttributeMap::getBoolAttribute(const std::string& attribute, bool defaultValue) const {
- AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), AttributeIs(Attribute(attribute, "")));
+ AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(),
+ lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, ""));
if (i == attributes.end()) {
return defaultValue;
}
@@ -48,7 +40,8 @@ bool AttributeMap::getBoolAttribute(const std::string& attribute, bool defaultVa
}
boost::optional<std::string> AttributeMap::getAttributeValue(const std::string& attribute) const {
- AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), AttributeIs(Attribute(attribute, "")));
+ AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(),
+ lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, ""));
if (i == attributes.end()) {
return boost::optional<std::string>();
}
diff --git a/Swiften/Parser/Tree/ParserElement.cpp b/Swiften/Parser/Tree/ParserElement.cpp
index 9d9b9b6..e5f8bc8 100644
--- a/Swiften/Parser/Tree/ParserElement.cpp
+++ b/Swiften/Parser/Tree/ParserElement.cpp
@@ -9,8 +9,12 @@
#include <Swiften/Parser/Tree/NullParserElement.h>
#include <iostream>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
-namespace Swift{
+namespace lambda = boost::lambda;
+
+namespace Swift {
ParserElement::ParserElement(const std::string& name, const std::string& xmlns, const AttributeMap& attributes) : name_(name), xmlns_(xmlns), attributes_(attributes) {
}
@@ -28,19 +32,10 @@ void ParserElement::appendCharacterData(const std::string& data) {
text_ += data;
}
-struct DoesntMatch {
- public:
- DoesntMatch(const std::string& tagName, const std::string& ns) : tagName(tagName), ns(ns) {}
- bool operator()(ParserElement::ref element) { return element->getName() != tagName || element->getNamespace() != ns; }
- private:
- std::string tagName;
- std::string ns;
-};
-
-
std::vector<ParserElement::ref> ParserElement::getChildren(const std::string& name, const std::string& xmlns) const {
std::vector<ParserElement::ref> result;
- std::remove_copy_if(children_.begin(), children_.end(), std::back_inserter(result), DoesntMatch(name, xmlns));
+ std::remove_copy_if(children_.begin(), children_.end(), std::back_inserter(result),
+ lambda::bind(&ParserElement::getName, *lambda::_1) != name || lambda::bind(&ParserElement::getNamespace, *lambda::_1) != xmlns);
return result;
}