aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Workflow/Value.hpp
blob: 2198674fe8c5be08e05584b7b7cca4eac1015268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once

#include "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;
};