aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Model/Workflow/Value_RTTI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'app/source/Cplt/Model/Workflow/Value_RTTI.cpp')
-rw-r--r--app/source/Cplt/Model/Workflow/Value_RTTI.cpp174
1 files changed, 174 insertions, 0 deletions
diff --git a/app/source/Cplt/Model/Workflow/Value_RTTI.cpp b/app/source/Cplt/Model/Workflow/Value_RTTI.cpp
new file mode 100644
index 0000000..a2a6960
--- /dev/null
+++ b/app/source/Cplt/Model/Workflow/Value_RTTI.cpp
@@ -0,0 +1,174 @@
+#include "Value.hpp"
+
+#include <Cplt/Model/Workflow/Values/Basic.hpp>
+#include <Cplt/Model/Workflow/Values/Database.hpp>
+#include <Cplt/Model/Workflow/Values/Dictionary.hpp>
+#include <Cplt/Model/Workflow/Values/List.hpp>
+#include <Cplt/UI/UI.hpp>
+#include <Cplt/Utils/I18n.hpp>
+
+constexpr BaseValue::KindInfo kEmptyInfo{
+ .PinIcon = ImGui::IconType::Circle,
+ .PinColor = RgbaColor(),
+};
+
+constexpr BaseValue::KindInfo kNumericInfo{
+ .PinIcon = ImGui::IconType::Circle,
+ .PinColor = RgbaColor(147, 226, 74),
+};
+
+constexpr BaseValue::KindInfo kTextInfo{
+ .PinIcon = ImGui::IconType::Circle,
+ .PinColor = RgbaColor(124, 21, 153),
+};
+
+constexpr BaseValue::KindInfo kDateTimeInfo{
+ .PinIcon = ImGui::IconType::Circle,
+ .PinColor = RgbaColor(147, 226, 74),
+};
+
+constexpr BaseValue::KindInfo kDatabaseRowIdInfo{
+ .PinIcon = ImGui::IconType::Circle,
+ .PinColor = RgbaColor(216, 42, 221),
+};
+
+constexpr BaseValue::KindInfo kListInfo{
+ .PinIcon = ImGui::IconType::Diamond,
+ .PinColor = RgbaColor(58, 154, 214),
+};
+
+constexpr BaseValue::KindInfo kDictionaryInfo{
+ .PinIcon = ImGui::IconType::Diamond,
+ .PinColor = RgbaColor(240, 240, 34),
+};
+
+constexpr BaseValue::KindInfo kDatabaseRowInfo{
+ .PinIcon = ImGui::IconType::Square,
+ .PinColor = RgbaColor(15, 124, 196),
+};
+
+constexpr BaseValue::KindInfo kObjectInfo{
+ .PinIcon = ImGui::IconType::Square,
+ .PinColor = RgbaColor(161, 161, 161),
+};
+
+const BaseValue::KindInfo& BaseValue::QueryInfo(BaseValue::Kind kind)
+{
+ switch (kind) {
+ case KD_Numeric: return kNumericInfo;
+ case KD_Text: return kTextInfo;
+ case KD_DateTime: return kDateTimeInfo;
+ case KD_DatabaseRowId: return kDatabaseRowIdInfo;
+ case KD_List: return kListInfo;
+ case KD_Dictionary: return kDictionaryInfo;
+
+ case KD_BaseObject: return kObjectInfo;
+ case KD_SaleDatabaseRow:
+ case KD_PurchaseDatabaseRow:
+ return kDatabaseRowInfo;
+
+ case InvalidKind: break;
+ }
+ return kEmptyInfo;
+}
+
+const char* BaseValue::Format(Kind kind)
+{
+ switch (kind) {
+ case KD_Numeric: return I18N_TEXT("Numeric", L10N_VALUE_NUMERIC);
+ case KD_Text: return I18N_TEXT("Text", L10N_VALUE_TEXT);
+ case KD_DateTime: return I18N_TEXT("Date/time", L10N_VALUE_DATE_TIME);
+ case KD_DatabaseRowId: return I18N_TEXT("Row id", L10N_VALUE_ROW_ID);
+ case KD_List: return I18N_TEXT("List", L10N_VALUE_LIST);
+ case KD_Dictionary: return I18N_TEXT("Dictionary", L10N_VALUE_DICT);
+
+ case KD_BaseObject: return I18N_TEXT("Object", L10N_VALUE_OBJECT);
+ case KD_SaleDatabaseRow: return I18N_TEXT("Sale record", L10N_VALUE_SALE_RECORD);
+ case KD_PurchaseDatabaseRow: return I18N_TEXT("Purchase record", L10N_VALUE_PURCHASE_RECORD);
+
+ case InvalidKind: break;
+ }
+ return "";
+}
+
+std::unique_ptr<BaseValue> BaseValue::CreateByKind(BaseValue::Kind kind)
+{
+ switch (kind) {
+ case KD_Numeric: return std::make_unique<NumericValue>();
+ case KD_Text: return std::make_unique<TextValue>();
+ case KD_DateTime: return std::make_unique<DateTimeValue>();
+ case KD_DatabaseRowId: return std::make_unique<DatabaseRowIdValue>();
+ case KD_List: return std::make_unique<ListValue>();
+ case KD_Dictionary: return std::make_unique<DictionaryValue>();
+
+ case KD_BaseObject: return nullptr;
+ case KD_SaleDatabaseRow: return std::make_unique<SaleDatabaseRowValue>();
+ case KD_PurchaseDatabaseRow: return std::make_unique<PurchaseDatabaseRowValue>();
+
+ case InvalidKind: break;
+ }
+ return nullptr;
+}
+
+bool BaseValue::IsInstance(const BaseValue* value)
+{
+ return true;
+}
+
+const BaseObjectDescription kEmptyObjectInfo{
+ .Properties = {},
+};
+
+const BaseObjectDescription kSaleDbRowObject{
+ .Properties = {
+ {
+ .Name = I18N_TEXT("Customer", L10N_VALUE_PROPERTY_CUSTOMER),
+ .Kind = BaseValue::KD_Text,
+ .Mutatable = false,
+ },
+ {
+ .Name = I18N_TEXT("Deadline", L10N_VALUE_PROPERTY_DEADLINE),
+ .Kind = BaseValue::KD_DateTime,
+ },
+ {
+ .Name = I18N_TEXT("Delivery time", L10N_VALUE_PROPERTY_DELIVERY_TIME),
+ .Kind = BaseValue::KD_DateTime,
+ },
+ },
+};
+
+const BaseObjectDescription kPurchaseDbRowObject{
+ .Properties = {
+ {
+ .Name = I18N_TEXT("Factory", L10N_VALUE_PROPERTY_FACTORY),
+ .Kind = BaseValue::KD_Text,
+ .Mutatable = false,
+ },
+ {
+ .Name = I18N_TEXT("Order time", L10N_VALUE_PROPERTY_ORDER_TIME),
+ .Kind = BaseValue::KD_DateTime,
+ },
+ {
+ .Name = I18N_TEXT("Delivery time", L10N_VALUE_PROPERTY_DELIVERY_TIME),
+ .Kind = BaseValue::KD_DateTime,
+ },
+ },
+};
+
+const BaseObjectDescription& BaseObjectValue::QueryObjectInfo(Kind kind)
+{
+ switch (kind) {
+ case KD_BaseObject: return kEmptyObjectInfo;
+ case KD_SaleDatabaseRow: return kSaleDbRowObject;
+ case KD_PurchaseDatabaseRow: return kPurchaseDbRowObject;
+
+ default: break;
+ }
+ return kEmptyObjectInfo;
+}
+
+bool BaseObjectValue::IsInstance(const BaseValue* value)
+{
+ return value->GetKind() >= KD_BaseObject &&
+ value->GetKind() <= KD_BaseObjectLast;
+}