This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/mapview/model/IHasParams.h
2018-10-25 12:19:36 +02:00

136 lines
3.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#ifndef IHASPARAMS_H
#define IHASPARAMS_H
#include <Indoor/floorplan/v2/Floorplan.h>
#include <Indoor/geo/Point2.h>
#include <Indoor/geo/Point3.h>
enum class ParamType {
NOT_AVAILABLE,
BOOL,
INT,
FLOAT,
DOUBLE,
STRING,
FILE,
POINT2,
POINT3,
ENUM,
};
class ParamValue {
private:
union {
bool _bool;
int _int;
float _float;
double _double;
float _arr[3];
};
std::string _str;
public:
template <typename T> ParamValue(const T val) {
setValue(val);
}
void setValue(const std::string& val) {_str = val;}
void setValue(const float val) {_float = val;}
void setValue(const double val) {_double = val;}
void setValue(const int val) {_int = val;}
void setValue(const bool val) {_bool = val;}
void setValue(const Point2 p) {_arr[0] = p.x; _arr[1] = p.y;}
void setValue(const Point3 p) {_arr[0] = p.x; _arr[1] = p.y; _arr[2] = p.z;}
Point2 toPoint2() const {return Point2(_arr[0], _arr[1]);}
Point3 toPoint3() const {return Point3(_arr[0], _arr[1], _arr[2]);}
std::string toString() const {return _str;}
float toFloat() const {return _float;}
double toDouble() const {return _double;}
int toInt() const {return _int;}
bool toBool() const {return _bool;}
};
//union ParamValue {
// int _int;
// float _float;
// std::string _string;
// template <typename T> ParamValue(const T val) {
// setValue(val);
// }
// int toInt() const {return _int;}
// float toFloat() const {return _float;}
// const std::string& toString() const {return _string;}
// void setValue(const float val) {_float = val;}
// void setValue(const int val) {_int = val;}
// void setValue(const std::string& val) {_string = val;}
//};
struct Param {
/** parameter name */
std::string name;
/** parameter type */
ParamType type;
/** read-only parameter? */
bool readOnly;
std::vector<std::string> enumValues;
/** ctor */
Param(const std::string& name, const ParamType type, const bool readOnly = false) : name(name), type(type), readOnly(readOnly) {;}
/** ctor */
Param(const std::string& name, const ParamType type, const std::vector<std::string>& enumValues) : name(name), type(type), readOnly(false), enumValues(enumValues) {;}
/** special parameter */
static Param getNA() { return Param("", ParamType::NOT_AVAILABLE); }
/** get all supported enum values */
const std::vector<std::string>& getEnumValues() const {return enumValues;}
};
/** free parameters */
class IHasParams {
public:
/** get the number of parameters */
virtual int getNumParams() const = 0;
/** get the description of the idx-th parameter */
virtual Param getParamDesc(const int idx) const = 0;
/** get the idx-th param's value */
virtual ParamValue getParamValue(const int idx) const = 0;
/** set the idx-th param's value */
virtual void setParamValue(const int idx, const ParamValue& val) = 0;
};
#endif // IHASPARAMS_H