From 7a325e1b3be04bc54941431458903022da1643ac Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 3 Jun 2021 10:06:55 -0700 Subject: Create template inheritance hierarchy, object value RTTI system --- core/src/Model/Workflow/Nodes/DocumentNodes.cpp | 2 +- core/src/Model/Workflow/Nodes/NumericNodes.cpp | 2 +- core/src/Model/Workflow/Nodes/TextNodes.cpp | 2 +- core/src/Model/Workflow/Nodes/UserInputNodes.cpp | 2 +- core/src/Model/Workflow/Value.hpp | 38 ++++++++ core/src/Model/Workflow/ValueInternals.hpp | 21 ++++ core/src/Model/Workflow/Value_Main.cpp | 11 +++ core/src/Model/Workflow/Value_RTTI.cpp | 115 ++++++++++++++++++++-- core/src/Model/Workflow/Values/Basic.cpp | 117 +++++++++++++++++++++++ core/src/Model/Workflow/Values/Basic.hpp | 67 +++++++++++++ core/src/Model/Workflow/Values/BasicValues.cpp | 117 ----------------------- core/src/Model/Workflow/Values/BasicValues.hpp | 52 ---------- core/src/Model/Workflow/Values/Database.cpp | 88 +++++++++++++++++ core/src/Model/Workflow/Values/Database.hpp | 51 ++++++++++ core/src/Model/Workflow/Values/fwd.hpp | 10 +- core/src/Model/Workflow/Workflow.hpp | 2 + core/src/Model/Workflow/Workflow_RTTI.cpp | 12 ++- core/src/Model/Workflow/fwd.hpp | 1 + 18 files changed, 527 insertions(+), 183 deletions(-) create mode 100644 core/src/Model/Workflow/ValueInternals.hpp create mode 100644 core/src/Model/Workflow/Values/Basic.cpp create mode 100644 core/src/Model/Workflow/Values/Basic.hpp delete mode 100644 core/src/Model/Workflow/Values/BasicValues.cpp delete mode 100644 core/src/Model/Workflow/Values/BasicValues.hpp create mode 100644 core/src/Model/Workflow/Values/Database.cpp create mode 100644 core/src/Model/Workflow/Values/Database.hpp (limited to 'core/src/Model/Workflow') diff --git a/core/src/Model/Workflow/Nodes/DocumentNodes.cpp b/core/src/Model/Workflow/Nodes/DocumentNodes.cpp index 3925dec..6729c63 100644 --- a/core/src/Model/Workflow/Nodes/DocumentNodes.cpp +++ b/core/src/Model/Workflow/Nodes/DocumentNodes.cpp @@ -1,7 +1,7 @@ #include "DocumentNodes.hpp" #include "Model/Workflow/Evaluation.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" bool DocumentTemplateExpansionNode::IsInstance(const WorkflowNode* node) { diff --git a/core/src/Model/Workflow/Nodes/NumericNodes.cpp b/core/src/Model/Workflow/Nodes/NumericNodes.cpp index ad51fb4..f0d28b1 100644 --- a/core/src/Model/Workflow/Nodes/NumericNodes.cpp +++ b/core/src/Model/Workflow/Nodes/NumericNodes.cpp @@ -1,7 +1,7 @@ #include "NumericNodes.hpp" #include "Model/Workflow/Evaluation.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" #include "Utils/Macros.hpp" #include "Utils/RTTI.hpp" diff --git a/core/src/Model/Workflow/Nodes/TextNodes.cpp b/core/src/Model/Workflow/Nodes/TextNodes.cpp index e67b033..4628dd3 100644 --- a/core/src/Model/Workflow/Nodes/TextNodes.cpp +++ b/core/src/Model/Workflow/Nodes/TextNodes.cpp @@ -1,7 +1,7 @@ #include "TextNodes.hpp" #include "Model/Workflow/Evaluation.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" #include "Utils/Macros.hpp" #include "Utils/RTTI.hpp" #include "Utils/Variant.hpp" diff --git a/core/src/Model/Workflow/Nodes/UserInputNodes.cpp b/core/src/Model/Workflow/Nodes/UserInputNodes.cpp index f8d3e01..0b6d471 100644 --- a/core/src/Model/Workflow/Nodes/UserInputNodes.cpp +++ b/core/src/Model/Workflow/Nodes/UserInputNodes.cpp @@ -1,7 +1,7 @@ #include "UserInputNodes.hpp" #include "Model/Workflow/Evaluation.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" bool FormInputNode::IsInstance(const WorkflowNode* node) { diff --git a/core/src/Model/Workflow/Value.hpp b/core/src/Model/Workflow/Value.hpp index 8b3e63a..ff62d43 100644 --- a/core/src/Model/Workflow/Value.hpp +++ b/core/src/Model/Workflow/Value.hpp @@ -5,6 +5,7 @@ #include #include +#include class BaseValue { @@ -14,6 +15,12 @@ public: KD_Numeric, KD_Text, KD_DateTime, + KD_DatabaseRowId, + + KD_BaseObject, + KD_SaleDatabaseRow, + KD_PurchaseDatabaseRow, + KD_BaseObjectLast = KD_PurchaseDatabaseRow, /// An unspecified type, otherwise known as "any" in some contexts. InvalidKind, @@ -34,6 +41,8 @@ public: static const char* Format(Kind kind); static std::unique_ptr CreateByKind(Kind kind); + static bool IsInstance(const BaseValue* value); + BaseValue(Kind kind); virtual ~BaseValue() = default; @@ -51,3 +60,32 @@ public: virtual void ReadFrom(std::istream& stream); virtual void WriteTo(std::ostream& stream); }; + +class BaseObjectDescription +{ +public: + struct Property + { + std::string Name; + BaseValue::Kind Kind; + bool Mutatable = true; + }; + +public: + std::vector Properties; +}; + +class BaseObjectValue : public BaseValue +{ +public: + /// \param kind A value kind enum, within the range of KD_BaseObject and KD_BaseObjectLast (both inclusive). + static const BaseObjectDescription& QueryObjectInfo(Kind kind); + + static bool IsInstance(const BaseValue* value); + BaseObjectValue(Kind kind); + + const BaseObjectDescription& GetObjectDescription() const; + + virtual const BaseValue* GetProperty(int idx) const = 0; + virtual bool SetProperty(int idx, std::unique_ptr value) = 0; +}; diff --git a/core/src/Model/Workflow/ValueInternals.hpp b/core/src/Model/Workflow/ValueInternals.hpp new file mode 100644 index 0000000..49981f0 --- /dev/null +++ b/core/src/Model/Workflow/ValueInternals.hpp @@ -0,0 +1,21 @@ +// This file contains utility classes and macros for implementing values +// As consumers, you should not include this header as it contains unnecessary symbols and can pollute your files +// for this reason, classes here aren't forward-declared in fwd.hpp either. + +#pragma once + +#include "Utils/RTTI.hpp" + +#include + +#define CHECK_VALUE_TYPE(Type, value) \ + if (!is_a(value)) { \ + return false; \ + } + +#define CHECK_VALUE_TYPE_AND_MOVE(Type, dest, value) \ + if (auto ptr = dyn_cast(value)) { \ + dest = std::move(*ptr); \ + } else { \ + return false; \ + } diff --git a/core/src/Model/Workflow/Value_Main.cpp b/core/src/Model/Workflow/Value_Main.cpp index fdd2fd5..ca972c4 100644 --- a/core/src/Model/Workflow/Value_Main.cpp +++ b/core/src/Model/Workflow/Value_Main.cpp @@ -22,3 +22,14 @@ void BaseValue::ReadFrom(std::istream& stream) void BaseValue::WriteTo(std::ostream& stream) { } + +BaseObjectValue::BaseObjectValue(Kind kind) + : BaseValue(kind) +{ + assert(kind >= KD_BaseObject && kind <= KD_BaseObjectLast); +} + +const BaseObjectDescription& BaseObjectValue::GetObjectDescription() const +{ + return QueryObjectInfo(this->GetKind()); +} diff --git a/core/src/Model/Workflow/Value_RTTI.cpp b/core/src/Model/Workflow/Value_RTTI.cpp index 5e24ed7..44b047c 100644 --- a/core/src/Model/Workflow/Value_RTTI.cpp +++ b/core/src/Model/Workflow/Value_RTTI.cpp @@ -1,6 +1,7 @@ #include "Value.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" +#include "Model/Workflow/Values/Database.hpp" #include "UI/UI.hpp" constexpr BaseValue::KindInfo kNumericInfo{ @@ -13,19 +14,42 @@ constexpr BaseValue::KindInfo kTextInfo{ .PinColor = RgbaColor(124, 21, 153), }; -constexpr BaseValue::KindInfo kDateTimeInfo{ - .PinIcon = ImGui::IconType::Diamond, +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 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: break; - case KD_DateTime: break; + case KD_Text: return kTextInfo; + case KD_DateTime: return kDateTimeInfo; + case KD_DatabaseRowId: return kDatabaseRowIdInfo; + + case KD_BaseObject: return kObjectinfo; + case KD_SaleDatabaseRow: + case KD_PurchaseDatabaseRow: + return kDatabaseRowInfo; + case InvalidKind: break; } + // TODO provide info here } const char* BaseValue::Format(Kind kind) @@ -34,8 +58,15 @@ const char* BaseValue::Format(Kind kind) case KD_Numeric: return "Numeric"; case KD_Text: return "Text"; case KD_DateTime: return "Date/time"; - case InvalidKind: return ""; + case KD_DatabaseRowId: return "Row id"; + + case KD_BaseObject: return "Object"; + case KD_SaleDatabaseRow: return "Sale record"; + case KD_PurchaseDatabaseRow: return "Purchase record"; + + case InvalidKind: break; } + return ""; } std::unique_ptr BaseValue::CreateByKind(BaseValue::Kind kind) @@ -44,6 +75,76 @@ std::unique_ptr BaseValue::CreateByKind(BaseValue::Kind kind) case KD_Numeric: return std::make_unique(); case KD_Text: return std::make_unique(); case KD_DateTime: return std::make_unique(); - case InvalidKind: return nullptr; + case KD_DatabaseRowId: return std::make_unique(); + + case KD_BaseObject: return nullptr; + case KD_SaleDatabaseRow: return std::make_unique(); + case KD_PurchaseDatabaseRow: return std::make_unique(); + + case InvalidKind: break; + } + return nullptr; +} + +bool BaseValue::IsInstance(const BaseValue* value) +{ + return true; +} + +const BaseObjectDescription kEmptyObjectInfo{ + .Properties = {}, +}; + +const BaseObjectDescription kSaleDbRowObject{ + .Properties = { + { + .Name = "Customer", + .Kind = BaseValue::KD_Text, + .Mutatable = false, + }, + { + .Name = "Deadline", + .Kind = BaseValue::KD_DateTime, + }, + { + .Name = "Completion time", + .Kind = BaseValue::KD_DateTime, + }, + }, +}; + +const BaseObjectDescription kPurchaseDbRowObject{ + .Properties = { + { + .Name = "Factory", + .Kind = BaseValue::KD_Text, + .Mutatable = false, + }, + { + .Name = "Order time", + .Kind = BaseValue::KD_DateTime, + }, + { + .Name = "Arrival 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; } diff --git a/core/src/Model/Workflow/Values/Basic.cpp b/core/src/Model/Workflow/Values/Basic.cpp new file mode 100644 index 0000000..d6a2395 --- /dev/null +++ b/core/src/Model/Workflow/Values/Basic.cpp @@ -0,0 +1,117 @@ +#include "Basic.hpp" + +#include +#include +#include + +bool NumericValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_Numeric; +} + +NumericValue::NumericValue() + : BaseValue(BaseValue::KD_Numeric) +{ +} + +template +static std::string NumberToString(T value) +{ + char buf[kMaxSize]; + +#if PLATFORM_WIN32 + auto res = std::to_chars(buf, buf + kMaxSize, value); + if (res.ec == std::errc()) { + return std::string(buf, res.ptr); + } else { + return ""; + } +#else + // TODO libstdc++ doesn't have floating point charconv yet + return std::to_string(value); +#endif +} + +std::string NumericValue::GetTruncatedString() const +{ + constexpr auto kMaxSize = std::numeric_limits::digits10; + return ::NumberToString((int64_t)mValue); +} + +std::string NumericValue::GetRoundedString() const +{ + constexpr auto kMaxSize = std::numeric_limits::digits10; + return ::NumberToString((int64_t)std::round(mValue)); +} + +std::string NumericValue::GetString() const +{ + constexpr auto kMaxSize = std::numeric_limits::max_digits10; + return ::NumberToString(mValue); +} + +int64_t NumericValue::GetInt() const +{ + return static_cast(mValue); +} + +double NumericValue::GetValue() const +{ + return mValue; +} + +void NumericValue::SetValue(double value) +{ + mValue = value; +} + +bool TextValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_Text; +} + +TextValue::TextValue() + : BaseValue(BaseValue::KD_Text) +{ +} + +const std::string& TextValue::GetValue() const +{ + return mValue; +} + +void TextValue::SetValue(const std::string& value) +{ + mValue = value; +} + +bool DateTimeValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_DateTime; +} + +DateTimeValue::DateTimeValue() + : BaseValue(BaseValue::KD_DateTime) +{ +} + +std::string DateTimeValue::GetString() const +{ + namespace chrono = std::chrono; + auto t = chrono::system_clock::to_time_t(mValue); + + char data[32]; + std::strftime(data, sizeof(data), "%Y-%m-%d %H:%M:%S", std::localtime(&t)); + + return std::string(data); +} + +const std::chrono::time_point& DateTimeValue::GetValue() const +{ + return mValue; +} + +void DateTimeValue::SetValue(const std::chrono::time_point& value) +{ + mValue = value; +} diff --git a/core/src/Model/Workflow/Values/Basic.hpp b/core/src/Model/Workflow/Values/Basic.hpp new file mode 100644 index 0000000..38e0531 --- /dev/null +++ b/core/src/Model/Workflow/Values/Basic.hpp @@ -0,0 +1,67 @@ +#pragma once + +#include "Model/Workflow/Value.hpp" + +#include +#include +#include + +class NumericValue : public BaseValue +{ +private: + double mValue; + +public: + static bool IsInstance(const BaseValue* value); + NumericValue(); + + NumericValue(const NumericValue&) = delete; + NumericValue& operator=(const NumericValue&) = delete; + NumericValue(NumericValue&&) = default; + NumericValue& operator=(NumericValue&&) = default; + + std::string GetTruncatedString() const; + std::string GetRoundedString() const; + std::string GetString() const; + + int64_t GetInt() const; + double GetValue() const; + void SetValue(double value); +}; + +class TextValue : public BaseValue +{ +private: + std::string mValue; + +public: + static bool IsInstance(const BaseValue* value); + TextValue(); + + TextValue(const TextValue&) = delete; + TextValue& operator=(const TextValue&) = delete; + TextValue(TextValue&&) = default; + TextValue& operator=(TextValue&&) = default; + + const std::string& GetValue() const; + void SetValue(const std::string& value); +}; + +class DateTimeValue : public BaseValue +{ +private: + std::chrono::time_point mValue; + +public: + static bool IsInstance(const BaseValue* value); + DateTimeValue(); + + DateTimeValue(const DateTimeValue&) = delete; + DateTimeValue& operator=(const DateTimeValue&) = delete; + DateTimeValue(DateTimeValue&&) = default; + DateTimeValue& operator=(DateTimeValue&&) = default; + + std::string GetString() const; + const std::chrono::time_point& GetValue() const; + void SetValue(const std::chrono::time_point& value); +}; diff --git a/core/src/Model/Workflow/Values/BasicValues.cpp b/core/src/Model/Workflow/Values/BasicValues.cpp deleted file mode 100644 index 748c652..0000000 --- a/core/src/Model/Workflow/Values/BasicValues.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "BasicValues.hpp" - -#include -#include -#include - -bool NumericValue::IsInstance(const BaseValue* value) -{ - return value->GetKind() == KD_Numeric; -} - -NumericValue::NumericValue() - : BaseValue(BaseValue::KD_Numeric) -{ -} - -template -static std::string NumberToString(T value) -{ - char buf[kMaxSize]; - -#if PLATFORM_WIN32 - auto res = std::to_chars(buf, buf + kMaxSize, value); - if (res.ec == std::errc()) { - return std::string(buf, res.ptr); - } else { - return ""; - } -#else - // TODO libstdc++ doesn't have floating point charconv yet - return std::to_string(value); -#endif -} - -std::string NumericValue::GetTruncatedString() const -{ - constexpr auto kMaxSize = std::numeric_limits::digits10; - return ::NumberToString((int64_t)mValue); -} - -std::string NumericValue::GetRoundedString() const -{ - constexpr auto kMaxSize = std::numeric_limits::digits10; - return ::NumberToString((int64_t)std::round(mValue)); -} - -std::string NumericValue::GetString() const -{ - constexpr auto kMaxSize = std::numeric_limits::max_digits10; - return ::NumberToString(mValue); -} - -int64_t NumericValue::GetInt() const -{ - return static_cast(mValue); -} - -double NumericValue::GetValue() const -{ - return mValue; -} - -void NumericValue::SetValue(double value) -{ - mValue = value; -} - -bool TextValue::IsInstance(const BaseValue* value) -{ - return value->GetKind() == KD_Text; -} - -TextValue::TextValue() - : BaseValue(BaseValue::KD_Text) -{ -} - -const std::string& TextValue::GetValue() const -{ - return mValue; -} - -void TextValue::SetValue(const std::string& value) -{ - mValue = value; -} - -bool DateTimeValue::IsInstance(const BaseValue* value) -{ - return value->GetKind() == KD_DateTime; -} - -DateTimeValue::DateTimeValue() - : BaseValue(BaseValue::KD_DateTime) -{ -} - -std::string DateTimeValue::GetString() const -{ - namespace chrono = std::chrono; - auto t = chrono::system_clock::to_time_t(mValue); - - char data[32]; - std::strftime(data, sizeof(data), "%Y-%m-%d %H:%M:%S", std::localtime(&t)); - - return std::string(data); -} - -const std::chrono::time_point& DateTimeValue::GetValue() const -{ - return mValue; -} - -void DateTimeValue::SetValue(const std::chrono::time_point& value) -{ - mValue = value; -} diff --git a/core/src/Model/Workflow/Values/BasicValues.hpp b/core/src/Model/Workflow/Values/BasicValues.hpp deleted file mode 100644 index 795876e..0000000 --- a/core/src/Model/Workflow/Values/BasicValues.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "Model/Workflow/Value.hpp" - -#include -#include -#include - -class NumericValue : public BaseValue -{ -private: - double mValue; - -public: - static bool IsInstance(const BaseValue* value); - NumericValue(); - - std::string GetTruncatedString() const; - std::string GetRoundedString() const; - std::string GetString() const; - - int64_t GetInt() const; - double GetValue() const; - void SetValue(double value); -}; - -class TextValue : public BaseValue -{ -private: - std::string mValue; - -public: - static bool IsInstance(const BaseValue* value); - TextValue(); - - const std::string& GetValue() const; - void SetValue(const std::string& value); -}; - -class DateTimeValue : public BaseValue -{ -private: - std::chrono::time_point mValue; - -public: - static bool IsInstance(const BaseValue* value); - DateTimeValue(); - - std::string GetString() const; - const std::chrono::time_point& GetValue() const; - void SetValue(const std::chrono::time_point& value); -}; diff --git a/core/src/Model/Workflow/Values/Database.cpp b/core/src/Model/Workflow/Values/Database.cpp new file mode 100644 index 0000000..12d2b80 --- /dev/null +++ b/core/src/Model/Workflow/Values/Database.cpp @@ -0,0 +1,88 @@ +#include "Database.hpp" + +#include "Model/TransactionsModel.hpp" +#include "Model/Workflow/ValueInternals.hpp" + +#include + +TableKind DatabaseRowIdValue::GetTable() const +{ + return mTable; +} + +int64_t DatabaseRowIdValue::GetRowId() const +{ + return mRowId; +} + +bool DatabaseRowIdValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_DatabaseRowId; +} + +DatabaseRowIdValue::DatabaseRowIdValue() + : BaseValue(KD_DatabaseRowId) + , mTable{ TableKind::Sales } + , mRowId{ std::numeric_limits::max() } +{ +} + +bool SaleDatabaseRowValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_SaleDatabaseRow; +} + +SaleDatabaseRowValue::SaleDatabaseRowValue() + : BaseObjectValue(KD_SaleDatabaseRow) +{ +} + +const BaseValue* SaleDatabaseRowValue::GetProperty(int idx) const +{ + switch (idx) { + case 0: return &mCustomerName; + case 1: return &mDeadline; + case 2: return &mDeliveryTime; + default: return nullptr; + } +} + +bool SaleDatabaseRowValue::SetProperty(int idx, std::unique_ptr value) +{ + switch (idx) { + case 0: return false; + case 1: CHECK_VALUE_TYPE_AND_MOVE(DateTimeValue, mDeadline, value.get()); break; + case 2: CHECK_VALUE_TYPE_AND_MOVE(DateTimeValue, mDeliveryTime, value.get()); break; + } + return true; +} + +bool PurchaseDatabaseRowValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_PurchaseDatabaseRow; +} + +PurchaseDatabaseRowValue::PurchaseDatabaseRowValue() + : BaseObjectValue(KD_PurchaseDatabaseRow) +{ +} + +const BaseValue* PurchaseDatabaseRowValue::GetProperty(int idx) const +{ + switch (idx) { + case 0: return &mFactoryName; + case 1: return &mOrderTime; + case 2: return &mDeliveryTime; + default: return nullptr; + } +} + +bool PurchaseDatabaseRowValue::SetProperty(int idx, std::unique_ptr value) +{ + switch (idx) { + case 0: return false; + case 1: CHECK_VALUE_TYPE_AND_MOVE(DateTimeValue, mOrderTime, value.get()); break; + case 2: CHECK_VALUE_TYPE_AND_MOVE(DateTimeValue, mDeliveryTime, value.get()); break; + } + return true; +} diff --git a/core/src/Model/Workflow/Values/Database.hpp b/core/src/Model/Workflow/Values/Database.hpp new file mode 100644 index 0000000..e8a4f83 --- /dev/null +++ b/core/src/Model/Workflow/Values/Database.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "Model/Workflow/Value.hpp" +#include "Model/Workflow/Values/Basic.hpp" +#include "cplt_fwd.hpp" + +class DatabaseRowIdValue : public BaseValue +{ +private: + TableKind mTable; + int64_t mRowId; + +public: + static bool IsInstance(const BaseValue* value); + DatabaseRowIdValue(); + + TableKind GetTable() const; + int64_t GetRowId() const; +}; + +class SaleDatabaseRowValue : public BaseObjectValue +{ +private: + int mCustomerId; + TextValue mCustomerName; + DateTimeValue mDeadline; + DateTimeValue mDeliveryTime; + +public: + static bool IsInstance(const BaseValue* value); + SaleDatabaseRowValue(); + + virtual const BaseValue* GetProperty(int idx) const; + virtual bool SetProperty(int idx, std::unique_ptr value); +}; + +class PurchaseDatabaseRowValue : public BaseObjectValue +{ +private: + int mFactoryId; + TextValue mFactoryName; + DateTimeValue mOrderTime; + DateTimeValue mDeliveryTime; + +public: + static bool IsInstance(const BaseValue* value); + PurchaseDatabaseRowValue(); + + virtual const BaseValue* GetProperty(int idx) const; + virtual bool SetProperty(int idx, std::unique_ptr value); +}; diff --git a/core/src/Model/Workflow/Values/fwd.hpp b/core/src/Model/Workflow/Values/fwd.hpp index 24f8119..de26226 100644 --- a/core/src/Model/Workflow/Values/fwd.hpp +++ b/core/src/Model/Workflow/Values/fwd.hpp @@ -1,6 +1,14 @@ #pragma once -// BasicValues.hpp +// Basic.hpp class NumericValue; class TextValue; class DateTimeValue; + +// Database.hpp +class DatabaseRowIdValue; +class SaleDatabaseRowValue; +class PurchaseDatabaseRowValue; + +// List.hpp +class ListValue; diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp index 161400e..c57ac31 100644 --- a/core/src/Model/Workflow/Workflow.hpp +++ b/core/src/Model/Workflow/Workflow.hpp @@ -111,6 +111,8 @@ public: static const char* FormatType(Type type); static std::unique_ptr CreateByKind(Kind kind); + static bool IsInstance(const WorkflowNode* node); + WorkflowNode(Kind kind, bool locked); virtual ~WorkflowNode() = default; diff --git a/core/src/Model/Workflow/Workflow_RTTI.cpp b/core/src/Model/Workflow/Workflow_RTTI.cpp index 34347b1..10659d0 100644 --- a/core/src/Model/Workflow/Workflow_RTTI.cpp +++ b/core/src/Model/Workflow/Workflow_RTTI.cpp @@ -21,8 +21,9 @@ const char* WorkflowNode::FormatKind(Kind kind) case KD_FormInput: return "FormInput"; case KD_DatabaseRowsInput: return "DatabaseRowsInput"; - case InvalidKind: return ""; + case InvalidKind: break; } + return ""; } const char* WorkflowNode::FormatType(Type type) @@ -32,6 +33,7 @@ const char* WorkflowNode::FormatType(Type type) case TransformType: return "transform"; case OutputType: return "output"; } + return ""; } std::unique_ptr WorkflowNode::CreateByKind(WorkflowNode::Kind kind) @@ -48,6 +50,12 @@ std::unique_ptr WorkflowNode::CreateByKind(WorkflowNode::Kind kind case KD_FormInput: return std::make_unique(); case KD_DatabaseRowsInput: return std::make_unique(); - case InvalidKind: return nullptr; + case InvalidKind: break; } + return nullptr; +} + +bool WorkflowNode::IsInstance(const WorkflowNode* node) +{ + return true; } diff --git a/core/src/Model/Workflow/fwd.hpp b/core/src/Model/Workflow/fwd.hpp index b541e52..d118fe8 100644 --- a/core/src/Model/Workflow/fwd.hpp +++ b/core/src/Model/Workflow/fwd.hpp @@ -13,6 +13,7 @@ class SavedWorkflow; // Value.hpp class BaseValue; +class BaseObjectValue; // Workflow.hpp class WorkflowConnection; -- cgit v1.2.3-70-g09d2