1 /********************* */
2 /*! \file sat_solver_registry.h
4 ** Original author: Dejan Jovanovic
5 ** Major contributors: none
6 ** Minor contributors (to current version): Morgan Deters
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2014 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief This class transforms a sequence of formulas into clauses.
14 ** This class takes a sequence of formulas.
15 ** It outputs a stream of clauses that is propositionally
16 ** equi-satisfiable with the conjunction of the formulas.
17 ** This stream is maintained in an online fashion.
19 ** Compile time registration of SAT solvers with the SAT solver factory
24 #include "cvc4_private.h"
29 #include "prop/sat_solver.h"
30 #include "prop/sat_solver_factory.h"
36 * Interface for SAT solver constructors. Solvers should declare an instantiation of the
37 * SatSolverConstructor interface below.
39 class SatSolverConstructorInterface
{
41 virtual ~SatSolverConstructorInterface() {}
42 virtual SatSolver
* construct() = 0;
46 * Registry containing all the registered SAT solvers.
48 class SatSolverRegistry
{
50 typedef std::map
<std::string
, SatSolverConstructorInterface
*> registry_type
;
52 /** Map from ids to solver constructors */
53 registry_type d_solvers
;
55 /** Nobody can create the registry, there can be only one! */
56 SatSolverRegistry() {}
59 * Register a SAT solver with the registry. The Constructor type should be a subclass
60 * of the SatSolverConstructor.
62 template <typename Constructor
>
63 size_t registerSolver(const char* id
) {
65 char* demangled
= abi::__cxa_demangle(id
, 0, 0, &status
);
66 d_solvers
[demangled
] = new Constructor();
68 return d_solvers
.size();
71 /** Get the instance of the registry */
72 static SatSolverRegistry
* getInstance();
80 * Returns the constructor for the given SAT solver.
82 static SatSolverConstructorInterface
* getConstructor(std::string id
);
84 /** Get the ids of the available solvers */
85 static void getSolverIds(std::vector
<std::string
>& solvers
);
87 /** The Constructors are friends, since they need to register */
88 template<typename Solver
>
89 friend class SatSolverConstructor
;
94 * Declare an instance of this class with the SAT solver in order to put it in the registry.
96 template<typename Solver
>
97 class SatSolverConstructor
: public SatSolverConstructorInterface
{
99 /** Static solver id we use for initialization */
100 static const size_t s_solverId
;
104 /** Constructs the solver */
105 SatSolver
* construct() {
111 template<typename Solver
>
112 const size_t SatSolverConstructor
<Solver
>::s_solverId
= SatSolverRegistry::getInstance()->registerSolver
<SatSolverConstructor
>(typeid(Solver
).name());
114 }/* CVC4::prop namespace */
115 }/* CVC4 namespace */