53 |
|
#include "types/Component.hpp" |
54 |
|
#include "types/MakeStamps.hpp" |
55 |
|
#include "types/ZconStamp.hpp" |
56 |
– |
#include "utils/CaseConversion.hpp" |
56 |
|
|
57 |
< |
template<typename T> |
59 |
< |
struct ParameterTraits; |
57 |
> |
#include "utils/ParameterManager.hpp" |
58 |
|
|
61 |
– |
//string |
62 |
– |
template<> |
63 |
– |
struct ParameterTraits<std::string>{ |
64 |
– |
typedef std::string RepType; // Representation type of the value |
65 |
– |
|
66 |
– |
template<typename T> static bool convert(T v, RepType& r){return false;} // !NB everything is ok |
67 |
– |
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
68 |
– |
static bool convert(RepType v, RepType& r) { r = v; return true;} |
69 |
– |
static std::string getParamType() { return "string";} |
70 |
– |
}; |
71 |
– |
//bool |
72 |
– |
template<> |
73 |
– |
struct ParameterTraits<bool>{ |
74 |
– |
typedef bool RepType; |
75 |
– |
template<typename T> static bool convert(T, RepType&){return false;} |
76 |
– |
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
77 |
– |
static bool convert(std::string v, RepType& r) { |
78 |
– |
oopse::toLower(v); |
79 |
– |
bool result = false; |
80 |
– |
if (v == "true") { |
81 |
– |
r = true; |
82 |
– |
result = true; |
83 |
– |
} else if (v == "false") { |
84 |
– |
r = false; |
85 |
– |
result = true; |
86 |
– |
} |
87 |
– |
|
88 |
– |
return result; |
89 |
– |
} |
90 |
– |
static std::string getParamType() { return "bool";} |
91 |
– |
}; |
92 |
– |
|
93 |
– |
//int |
94 |
– |
template<> |
95 |
– |
struct ParameterTraits<int>{ |
96 |
– |
typedef int RepType; |
97 |
– |
template<typename T> static bool convert(T, RepType&){return false;} |
98 |
– |
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
99 |
– |
static bool convert(RepType v, RepType& r) { r=v; return true;} |
100 |
– |
static std::string getParamType() { return "int";} |
101 |
– |
}; |
102 |
– |
|
103 |
– |
//double |
104 |
– |
template<> |
105 |
– |
struct ParameterTraits<double>{ |
106 |
– |
typedef double RepType; |
107 |
– |
template<typename T> static bool convert(T, RepType&){return false;} |
108 |
– |
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
109 |
– |
static bool convert(RepType v, RepType& r) {r=v; return true;} |
110 |
– |
static bool convert(int v, RepType& r) {r = static_cast<double>(v); return true;} |
111 |
– |
static std::string getParamType() { return "double";} |
112 |
– |
}; |
113 |
– |
|
114 |
– |
|
115 |
– |
class ParameterBase { |
116 |
– |
public: |
117 |
– |
ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {} |
118 |
– |
bool isOptional() {return optional_;} |
119 |
– |
void setOptional(bool optional) {optional_ = optional;} |
120 |
– |
bool hasDefaultValue() {return defaultValue_;} |
121 |
– |
virtual bool isValid() { return true;} |
122 |
– |
const std::string& getKeyword() {return keyword_;} |
123 |
– |
void setKeyword(const std::string& keyword) { keyword_ = keyword;} |
124 |
– |
bool empty() {return empty_;} |
125 |
– |
virtual bool setData(std::string) = 0; |
126 |
– |
virtual bool setData(int) = 0; |
127 |
– |
virtual bool setData(double) = 0; |
128 |
– |
virtual std::string getParamType() = 0; |
129 |
– |
protected: |
130 |
– |
std::string keyword_; |
131 |
– |
bool optional_; |
132 |
– |
bool defaultValue_; |
133 |
– |
bool empty_; |
134 |
– |
}; |
135 |
– |
|
136 |
– |
template<class ParamType> |
137 |
– |
class Parameter : public ParameterBase{ |
138 |
– |
public: |
139 |
– |
typedef ParameterTraits<ParamType> ValueType; |
140 |
– |
void setDefaultValue(const ParamType& value) {data_ = value; defaultValue_ = true;} |
141 |
– |
ParamType getData() { return data_;} |
142 |
– |
|
143 |
– |
virtual bool setData(std::string sval) { |
144 |
– |
return internalSetData<std::string>(sval); |
145 |
– |
} |
146 |
– |
virtual bool setData(int ival) { |
147 |
– |
return internalSetData<int>(ival); |
148 |
– |
} |
149 |
– |
|
150 |
– |
virtual bool setData(double dval) { |
151 |
– |
return internalSetData<double>(dval); |
152 |
– |
} |
153 |
– |
|
154 |
– |
virtual std::string getParamType() { return ParameterTraits<ParamType>::getParamType();} |
155 |
– |
private: |
156 |
– |
template<class T> bool internalSetData(T data) { |
157 |
– |
ParamType tmp; |
158 |
– |
bool result = ValueType::convert(data, tmp); |
159 |
– |
if (result) { |
160 |
– |
empty_ = false; |
161 |
– |
data_ = tmp; |
162 |
– |
} |
163 |
– |
return result; |
164 |
– |
} |
165 |
– |
|
166 |
– |
private: |
167 |
– |
ParamType data_; |
168 |
– |
|
169 |
– |
}; |
170 |
– |
|
171 |
– |
#define DeclareParameter(NAME, TYPE) \ |
172 |
– |
private: \ |
173 |
– |
Parameter<TYPE> NAME; \ |
174 |
– |
public: \ |
175 |
– |
bool have##NAME() { return !NAME.empty();} \ |
176 |
– |
TYPE get##NAME() { return NAME.getData();} |
177 |
– |
|
178 |
– |
|
59 |
|
class Globals { |
60 |
|
public: |
61 |
|
Globals(); |
118 |
|
DeclareParameter(SurfaceTension, double); |
119 |
|
DeclareParameter(PrintPressureTensor, bool); |
120 |
|
DeclareParameter(ElectrostaticSummationMethod, std::string); |
121 |
+ |
DeclareParameter(ElectrostaticScreeningMethod, std::string); |
122 |
|
DeclareParameter(DampingAlpha, double); |
123 |
|
DeclareParameter(CutoffPolicy, std::string); |
124 |
+ |
DeclareParameter(SwitchingFunctionType, std::string); |
125 |
|
DeclareParameter(CompressDumpFile, bool); |
126 |
+ |
DeclareParameter(OutputForceVector, bool); |
127 |
|
DeclareParameter(SkinThickness, double); |
128 |
|
DeclareParameter(StatFileFormat, std::string); |
129 |
|
|