| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #ifndef RS_VARIABLE_H |
| | #define RS_VARIABLE_H |
| |
|
| | #include <QString> |
| | #include "rs.h" |
| | #include "rs_vector.h" |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | class RS_Variable { |
| | struct RS_VariableContents { |
| | QString s; |
| | int i=0; |
| | double d=0.; |
| | RS_Vector v{false}; |
| | }; |
| | public: |
| | |
| | RS_Variable() = default; |
| | RS_Variable(const RS_Vector& v, int c): |
| | code{c} |
| | { |
| | setVector(v); |
| | } |
| | RS_Variable(const QString& v, int c): |
| | code{c} |
| | { |
| | setString(v); |
| | } |
| | RS_Variable(int v, int c): |
| | code{c} |
| | { |
| | setInt(v); |
| | } |
| | RS_Variable(double v, int c): |
| | code{c} |
| | { |
| | setDouble(v); |
| | } |
| |
|
| |
|
| | void setString(const QString& str) { |
| | contents.s = str; |
| | type = RS2::VariableString; |
| | } |
| | void setInt(int i) { |
| | contents.i = i; |
| | type = RS2::VariableInt; |
| | } |
| | void setDouble(double d) { |
| | contents.d = d; |
| | type = RS2::VariableDouble; |
| | } |
| | void setVector(const RS_Vector& v) { |
| | contents.v = v; |
| | type = RS2::VariableVector; |
| | } |
| |
|
| | QString getString() const { |
| | return contents.s; |
| | } |
| | int getInt() const { |
| | return contents.i; |
| | } |
| | double getDouble() const { |
| | return contents.d; |
| | } |
| | RS_Vector getVector() const { |
| | return contents.v; |
| | } |
| |
|
| | RS2::VariableType getType() const { |
| | return type; |
| | } |
| | int getCode() const { |
| | return code; |
| | } |
| |
|
| | QString toString(); |
| |
|
| | |
| |
|
| | private: |
| | RS_VariableContents contents; |
| | RS2::VariableType type = RS2::VariableVoid; |
| | int code = 0; |
| | }; |
| |
|
| | inline QString RS_Variable::toString() { |
| | switch (type) { |
| | case RS2::VariableString: |
| | return contents.s; |
| | case RS2::VariableInt: |
| | return QString::number(contents.i); |
| | case RS2::VariableDouble: |
| | return QString::number(contents.d); |
| | case RS2::VariableVector: |
| | return QString::number(contents.v.x) + " " + QString::number(contents.v.y); |
| | default: |
| | return ""; |
| | } |
| | } |
| |
|
| | #endif |
| |
|