| 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 |
– |
}; |
| 70 |
– |
//bool |
| 71 |
– |
template<> |
| 72 |
– |
struct ParameterTraits<bool>{ |
| 73 |
– |
typedef bool RepType; |
| 74 |
– |
template<typename T> static bool convert(T, RepType&){return false;} |
| 75 |
– |
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
| 76 |
– |
static bool convert(std::string v, RepType& r) { |
| 77 |
– |
oopse::toLower(v); |
| 78 |
– |
bool result = false; |
| 79 |
– |
if (v == "true") { |
| 80 |
– |
r = true; |
| 81 |
– |
result = true; |
| 82 |
– |
} else if (v == "false") { |
| 83 |
– |
r = false; |
| 84 |
– |
result = true; |
| 85 |
– |
} |
| 86 |
– |
|
| 87 |
– |
return result; |
| 88 |
– |
} |
| 89 |
– |
}; |
| 90 |
– |
|
| 91 |
– |
//int |
| 92 |
– |
template<> |
| 93 |
– |
struct ParameterTraits<int>{ |
| 94 |
– |
typedef int RepType; |
| 95 |
– |
template<typename T> static bool convert(T, RepType&){return false;} |
| 96 |
– |
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
| 97 |
– |
static bool convert(RepType v, RepType& r) { r=v; return true;} |
| 98 |
– |
}; |
| 99 |
– |
|
| 100 |
– |
//double |
| 101 |
– |
template<> |
| 102 |
– |
struct ParameterTraits<double>{ |
| 103 |
– |
typedef double RepType; |
| 104 |
– |
template<typename T> static bool convert(T, RepType&){return false;} |
| 105 |
– |
template<typename T> static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} |
| 106 |
– |
static bool convert(RepType v, RepType& r) {r=v; return true;} |
| 107 |
– |
static bool convert(int v, RepType& r) {r = static_cast<double>(v); return true;} |
| 108 |
– |
}; |
| 109 |
– |
|
| 110 |
– |
|
| 111 |
– |
class ParameterBase { |
| 112 |
– |
public: |
| 113 |
– |
ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {} |
| 114 |
– |
bool isOptional() {return optional_;} |
| 115 |
– |
void setOptional(bool optional) {optional_ = optional;} |
| 116 |
– |
bool hasDefaultValue() {return defaultValue_;} |
| 117 |
– |
virtual bool isValid() { return true;} |
| 118 |
– |
const std::string& getKeyword() {return keyword_;} |
| 119 |
– |
void setKeyword(const std::string& keyword) { keyword_ = keyword;} |
| 120 |
– |
bool empty() {return empty_;} |
| 121 |
– |
virtual bool setData(std::string) = 0; |
| 122 |
– |
virtual bool setData(int) = 0; |
| 123 |
– |
virtual bool setData(double) = 0; |
| 124 |
– |
|
| 125 |
– |
protected: |
| 126 |
– |
std::string keyword_; |
| 127 |
– |
bool optional_; |
| 128 |
– |
bool defaultValue_; |
| 129 |
– |
bool empty_; |
| 130 |
– |
}; |
| 131 |
– |
|
| 132 |
– |
template<class ParamType> |
| 133 |
– |
class Parameter : public ParameterBase{ |
| 134 |
– |
public: |
| 135 |
– |
typedef ParameterTraits<ParamType> ValueType; |
| 136 |
– |
void setDefaultValue(const ParamType& value) {data_ = value; defaultValue_ = true;} |
| 137 |
– |
ParamType getData() { return data_;} |
| 138 |
– |
|
| 139 |
– |
virtual bool setData(std::string sval) { |
| 140 |
– |
return internalSetData<std::string>(sval); |
| 141 |
– |
} |
| 142 |
– |
virtual bool setData(int ial) { |
| 143 |
– |
return internalSetData<int>(ial); |
| 144 |
– |
} |
| 145 |
– |
|
| 146 |
– |
virtual bool setData(double dval) { |
| 147 |
– |
return internalSetData<double>(dval); |
| 148 |
– |
} |
| 149 |
– |
|
| 150 |
– |
private: |
| 151 |
– |
template<class T> bool internalSetData(T data) { |
| 152 |
– |
ParamType tmp; |
| 153 |
– |
bool result = ValueType::convert(data, tmp); |
| 154 |
– |
if (result) { |
| 155 |
– |
empty_ = false; |
| 156 |
– |
data_ = tmp; |
| 157 |
– |
} |
| 158 |
– |
return result; |
| 159 |
– |
} |
| 160 |
– |
|
| 161 |
– |
private: |
| 162 |
– |
ParamType data_; |
| 163 |
– |
|
| 164 |
– |
}; |
| 165 |
– |
|
| 166 |
– |
#define DeclareParameter(NAME, TYPE) \ |
| 167 |
– |
private: \ |
| 168 |
– |
Parameter<TYPE> NAME; \ |
| 169 |
– |
public: \ |
| 170 |
– |
bool have##NAME() { return !NAME.empty();} \ |
| 171 |
– |
TYPE get##NAME() { return NAME.getData();} |
| 172 |
– |
|
| 173 |
– |
|
| 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 |
|
|