diff options
author | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
commit | 7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch) | |
tree | e95be6e66db504ed06d00b72c579565bab873277 /app/source/Cplt/Model/Workflow/Value.hpp | |
parent | 2cf952088d375ac8b2f45b144462af0953436cff (diff) |
Restructure project
Diffstat (limited to 'app/source/Cplt/Model/Workflow/Value.hpp')
-rw-r--r-- | app/source/Cplt/Model/Workflow/Value.hpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/app/source/Cplt/Model/Workflow/Value.hpp b/app/source/Cplt/Model/Workflow/Value.hpp new file mode 100644 index 0000000..70fcb57 --- /dev/null +++ b/app/source/Cplt/Model/Workflow/Value.hpp @@ -0,0 +1,94 @@ +#pragma once + +#include <Cplt/Utils/Color.hpp> +#include <Cplt/fwd.hpp> + +#include <iosfwd> +#include <memory> +#include <string> +#include <vector> + +class BaseValue +{ +public: + enum Kind + { + KD_Numeric, + KD_Text, + KD_DateTime, + KD_DatabaseRowId, + KD_List, + KD_Dictionary, + + KD_BaseObject, + KD_SaleDatabaseRow, + KD_PurchaseDatabaseRow, + KD_BaseObjectLast = KD_PurchaseDatabaseRow, + + /// An unspecified type, otherwise known as "any" in some contexts. + InvalidKind, + KindCount = InvalidKind, + }; + + struct KindInfo + { + ImGui::IconType PinIcon; + RgbaColor PinColor; + }; + +private: + Kind mKind; + +public: + static const KindInfo& QueryInfo(Kind kind); + static const char* Format(Kind kind); + static std::unique_ptr<BaseValue> CreateByKind(Kind kind); + + static bool IsInstance(const BaseValue* value); + + BaseValue(Kind kind); + virtual ~BaseValue() = default; + + BaseValue(const BaseValue&) = delete; + BaseValue& operator=(const BaseValue&) = delete; + BaseValue(BaseValue&&) = default; + BaseValue& operator=(BaseValue&&) = default; + + Kind GetKind() const; + + // TODO get constant editor + + /// The functions \c ReadFrom, \c WriteTo will only be valid to call if this function returns true. + virtual bool SupportsConstant() const; + 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<Property> 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<BaseValue> value) = 0; +}; |