blob: 856345e312017b14cd5216cc14e567b8c1690b2c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/*
* Copyright (c) 2010-2014 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#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(std::remove(factories_.begin(), factories_.end(), factory), factories_.end());
}
void PayloadParserFactoryCollection::setDefaultFactory(PayloadParserFactory* factory) {
defaultFactory_ = factory;
}
PayloadParserFactory* PayloadParserFactoryCollection::getPayloadParserFactory(const std::string& element, const std::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_);
}
}
|