SolverMaster.h 1.71 KB
Newer Older
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1
2
3
4
5
#ifndef INMOST_SOLVER_MASTER
#define INMOST_SOLVER_MASTER

#include <inmost_solver.h>
#include <inmost_solver_interface.h>
6
7
8
9

namespace INMOST {

    struct SolverBaseFactory {
Dmitry Bagaev's avatar
Dmitry Bagaev committed
10
        virtual SolverInterface *create(SolverParameters &parameters) = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
11

Dmitry Bagaev's avatar
Dmitry Bagaev committed
12
        virtual SolverInterface *copy(const SolverInterface *other) = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
13

14
15
16
        virtual ~SolverBaseFactory() {};
    };

Dmitry Bagaev's avatar
Dmitry Bagaev committed
17
18
    template<class C>
    struct SolverCreateFactory : SolverBaseFactory {
Dmitry Bagaev's avatar
Dmitry Bagaev committed
19
20
        SolverInterface *create(SolverParameters &parameters) {
            return new C(parameters);
21
22
        };

Dmitry Bagaev's avatar
Dmitry Bagaev committed
23
        SolverInterface *copy(const SolverInterface *other) {
24
25
26
27
            return new C(other);
        };
    };

28
    class SolverMaster {
29
30
    private:
        static std::map<std::string, SolverBaseFactory *> solvers;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
31

Dmitry Bagaev's avatar
Dmitry Bagaev committed
32
33
        template<class T>
        static void registerSolver(std::string name) {
34
35
            solvers.insert(std::make_pair(name, new SolverCreateFactory<T>));
        };
Dmitry Bagaev's avatar
Dmitry Bagaev committed
36

Dmitry Bagaev's avatar
Dmitry Bagaev committed
37
        static SolverInterface *getSolver(std::string name, SolverParameters &parameters);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
38

39
        static SolverInterface *copySolver(const SolverInterface *other);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
40

41
        static std::vector<std::string> getAvailableSolvers();
Dmitry Bagaev's avatar
Dmitry Bagaev committed
42

43
        static bool isSolverAvailable(std::string name);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
44
45
46
47
48
49
50
51
52
53

        friend Solver::Solver(std::string solverName, std::string prefix, INMOST_MPI_Comm _comm);

        friend Solver::Solver(const Solver &other);

        friend void Solver::Initialize(int *argc, char ***argv, const char *database);

        friend bool Solver::isSolverAvailable(std::string name);

        friend std::vector<std::string> Solver::getAvailableSolvers();
54
55
    };

56
    typedef std::map<std::string, SolverBaseFactory *>::iterator solvers_map_iterator_t;
57
58
}

Dmitry Bagaev's avatar
Dmitry Bagaev committed
59
#endif //INMOST_SOLVER_MASTER