Hex: src/quantities.h Source File

| Hex 2.2 Hydrogen-electron collision solver

quantities.h
Go to the documentation of this file.
1 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2 // //
3 // / / / / __ \ \ / / //
4 // / /__ / / / _ \ \ \/ / //
5 // / ___ / | |/_/ / /\ \ //
6 // / / / / \_\ / / \ \ //
7 // //
8 // //
9 // Copyright (c) 2016, Jakub Benda, Charles University in Prague //
10 // //
11 // MIT License: //
12 // //
13 // Permission is hereby granted, free of charge, to any person obtaining a //
14 // copy of this software and associated documentation files (the "Software"), //
15 // to deal in the Software without restriction, including without limitation //
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense, //
17 // and/or sell copies of the Software, and to permit persons to whom the //
18 // Software is furnished to do so, subject to the following conditions: //
19 // //
20 // The above copyright notice and this permission notice shall be included //
21 // in all copies or substantial portions of the Software. //
22 // //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, //
27 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF //
28 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
29 // //
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31
32 #ifndef HEX_DB_QUANTITIES_H
33 #define HEX_DB_QUANTITIES_H
34
35 // --------------------------------------------------------------------------------- //
36
37 #include <iostream>
38 #include <string>
39 #include <map>
40 #include <vector>
41
42 // --------------------------------------------------------------------------------- //
43
44 #include "hex-rts.h"
45
46 // --------------------------------------------------------------------------------- //
47
48 #include <sqlitepp/sqlitepp.hpp>
49
50 // --------------------------------------------------------------------------------- //
51
52 class ScatteringQuantity
53 {
54 protected:
55
57 sqlitepp::session * db;
58
59 public:
60
61 // run-time selection mechanism
62
63 baseClassRunTimeSelectionDefinitions(ScatteringQuantity, ())
64
65 // properties
66
67
68 virtual std::string description ()
69 {
70 return "";
71 }
72
74 virtual std::vector<std::pair<std::string,std::string>> params ()
75 {
76 return std::vector<std::pair<std::string,std::string>>();
77 }
78
80 virtual std::vector<std::string> vparams ()
81 {
82 return std::vector<std::string>();
83 }
84
87 virtual std::vector<std::string> dependencies ()
88 {
89 return std::vector<std::string>();
90 }
91
92 // database interface
93
94 sqlitepp::session & session ()
95 {
96 return *db;
97 }
98
100 virtual bool initialize (sqlitepp::session & db)
101 {
102 this->db = &db;
103 return true;
104 }
105
107 virtual bool createTable ()
108 {
109 return true;
110 }
111
113 virtual bool updateTable ()
114 {
115 return true;
116 }
117
119 virtual bool run (std::map<std::string,std::string> const & params)
120 {
121 return true;
122 }
123 };
124
125 // --------------------------------------------------------------------------------- //
126
127 ScatteringQuantity * get_quantity (std::string name);
128
129 // --------------------------------------------------------------------------------- //
130
131 // define new scattering quantity
132 #define createNewScatteringQuantity(Q, NAME) \
133 class Q : public ScatteringQuantity \
134 { \
135 public: \
136 derivedClassRunTimeSelectionDefinitions(ScatteringQuantity, (), Q, (), NAME) \
137 std::string description (); \
138 std::vector<std::pair<std::string,std::string>> params (); \
139 std::vector<std::string> vparams (); \
140 std::vector<std::string> dependencies (); \
141 bool initialize (sqlitepp::session & db); \
142 bool createTable (); \
143 bool updateTable (); \
144 bool run (std::map<std::string,std::string> const & params); \
145 }; \
146 addClassToParentRunTimeSelectionTable(ScatteringQuantity, Q)
147
148 // --------------------------------------------------------------------------------- //
149
150 #endif
ScatteringQuantity::vparams
virtual std::vector< std::string > vparams()
List of vectorizable scattering event parameters that have to be specified by user.
Definition: quantities.h:80
ScatteringQuantity::updateTable
virtual bool updateTable()
SQL statements that update the table after insetion of new data.
Definition: quantities.h:113
ScatteringQuantity::baseClassRunTimeSelectionDefinitions
baseClassRunTimeSelectionDefinitions(ScatteringQuantity,()) virtual std
Longer description text for use in program help.
Definition: quantities.h:63
ScatteringQuantity::db
sqlitepp::session * db
Database session.
Definition: quantities.h:57
ScatteringQuantity::run
virtual bool run(std::map< std::string, std::string > const &params)
write out requested data
Definition: quantities.h:119
get_quantity
ScatteringQuantity * get_quantity(std::string name)
ScatteringQuantity::initialize
virtual bool initialize(sqlitepp::session &db)
initialize (e.g.) by defining external routines for SQLite
Definition: quantities.h:100
ScatteringQuantity::dependencies
virtual std::vector< std::string > dependencies()
Definition: quantities.h:87
ScatteringQuantity::params
virtual std::vector< std::pair< std::string, std::string > > params()
List of all scattering event parameters (with description) that have to be specified by user...
Definition: quantities.h:74
ScatteringQuantity::session
sqlitepp::session & session()
Definition: quantities.h:94
ScatteringQuantity
Definition: quantities.h:52
ScatteringQuantity::createTable
virtual bool createTable()
SQL statements that create the required table, or empty vector if not needed.
Definition: quantities.h:107