diff options
Diffstat (limited to 'Swiften/Parser/PayloadParserFactoryCollection.cpp')
-rw-r--r-- | Swiften/Parser/PayloadParserFactoryCollection.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParserFactoryCollection.cpp new file mode 100644 index 0000000..6d3a4cf --- /dev/null +++ b/Swiften/Parser/PayloadParserFactoryCollection.cpp @@ -0,0 +1,31 @@ +#include <boost/bind.hpp> +#include <algorithm> + +#include "Swiften/Parser/PayloadParserFactoryCollection.h" +#include "Swiften/Parser/PayloadParserFactory.h" + +namespace Swift { + +PayloadParserFactoryCollection::PayloadParserFactoryCollection() : defaultFactory_(NULL) { +} + +void PayloadParserFactoryCollection::addFactory(PayloadParserFactory* factory) { + factories_.push_back(factory); +} + +void PayloadParserFactoryCollection::removeFactory(PayloadParserFactory* factory) { + factories_.erase(remove(factories_.begin(), factories_.end(), factory), factories_.end()); +} + +void PayloadParserFactoryCollection::setDefaultFactory(PayloadParserFactory* factory) { + defaultFactory_ = factory; +} + +PayloadParserFactory* PayloadParserFactoryCollection::getPayloadParserFactory(const String& element, const String& ns, const AttributeMap& attributes) { + std::vector<PayloadParserFactory*>::reverse_iterator i = std::find_if( + factories_.rbegin(), factories_.rend(), + boost::bind(&PayloadParserFactory::canParse, _1, element, ns, attributes)); + return (i != factories_.rend() ? *i : defaultFactory_); +} + +} |