Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 25, 2021
1 parent be82b65 commit 895c11a
Show file tree
Hide file tree
Showing 4 changed files with 399 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/eez/flow/private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,15 @@ void assignValue(FlowState *flowState, int componentIndex, Value &dstValue, cons
pDstValue->floatValue = srcValue.toFloat();
} else if (pDstValue->isDouble()) {
pDstValue->doubleValue = srcValue.toDouble();
} else if (pDstValue->isAnyStringType()) {
*pDstValue = srcValue.toString(0x30a91156);
} else {
char errorMessage[100];
snprintf(errorMessage, sizeof(errorMessage), "Can not assign %s to %s\n",
g_valueTypeNames[pDstValue->type](*pDstValue), g_valueTypeNames[srcValue.type](srcValue)
);
throwError(flowState, componentIndex, errorMessage);
}

// TODO

onValueChanged(pDstValue);
}
Expand Down
122 changes: 122 additions & 0 deletions src/eez/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ void UNDEFINED_value_to_text(const Value &value, char *text, int count) {
*text = 0;
}

const char *UNDEFINED_value_type_name(const Value &value) {
return "undefined";
}

bool compare_NULL_value(const Value &a, const Value &b) {
return true;
}
Expand All @@ -60,6 +64,10 @@ void NULL_value_to_text(const Value &value, char *text, int count) {
*text = 0;
}

const char *NULL_value_type_name(const Value &value) {
return "null";
}

bool compare_BOOLEAN_value(const Value &a, const Value &b) {
return a.getInt() == b.getInt();
}
Expand All @@ -68,6 +76,10 @@ void BOOLEAN_value_to_text(const Value &value, char *text, int count) {
stringAppendInt(text, count, value.getInt());
}

const char *BOOLEAN_value_type_name(const Value &value) {
return "boolean";
}

bool compare_INT8_value(const Value &a, const Value &b) {
return a.getInt8() == b.getInt8();
}
Expand All @@ -76,6 +88,10 @@ void INT8_value_to_text(const Value &value, char *text, int count) {
stringAppendInt(text, count, value.getInt8());
}

const char *INT8_value_type_name(const Value &value) {
return "int8";
}

bool compare_UINT8_value(const Value &a, const Value &b) {
return a.getUInt8() == b.getUInt8();
}
Expand All @@ -84,6 +100,10 @@ void UINT8_value_to_text(const Value &value, char *text, int count) {
stringAppendUInt32(text, count, value.getUInt8());
}

const char *UINT8_value_type_name(const Value &value) {
return "uint8";
}

bool compare_INT16_value(const Value &a, const Value &b) {
return a.getInt16() == b.getInt16();
}
Expand All @@ -92,6 +112,10 @@ void INT16_value_to_text(const Value &value, char *text, int count) {
stringAppendInt(text, count, value.getInt16());
}

const char *INT16_value_type_name(const Value &value) {
return "int16";
}

bool compare_UINT16_value(const Value &a, const Value &b) {
return a.getUInt16() == b.getUInt16();
}
Expand All @@ -100,6 +124,10 @@ void UINT16_value_to_text(const Value &value, char *text, int count) {
stringAppendUInt32(text, count, value.getUInt16());
}

const char *UINT16_value_type_name(const Value &value) {
return "uint16";
}

bool compare_INT32_value(const Value &a, const Value &b) {
return a.getInt32() == b.getInt32();
}
Expand All @@ -108,6 +136,10 @@ void INT32_value_to_text(const Value &value, char *text, int count) {
stringAppendInt(text, count, value.getInt32());
}

const char *INT32_value_type_name(const Value &value) {
return "int32";
}

bool compare_UINT32_value(const Value &a, const Value &b) {
return a.getUInt32() == b.getUInt32();
}
Expand All @@ -116,6 +148,10 @@ void UINT32_value_to_text(const Value &value, char *text, int count) {
stringAppendUInt32(text, count, value.getUInt32());
}

const char *UINT32_value_type_name(const Value &value) {
return "uint32";
}

bool compare_INT64_value(const Value &a, const Value &b) {
return a.getInt64() == b.getInt64();
}
Expand All @@ -124,6 +160,10 @@ void INT64_value_to_text(const Value &value, char *text, int count) {
stringAppendInt64(text, count, value.getInt64());
}

const char *INT64_value_type_name(const Value &value) {
return "int64";
}

bool compare_UINT64_value(const Value &a, const Value &b) {
return a.getUInt64() == b.getUInt64();
}
Expand All @@ -132,6 +172,10 @@ void UINT64_value_to_text(const Value &value, char *text, int count) {
stringAppendUInt64(text, count, value.getUInt64());
}

const char *UINT64_value_type_name(const Value &value) {
return "uint64";
}

bool compare_FLOAT_value(const Value &a, const Value &b) {
return a.getUnit() == b.getUnit() && a.getFloat() == b.getFloat() && a.getOptions() == b.getOptions();
}
Expand Down Expand Up @@ -289,6 +333,10 @@ void FLOAT_value_to_text(const Value &value, char *text, int count) {
}
}

const char *FLOAT_value_type_name(const Value &value) {
return "float";
}

bool compare_DOUBLE_value(const Value &a, const Value &b) {
return a.getUnit() == b.getUnit() && a.getDouble() == b.getDouble() && a.getOptions() == b.getOptions();
}
Expand Down Expand Up @@ -446,6 +494,10 @@ void DOUBLE_value_to_text(const Value &value, char *text, int count) {
}
}

const char *DOUBLE_value_type_name(const Value &value) {
return "double";
}

bool compare_STRING_value(const Value &a, const Value &b) {
const char *astr = a.getString();
const char *bstr = b.getString();
Expand All @@ -467,6 +519,10 @@ void STRING_value_to_text(const Value &value, char *text, int count) {
}
}

const char *STRING_value_type_name(const Value &value) {
return "string";
}

bool compare_ARRAY_value(const Value &a, const Value &b) {
return a.arrayValue == b.arrayValue;
}
Expand All @@ -475,6 +531,10 @@ void ARRAY_value_to_text(const Value &value, char *text, int count) {
text[0] = 0;
}

const char *ARRAY_value_type_name(const Value &value) {
return "array";
}

bool compare_STRING_REF_value(const Value &a, const Value &b) {
return compare_STRING_value(a, b);
}
Expand All @@ -483,6 +543,10 @@ void STRING_REF_value_to_text(const Value &value, char *text, int count) {
STRING_value_to_text(value, text, count);
}

const char *STRING_REF_value_type_name(const Value &value) {
return "string";
}

bool compare_VERSIONED_STRING_value(const Value &a, const Value &b) {
return a.unit == b.unit; // here unit is used as string version
}
Expand All @@ -496,6 +560,10 @@ void VERSIONED_STRING_value_to_text(const Value &value, char *text, int count) {
}
}

const char *VERSIONED_STRING_value_type_name(const Value &value) {
return "versioned-string";
}

bool compare_VALUE_PTR_value(const Value &a, const Value &b) {
return a.pValueValue == b.pValueValue || (a.pValueValue && b.pValueValue && *a.pValueValue == *b.pValueValue);
}
Expand All @@ -508,6 +576,14 @@ void VALUE_PTR_value_to_text(const Value &value, char *text, int count) {
}
}

const char *VALUE_PTR_value_type_name(const Value &value) {
if (value.pValueValue) {
return g_valueTypeNames[value.pValueValue->type](value.pValueValue);
} else {
return "null";
}
}

bool compare_FLOW_OUTPUT_value(const Value &a, const Value &b) {
return a.getUInt16() == b.getUInt16();
}
Expand All @@ -516,6 +592,10 @@ void FLOW_OUTPUT_value_to_text(const Value &value, char *text, int count) {
text[0] = 0;
}

const char *FLOW_OUTPUT_value_type_name(const Value &value) {
return "internal";
}

bool compare_RANGE_value(const Value &a, const Value &b) {
return a.getUInt32() == b.getUInt32();
}
Expand All @@ -524,6 +604,10 @@ void RANGE_value_to_text(const Value &value, char *text, int count) {
text[0] = 0;
}

const char *RANGE_value_type_name(const Value &value) {
return "internal";
}

bool compare_PASSWORD_value(const Value &a, const Value &b) {
return strlen(a.getString()) == strlen(b.getString());
}
Expand All @@ -537,6 +621,10 @@ void PASSWORD_value_to_text(const Value &value, char *text, int count) {
text[i] = 0;
}

const char *PASSWORD_value_type_name(const Value &value) {
return "internal";
}

bool compare_ENUM_value(const Value &a, const Value &b) {
return a.getEnum().enumDefinition == b.getEnum().enumDefinition &&
a.getEnum().enumValue == b.getEnum().enumValue;
Expand All @@ -556,6 +644,10 @@ void ENUM_value_to_text(const Value &value, char *text, int count) {
}
}

const char *ENUM_value_type_name(const Value &value) {
return "internal";
}

bool compare_PERCENTAGE_value(const Value &a, const Value &b) {
return a.getInt() == b.getInt();
}
Expand All @@ -565,6 +657,10 @@ void PERCENTAGE_value_to_text(const Value &value, char *text, int count) {
text[count - 1] = 0;
}

const char *PERCENTAGE_value_type_name(const Value &value) {
return "internal";
}

bool compare_SIZE_value(const Value &a, const Value &b) {
return a.getUInt32() == b.getUInt32();
}
Expand All @@ -574,6 +670,10 @@ void SIZE_value_to_text(const Value &value, char *text, int count) {
text[count - 1] = 0;
}

const char *SIZE_value_type_name(const Value &value) {
return "internal";
}

bool compare_POINTER_value(const Value &a, const Value &b) {
return a.getVoidPointer() == b.getVoidPointer();
}
Expand All @@ -582,6 +682,10 @@ void POINTER_value_to_text(const Value &value, char *text, int count) {
text[0] = 0;
}

const char *POINTER_value_type_name(const Value &value) {
return "internal";
}

bool compare_TIME_SECONDS_value(const Value &a, const Value &b) {
return a.getUInt32() == b.getUInt32();
}
Expand All @@ -596,6 +700,10 @@ void TIME_SECONDS_value_to_text(const Value &value, char *text, int count) {
text[count - 1] = 0;
}

const char *TIME_SECONDS_value_type_name(const Value &value) {
return "internal";
}

bool compare_YT_DATA_GET_VALUE_FUNCTION_POINTER_value(const Value &a, const Value &b) {
return a.getUInt32() == b.getUInt32();
}
Expand All @@ -604,6 +712,10 @@ void YT_DATA_GET_VALUE_FUNCTION_POINTER_value_to_text(const Value &value, char *
text[0] = 0;
}

const char *YT_DATA_GET_VALUE_FUNCTION_POINTER_value_type_name(const Value &value) {
return "internal";
}

////////////////////////////////////////////////////////////////////////////////

#define VALUE_TYPE(NAME) bool compare_##NAME##_value(const Value &a, const Value &b);
Expand All @@ -627,6 +739,16 @@ ValueToTextFunction g_valueTypeToTextFunctions[] = {
};
#undef VALUE_TYPE

#define VALUE_TYPE(NAME) const char * NAME##_value_type_name(const Value &value);
VALUE_TYPES
#undef VALUE_TYPE

#define VALUE_TYPE(NAME) NAME##_value_type_name,
ValueTypeNameFunction g_valueTypeNames[] = {
VALUE_TYPES
};
#undef VALUE_TYPE

////////////////////////////////////////////////////////////////////////////////

uint16_t getPageIndexFromValue(const Value &value) {
Expand Down
2 changes: 2 additions & 0 deletions src/eez/gui/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,11 @@ struct StringRef : public Ref {

typedef bool (*CompareValueFunction)(const Value &a, const Value &b);
typedef void (*ValueToTextFunction)(const Value &value, char *text, int count);
typedef const char * (*ValueTypeNameFunction)(const Value &value);

extern CompareValueFunction g_valueTypeCompareFunctions[];
extern ValueToTextFunction g_valueTypeToTextFunctions[];
extern ValueTypeNameFunction g_valueTypeNames[];

////////////////////////////////////////////////////////////////////////////////

Expand Down
Loading

0 comments on commit 895c11a

Please sign in to comment.