aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/Model')
-rw-r--r--core/src/Model/Workflow/Value.hpp1
-rw-r--r--core/src/Model/Workflow/Value_RTTI.cpp9
-rw-r--r--core/src/Model/Workflow/Values/Dictionary.cpp49
-rw-r--r--core/src/Model/Workflow/Values/Dictionary.hpp25
-rw-r--r--core/src/Model/Workflow/Values/fwd.hpp3
5 files changed, 87 insertions, 0 deletions
diff --git a/core/src/Model/Workflow/Value.hpp b/core/src/Model/Workflow/Value.hpp
index 39c0bf3..ed35349 100644
--- a/core/src/Model/Workflow/Value.hpp
+++ b/core/src/Model/Workflow/Value.hpp
@@ -17,6 +17,7 @@ public:
KD_DateTime,
KD_DatabaseRowId,
KD_List,
+ KD_Dictionary,
KD_BaseObject,
KD_SaleDatabaseRow,
diff --git a/core/src/Model/Workflow/Value_RTTI.cpp b/core/src/Model/Workflow/Value_RTTI.cpp
index d6721d7..dfb1273 100644
--- a/core/src/Model/Workflow/Value_RTTI.cpp
+++ b/core/src/Model/Workflow/Value_RTTI.cpp
@@ -2,6 +2,7 @@
#include "Model/Workflow/Values/Basic.hpp"
#include "Model/Workflow/Values/Database.hpp"
+#include "Model/Workflow/Values/Dictionary.hpp"
#include "Model/Workflow/Values/List.hpp"
#include "UI/UI.hpp"
@@ -30,6 +31,11 @@ constexpr BaseValue::KindInfo kListInfo{
.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),
@@ -48,6 +54,7 @@ const BaseValue::KindInfo& BaseValue::QueryInfo(BaseValue::Kind kind)
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:
@@ -67,6 +74,7 @@ const char* BaseValue::Format(Kind kind)
case KD_DateTime: return "Date/time";
case KD_DatabaseRowId: return "Row id";
case KD_List: return "List";
+ case KD_Dictionary: return "Dictionary";
case KD_BaseObject: return "Object";
case KD_SaleDatabaseRow: return "Sale record";
@@ -85,6 +93,7 @@ std::unique_ptr<BaseValue> BaseValue::CreateByKind(BaseValue::Kind kind)
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>();
diff --git a/core/src/Model/Workflow/Values/Dictionary.cpp b/core/src/Model/Workflow/Values/Dictionary.cpp
new file mode 100644
index 0000000..106e48d
--- /dev/null
+++ b/core/src/Model/Workflow/Values/Dictionary.cpp
@@ -0,0 +1,49 @@
+#include "Dictionary.hpp"
+
+#include "Utils/Macros.hpp"
+
+bool DictionaryValue::IsInstance(const BaseValue* value)
+{
+ return value->GetKind() == KD_Dictionary;
+}
+
+DictionaryValue::DictionaryValue()
+ : BaseValue(KD_Dictionary)
+{
+}
+
+int DictionaryValue::GetCount() const
+{
+ return mElements.size();
+}
+
+BaseValue* DictionaryValue::Find(std::string_view key)
+{
+ auto iter = mElements.find(key);
+ if (iter != mElements.end()) {
+ return iter.value().get();
+ } else {
+ return nullptr;
+ }
+}
+
+BaseValue* DictionaryValue::Insert(std::string_view key, std::unique_ptr<BaseValue>& value)
+{
+ auto [iter, success] = mElements.insert(key, std::move(value));
+ if (success) {
+ return iter.value().get();
+ } else {
+ return nullptr;
+ }
+}
+
+BaseValue& DictionaryValue::InsertOrReplace(std::string_view key, std::unique_ptr<BaseValue> value)
+{
+ auto [iter, DISCARD] = mElements.emplace(key, std::move(value));
+ return *iter.value();
+}
+
+void DictionaryValue::Remove(std::string_view key)
+{
+ mElements.erase(mElements.find(key));
+}
diff --git a/core/src/Model/Workflow/Values/Dictionary.hpp b/core/src/Model/Workflow/Values/Dictionary.hpp
new file mode 100644
index 0000000..65ea82f
--- /dev/null
+++ b/core/src/Model/Workflow/Values/Dictionary.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "Model/Workflow/Value.hpp"
+
+#include <tsl/array_map.h>
+#include <memory>
+#include <string>
+#include <string_view>
+
+class DictionaryValue : public BaseValue
+{
+private:
+ tsl::array_map<char, std::unique_ptr<BaseValue>> mElements;
+
+public:
+ static bool IsInstance(const BaseValue* value);
+ DictionaryValue();
+
+ int GetCount() const;
+ BaseValue* Find(std::string_view key);
+
+ BaseValue* Insert(std::string_view key, std::unique_ptr<BaseValue>& value);
+ BaseValue& InsertOrReplace(std::string_view key, std::unique_ptr<BaseValue> value);
+ void Remove(std::string_view key);
+};
diff --git a/core/src/Model/Workflow/Values/fwd.hpp b/core/src/Model/Workflow/Values/fwd.hpp
index de26226..51a04e9 100644
--- a/core/src/Model/Workflow/Values/fwd.hpp
+++ b/core/src/Model/Workflow/Values/fwd.hpp
@@ -10,5 +10,8 @@ class DatabaseRowIdValue;
class SaleDatabaseRowValue;
class PurchaseDatabaseRowValue;
+// Dictionary.hpp
+class DictionaryValue;
+
// List.hpp
class ListValue;