18 #ifndef PROJECT_CONTROLPAREMETERS_H 19 #define PROJECT_CONTROLPAREMETERS_H 27 #define CONTROL_PARAMETER_MAXIMUM_NAME_LENGTH 64 29 #define INIT_PARAMETER(name) param_##name(#name, name, collection) 30 #define DECLARE_PARAMETER(type, name) \ 32 ControlParameter param_##name; 83 "[ERROR] ControlParameterCollection %s: tried to add parameter %s " 85 _name.c_str(), name.c_str());
86 throw std::runtime_error(
"control parameter error");
100 throw std::runtime_error(
"parameter " + name +
101 " wasn't found in parameter collection " +
108 std::string printToYamlString();
109 bool checkIfAllSet();
114 std::map<std::string, ControlParameter*>
_map;
129 const std::string& units =
"") {
140 const std::string& units =
"") {
151 const std::string& units =
"") {
162 const std::string& units =
"") {
166 _value.vec3f = value.data();
173 const std::string& units =
"") {
177 _value.vec3d = value.data();
186 _value.vec3d = (
double*)&_staticValue;
191 printf(
"[Error] name %s is too long, shortening to ", _name.c_str());
193 printf(
"%s\n", _name.c_str());
203 throw std::runtime_error(
"Tried to initialize control parameter " +
204 _name +
" as a double!");
214 throw std::runtime_error(
"Tried to initialize control parameter " +
215 _name +
" as a float!");
223 throw std::runtime_error(
"Tried to initialize control parameter " +
224 _name +
" as an integer!");
232 throw std::runtime_error(
"Tried to initialize control parameter " +
233 _name +
" as a vector3f");
236 _value.vec3f[0] = v[0];
237 _value.vec3f[1] = v[1];
238 _value.vec3f[2] = v[2];
243 throw std::runtime_error(
"Tried to initialize control parameter " +
244 _name +
" as a vector3d");
247 _value.vec3d[0] = v[0];
248 _value.vec3d[1] = v[1];
249 _value.vec3d[2] = v[2];
254 throw std::runtime_error(
"type mismatch in set");
267 _value.vec3f[0] = value.vec3f[0];
268 _value.vec3f[1] = value.vec3f[1];
269 _value.vec3f[2] = value.vec3f[2];
272 _value.vec3d[0] = value.vec3d[0];
273 _value.vec3d[1] = value.vec3d[1];
274 _value.vec3d[2] = value.vec3d[2];
277 throw std::runtime_error(
"invalid kind");
285 throw std::runtime_error(
"type mismatch in get");
298 value.
vec3f[0] = _value.vec3f[0];
299 value.
vec3f[1] = _value.vec3f[1];
300 value.
vec3f[2] = _value.vec3f[2];
303 value.
vec3d[0] = _value.vec3d[0];
304 value.
vec3d[1] = _value.vec3d[1];
305 value.
vec3d[2] = _value.vec3d[2];
308 throw std::runtime_error(
"invalid kind");
326 result += std::to_string(*_value.i);
341 result +=
"<unknown type " + std::to_string((
u32)(_kind)) +
342 "> (add it yourself in ControlParameters.h!)";
351 *_value.d = std::stod(value);
354 *_value.f = std::stof(value);
357 *_value.i = std::stoll(value);
361 _value.vec3f[0] = v[0];
362 _value.vec3f[1] = v[1];
363 _value.vec3f[2] = v[2];
367 _value.vec3d[0] = v[0];
368 _value.vec3d[1] = v[1];
369 _value.vec3d[2] = v[2];
409 collection.lookup(name).initializeDouble(d);
413 collection.lookup(name).initializeFloat(f);
417 collection.lookup(name).initializeInteger(i);
421 collection.lookup(name).initializeVec3f(v);
425 collection.lookup(name).initializeVec3d(v);
432 void writeToIniFile(
const std::string& path);
433 void initializeFromIniFile(
const std::string& path);
434 void initializeFromYamlFile(
const std::string& path);
435 void defineAndInitializeFromYamlFile(
const std::string& path);
437 void writeToYamlFile(
const std::string& path);
439 std::string generateUnitializedList();
448 #endif // PROJECT_CONTROLPAREMETERS_H Common types that are only valid in C++.
ControlParameter(const std::string &name, s64 &value, ControlParameterCollection &collection, const std::string &units="")
ControlParameterCollection collection
ControlParameterValueKind _kind
ControlParameterValueKind
std::string controlParameterValueKindToString(ControlParameterValueKind valueKind)
std::map< std::string, ControlParameter * > _map
ControlParameterCollection(const std::string &name)
ControlParameterValue _staticValue
bool isFullyInitialized()
std::string numberToString(T number)
typename Eigen::Matrix< T, 3, 1 > Vec3
ControlParameterValuePtr _value
ControlParameter(const std::string &name, float &value, ControlParameterCollection &collection, const std::string &units="")
void initializeDouble(const std::string &name, double d)
void initializeVec3d(const Vec3< double > &v)
void initializeInteger(s64 i)
void initializeDouble(double d)
#define CONTROL_PARAMETER_MAXIMUM_NAME_LENGTH
void initializeVec3d(const std::string &name, Vec3< double > &v)
void initializeInteger(const std::string &name, s64 i)
ControlParameter(const std::string &name, ControlParameterValueKind kind)
ControlParameter & lookup(const std::string &name)
ControlParameter(const std::string &name, Vec3< float > &value, ControlParameterCollection &collection, const std::string &units="")
std::string controlParameterValueToString(ControlParameterValue v, ControlParameterValueKind kind)
void initializeFloat(const std::string &name, float f)
void initializeVec3f(const Vec3< float > &v)
void initializeFloat(float f)
void initializeVec3f(const std::string &name, Vec3< float > &v)
ControlParameter(const std::string &name, double &value, ControlParameterCollection &collection, const std::string &units="")
ControlParameterValueKind getControlParameterValueKindFromString(const std::string &str)
bool setFromString(const std::string &value)
void addParameter(ControlParameter *param, const std::string &name)
ControlParameter(const std::string &name, Vec3< double > &value, ControlParameterCollection &collection, const std::string &units="")
bool mapContains(const std::map< T1, T2 > &set, T1 key)
ControlParameters(const std::string &name)
MX f(const MX &x, const MX &u)