mirror of
https://github.com/okalachev/flix.git
synced 2026-09-06 08:20:57 +00:00
Switch code style in Value definition a bit
This commit is contained in:
+12
-12
@@ -71,27 +71,27 @@ struct Value {
|
|||||||
enum { EMPTY, FLOAT, INT, BOOL, FLOAT_FN, INT_FN, BOOL_FN } type;
|
enum { EMPTY, FLOAT, INT, BOOL, FLOAT_FN, INT_FN, BOOL_FN } type;
|
||||||
union {
|
union {
|
||||||
void *pointer;
|
void *pointer;
|
||||||
float *_float;
|
float *float_;
|
||||||
int *_int;
|
int *int_;
|
||||||
bool *_bool;
|
bool *bool_;
|
||||||
float (*floatFn)();
|
float (*floatFn)();
|
||||||
int (*intFn)();
|
int (*intFn)();
|
||||||
bool (*boolFn)();
|
bool (*boolFn)();
|
||||||
};
|
};
|
||||||
|
|
||||||
Value() : type(EMPTY), pointer(nullptr) {};
|
Value() : type(EMPTY), pointer(nullptr) {};
|
||||||
Value(float *pt) : type(FLOAT), _float(pt) {};
|
Value(float *pt) : type(FLOAT), float_(pt) {};
|
||||||
Value(int *pt) : type(INT), _int(pt) {};
|
Value(int *pt) : type(INT), int_(pt) {};
|
||||||
Value(bool *pt) : type(BOOL), _bool(pt) {};
|
Value(bool *pt) : type(BOOL), bool_(pt) {};
|
||||||
Value(float (*fn)()) : type(FLOAT_FN), floatFn(fn) {};
|
Value(float (*fn)()) : type(FLOAT_FN), floatFn(fn) {};
|
||||||
Value(int (*fn)()) : type(INT_FN), intFn(fn) {};
|
Value(int (*fn)()) : type(INT_FN), intFn(fn) {};
|
||||||
Value(bool (*fn)()) : type(BOOL_FN), boolFn(fn) {};
|
Value(bool (*fn)()) : type(BOOL_FN), boolFn(fn) {};
|
||||||
|
|
||||||
float get() const {
|
float get() const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case FLOAT: return *_float;
|
case FLOAT: return *float_;
|
||||||
case INT: return *_int;
|
case INT: return *int_;
|
||||||
case BOOL: return *_bool ? 1 : 0;
|
case BOOL: return *bool_ ? 1 : 0;
|
||||||
case FLOAT_FN: return floatFn();
|
case FLOAT_FN: return floatFn();
|
||||||
case INT_FN: return intFn();
|
case INT_FN: return intFn();
|
||||||
case BOOL_FN: return boolFn() ? 1 : 0;
|
case BOOL_FN: return boolFn() ? 1 : 0;
|
||||||
@@ -101,9 +101,9 @@ struct Value {
|
|||||||
|
|
||||||
bool set(float value) const {
|
bool set(float value) const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case FLOAT: *_float = value; break;
|
case FLOAT: *float_ = value; break;
|
||||||
case INT: if (!isfinite(value)) return false; *_int = value; break;
|
case INT: if (!isfinite(value)) return false; *int_ = value; break;
|
||||||
case BOOL: *_bool = (value != 0); break;
|
case BOOL: *bool_ = (value != 0); break;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user