SolverFactory.cpp 1.27 KB
Newer Older
1 2 3 4
//
// Created by Dmitri Bagaev on 28.09.16.
//

Dmitry Bagaev's avatar
Dmitry Bagaev committed
5
#include "inmost.h"
6
#include "SolverFactory.h"
Dmitry Bagaev's avatar
Dmitry Bagaev committed
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

namespace INMOST {

    std::map<std::string, SolverBaseFactory *> SolverFactory::solvers = std::map<std::string, SolverBaseFactory *>();

    SolverInterface *SolverFactory::getSolver(std::string name) {
        auto iterator = SolverFactory::solvers.find(name);
        if (iterator != SolverFactory::solvers.end()) {
            return iterator->second->create();
        } else {
            throw INMOST::SolverNotFound;
        }
    }

    SolverInterface *SolverFactory::copySolver(const SolverInterface *other) {
23
        auto iterator = SolverFactory::solvers.find(other->SolverName());
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
        if (iterator != SolverFactory::solvers.end()) {
            return iterator->second->copy(other);
        } else {
            throw INMOST::SolverNotFound;
        }
    }

    std::vector<std::string> SolverFactory::getAvailableSolvers() {
        std::vector<std::string> s;
        for (auto bi = SolverFactory::solvers.begin(); bi != SolverFactory::solvers.end(); bi++) {
            s.push_back(bi->first);
        }
        return s;
    }

    bool SolverFactory::isSolverAvailable(std::string name) {
        return SolverFactory::solvers.find(name) != SolverFactory::solvers.end();
    }



}