summaryrefslogtreecommitdiffstats
blob: 44264284c68060be030f6857087242fd8f9fddb4 (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
38
39
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swiften/Parser/PayloadParserFactoryCollection.h>

#include <algorithm>

#include <boost/bind.hpp>

#include <Swiften/Parser/PayloadParserFactory.h>

namespace Swift {

PayloadParserFactoryCollection::PayloadParserFactoryCollection() : defaultFactory_(nullptr) {
}

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_);
}

}