aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Workflow/Values
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/Model/Workflow/Values')
-rw-r--r--core/src/Model/Workflow/Values/List.cpp100
-rw-r--r--core/src/Model/Workflow/Values/List.hpp50
2 files changed, 150 insertions, 0 deletions
diff --git a/core/src/Model/Workflow/Values/List.cpp b/core/src/Model/Workflow/Values/List.cpp
new file mode 100644
index 0000000..9fd6bfd
--- /dev/null
+++ b/core/src/Model/Workflow/Values/List.cpp
@@ -0,0 +1,100 @@
+#include "List.hpp"
+
+#include <utility>
+
+BaseValue* ListValue::Iterator::operator*() const
+{
+ return mIter->get();
+}
+
+BaseValue* ListValue::Iterator::operator->() const
+{
+ return mIter->get();
+}
+
+ListValue::Iterator& ListValue::Iterator::operator++()
+{
+ ++mIter;
+ return *this;
+}
+
+ListValue::Iterator ListValue::Iterator::operator++(int) const
+{
+ return Iterator(mIter + 1);
+}
+
+ListValue::Iterator& ListValue::Iterator::operator--()
+{
+ --mIter;
+ return *this;
+}
+
+ListValue::Iterator ListValue::Iterator::operator--(int) const
+{
+ return Iterator(mIter - 1);
+}
+
+bool operator==(const ListValue::Iterator& a, const ListValue::Iterator& b)
+{
+ return a.mIter == b.mIter;
+}
+
+ListValue::Iterator::Iterator(decltype(mIter) iter)
+ : mIter{ iter }
+{
+}
+
+bool ListValue::IsInstance(const BaseValue* value)
+{
+ return value->GetKind() == KD_List;
+}
+
+ListValue::ListValue()
+ : BaseValue(KD_List)
+{
+}
+
+int ListValue::GetCount() const
+{
+ return mElements.size();
+}
+
+BaseValue* ListValue::GetElement(int i) const
+{
+ return mElements[i].get();
+}
+
+void ListValue::Append(std::unique_ptr<BaseValue> element)
+{
+ mElements.push_back(std::move(element));
+}
+
+void ListValue::Insert(int i, std::unique_ptr<BaseValue> element)
+{
+ mElements.insert(mElements.begin() + i, std::move(element));
+}
+
+void ListValue::Insert(Iterator iter, std::unique_ptr<BaseValue> element)
+{
+ mElements.insert(iter.mIter, std::move(element));
+}
+
+void ListValue::Remove(int i)
+{
+ mElements.erase(mElements.begin() + i);
+}
+
+void ListValue::Remove(Iterator iter)
+{
+ mElements.erase(iter.mIter);
+}
+
+ListValue::Iterator ListValue::begin()
+{
+ return Iterator(mElements.begin());
+}
+
+ListValue::Iterator ListValue::end()
+{
+ return Iterator(mElements.end());
+}
diff --git a/core/src/Model/Workflow/Values/List.hpp b/core/src/Model/Workflow/Values/List.hpp
new file mode 100644
index 0000000..706a95c
--- /dev/null
+++ b/core/src/Model/Workflow/Values/List.hpp
@@ -0,0 +1,50 @@
+#pragma once
+
+#include "Model/Workflow/Value.hpp"
+
+#include <memory>
+#include <vector>
+
+class ListValue : public BaseValue
+{
+public:
+ class Iterator
+ {
+ private:
+ std::vector<std::unique_ptr<BaseValue>>::iterator mIter;
+
+ public:
+ BaseValue* operator*() const;
+ BaseValue* operator->() const;
+
+ Iterator& operator++();
+ Iterator operator++(int) const;
+ Iterator& operator--();
+ Iterator operator--(int) const;
+
+ friend bool operator==(const Iterator& a, const Iterator& b);
+
+ private:
+ friend class ListValue;
+ Iterator(decltype(mIter) iter);
+ };
+
+private:
+ std::vector<std::unique_ptr<BaseValue>> mElements;
+
+public:
+ static bool IsInstance(const BaseValue* value);
+ ListValue();
+
+ int GetCount() const;
+ BaseValue* GetElement(int i) const;
+
+ void Append(std::unique_ptr<BaseValue> element);
+ void Insert(int i, std::unique_ptr<BaseValue> element);
+ void Insert(Iterator iter, std::unique_ptr<BaseValue> element);
+ void Remove(int i);
+ void Remove(Iterator iter);
+
+ Iterator begin();
+ Iterator end();
+};