queso-0.56.1
AlgorithmFactory.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #ifndef QUESO_ALGORITHM_FACTORY_H
26 #define QUESO_ALGORITHM_FACTORY_H
27 
28 #include <queso/Factory.h>
29 #include <queso/GslVector.h>
30 #include <queso/GslMatrix.h>
31 #include <queso/VectorSpace.h>
32 #include <queso/Algorithm.h>
33 
34 namespace QUESO
35 {
36 
42 class AlgorithmFactory : public Factory<Algorithm<GslVector, GslMatrix> >
43 {
44 public:
48  AlgorithmFactory(const std::string & name)
50  {}
51 
55  virtual ~AlgorithmFactory() {}
56 
57  static void set_environment(const BaseEnvironment & env)
58  {
59  m_env = &env;
60  }
61 
62  static void set_tk(const BaseTKGroup<GslVector, GslMatrix> & tk)
63  {
64  m_tk = &tk;
65  }
66 
67 protected:
68  virtual SharedPtr<Algorithm<GslVector, GslMatrix> >::Type build_algorithm() = 0;
69 
70  static const BaseEnvironment * m_env;
72 
73 private:
78  virtual SharedPtr<Algorithm<GslVector, GslMatrix> >::Type create();
79 };
80 
81 inline
82 SharedPtr<Algorithm<GslVector, GslMatrix> >::Type
84 {
85  queso_require_msg(m_env, "ERROR: must call set_environment() before building alg!");
86  queso_require_msg(m_tk, "ERROR: must call set_tk() before building alg!");
87 
88  SharedPtr<Algorithm<GslVector, GslMatrix> >::Type new_alg = this->build_algorithm();
89 
90  queso_assert(new_alg);
91 
92  return new_alg;
93 }
94 
100 template <class DerivedAlgorithm>
102 {
103 public:
104  AlgorithmFactoryImp(const std::string & name)
105  : AlgorithmFactory(name)
106  {}
107 
108  virtual ~AlgorithmFactoryImp() {}
109 
110 private:
111  virtual SharedPtr<Algorithm<GslVector, GslMatrix> >::Type build_algorithm();
112 };
113 
114 } // namespace QUESO
115 
116 #endif // QUESO_ALGORITHM_FACTORY_H
virtual SharedPtr< Algorithm< GslVector, GslMatrix > >::Type create()
static void set_tk(const BaseTKGroup< GslVector, GslMatrix > &tk)
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:197
AlgorithmFactoryImp(const std::string &name)
static const BaseTKGroup< GslVector, GslMatrix > * m_tk
virtual SharedPtr< Algorithm< GslVector, GslMatrix > >::Type build_algorithm()=0
AlgorithmFactory(const std::string &name)
Class for vector operations using GSL library.
Definition: GslVector.h:49
#define queso_assert(asserted)
Definition: asserts.h:132
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
This base class allows the representation of a transition kernel.
Definition: Algorithm.h:32
static void set_environment(const BaseEnvironment &env)
virtual SharedPtr< Algorithm< GslVector, GslMatrix > >::Type build_algorithm()
static const BaseEnvironment * m_env
Class for matrix operations using GSL library.
Definition: GslMatrix.h:49

Generated on Thu Dec 15 2016 13:23:10 for queso-0.56.1 by  doxygen 1.8.5