SolverFactory.h 1.12 KB
Newer Older
1 2 3
#ifndef INMOST_SOLVERFACTORY_H
#define INMOST_SOLVERFACTORY_H

Dmitry Bagaev's avatar
Dmitry Bagaev committed
4
#include <inmost.h>
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

namespace INMOST {

    struct SolverBaseFactory {
        virtual SolverInterface* create() = 0;
        virtual SolverInterface* copy(const SolverInterface* other) = 0;
        virtual ~SolverBaseFactory() {};
    };

    template <class C> struct SolverCreateFactory : SolverBaseFactory {
        SolverInterface *create() {
            return new C;
        };

        SolverInterface *copy(const SolverInterface* other) {
            return new C(other);
        };
    };

    class SolverFactory {
    private:
        static std::map<std::string, SolverBaseFactory *> solvers;
    public:
        template<class T> static void registerSolver(std::string name) {
            solvers.insert(std::make_pair(name, new SolverCreateFactory<T>));
        };
        static SolverInterface *getSolver(std::string name);
        static SolverInterface *copySolver(const SolverInterface *other);
        static std::vector<std::string> getAvailableSolvers();
        static bool isSolverAvailable(std::string name);
    };

}

#endif //INMOST_SOLVERFACTORY_H