Grid 0.7.0
Modules.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/action/gauge/WilsonGaugeAction.h
6
7Copyright (C) 2016
8
9Author: Guido Cossu <guido.cossu@ed.ac.uk>
10
11This program is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along
22with this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25See the full license in the file "LICENSE" in the top level distribution
26directory
27*************************************************************************************/
28 /* END LEGAL */
29#ifndef HMC_MODULES_H
30#define HMC_MODULES_H
31
32 /*
33 Define loadable, serializable modules
34 for the HMC execution
35 */
36
38
39// Empty class for no parameters
41
42
43/*
44 Base class for modules with parameters
45*/
46template < class P >
48public:
49 typedef P Parameters;
50
52
53 template <class ReaderClass>
54 Parametrized(Reader<ReaderClass> & R, std::string section_name = "parameters"){
55 read(R, section_name, Par_);
56 }
57
59 Par_ = Par;
60 }
61
63 std::cout << Par_ << std::endl;
64 }
65
66protected:
68private:
69 std::string section_name;
70};
71
72
73template <>
75public:
77
79
80 template <class ReaderClass>
81 Parametrized(Reader<ReaderClass> & Reader){};
82
84
86
87};
88
89
90
92// Lowest level abstract module class
94template <class Prod>
96public:
97 typedef Prod Product;
98
99 virtual Prod* getPtr() = 0;
100
101 // add a getReference?
102 virtual ~HMCModuleBase(){};
103 virtual void print_parameters(){}; // default to nothing
104};
105
106
108// Registration class
110
111template <class T, class TheFactory>
113public:
114 Registrar(std::string className) {
115 // register the class factory function
116 TheFactory::getInstance().registerBuilder(className,
117 [&](typename TheFactory::TheReader Reader)
118 {
119 return std::unique_ptr<T>(new T(Reader));
120 }
121 );
122 }
123};
124
126
127#endif //HMC_MODULES_H
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
BaseHmcCheckpointer< ImplementationPolicy > Product
Definition Modules.h:97
virtual Prod * getPtr()=0
virtual ~HMCModuleBase()
Definition Modules.h:102
virtual void print_parameters()
Definition Modules.h:103
void set_parameters(Parameters Par)
Definition Modules.h:83
Parametrized(Parameters Par)
Definition Modules.h:78
Parametrized(Reader< ReaderClass > &Reader)
Definition Modules.h:81
void set_parameters(Parameters Par)
Definition Modules.h:58
void print_parameters()
Definition Modules.h:62
Parametrized(Parameters Par)
Definition Modules.h:51
std::string section_name
Definition Modules.h:69
Parametrized(Reader< ReaderClass > &R, std::string section_name="parameters")
Definition Modules.h:54
Parameters Par_
Definition Modules.h:67
Registrar(std::string className)
Definition Modules.h:114