TGSTK  0.0.1
The Tumour Growth Simulation ToolKit
tgstkAlgorithmBase.h
Go to the documentation of this file.
1 /*==========================================================================
2 
3  This file is part of the Tumor Growth Simulation ToolKit (TGSTK)
4  (<https://github.com/cormarte/TGSTK>, <https://cormarte.github.io/TGSTK>).
5 
6  Copyright (C) 2021 Corentin Martens
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program 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
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <https://www.gnu.org/licenses/>.
20 
21  Contact: corentin.martens@ulb.be
22 
23 ==========================================================================*/
24 
35 #ifndef TGSTKALGORITHMBASE_H
36 #define TGSTKALGORITHMBASE_H
37 
38 #define assertNotNullPtr(var) _assertNotNullPtr(var, #var)
39 #define assertValueInRange(var, min, max) _assertValueInRange(var, min, max, #var)
40 #define assertValueIsEqual(var1, var2) _assertValueIsEqual(var1, var2, #var1, #var2)
41 
42 #include <tgstk/tgstkGlobal.h>
44 
46 
47  public:
48 
49  virtual ~tgstkAlgorithmBase();
50 
51  virtual bool check();
52  virtual void execute()=0;
53 
54  bool update();
55 
56  protected:
57 
59 
60  template<typename Type> bool _assertNotNullPtr(Type var, std::string name);
61  template<typename Type> bool _assertValueInRange(Type var, Type min, Type max, std::string name);
62  template<typename Type1, typename Type2> bool _assertValueIsEqual(Type1 var1, Type2 var2, std::string name1, std::string name2);
63 };
64 
65 template<typename Type>
66 bool tgstkAlgorithmBase::_assertNotNullPtr(Type var, std::string name) {
67 
68  bool assert = var != nullptr;
69 
70  if (!assert) {
71 
72  cout << this->objectName << ": Error: '" << name << "' is nullptr." << endl;
73  }
74 
75  return assert;
76 }
77 
78 template<typename Type>
79 bool tgstkAlgorithmBase::_assertValueInRange(Type var, Type min, Type max, std::string name) {
80 
81  bool assert = (var >= min && var <= max);
82 
83  if (!assert) {
84 
85  cout << this->objectName << ": Error: '" << name << "' should be in range [" << min << "; " << max <<"]." << endl;
86  }
87 
88  return assert;
89 }
90 
91 template<typename Type1, typename Type2>
92 bool tgstkAlgorithmBase::_assertValueIsEqual(Type1 var1, Type2 var2, std::string name1, std::string name2) {
93 
94  bool assert = (var1 == var2);
95 
96  if (!assert) {
97 
98  cout << this->objectName << ": Error: '" << name1 << "' not equal to '" << name2 << "'." << endl;
99  }
100 
101  return assert;
102 }
103 
104 #endif // TGSTKALGORITHMBASE_H
tgstkGlobal.h
TGSTK_EXPORT
#define TGSTK_EXPORT
Definition: tgstkGlobal.h:31
tgstkAlgorithmBase::_assertValueInRange
bool _assertValueInRange(Type var, Type min, Type max, std::string name)
Definition: tgstkAlgorithmBase.h:79
tgstkObjectBase::objectName
std::string objectName
Definition: tgstkObjectBase.h:44
tgstkObjectBase
Definition: tgstkObjectBase.h:32
tgstkAlgorithmBase::_assertValueIsEqual
bool _assertValueIsEqual(Type1 var1, Type2 var2, std::string name1, std::string name2)
Definition: tgstkAlgorithmBase.h:92
tgstkAlgorithmBase
Base class for TGSTK algorithms.
Definition: tgstkAlgorithmBase.h:45
tgstkObjectBase.h
tgstkAlgorithmBase::_assertNotNullPtr
bool _assertNotNullPtr(Type var, std::string name)
Definition: tgstkAlgorithmBase.h:66