aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/mapper/Mapper.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-08 16:53:51 +0800
committercrupest <crupest@outlook.com>2022-02-08 16:53:51 +0800
commit74bb9cd27242b9320f99ff4d2b50c3051576cc14 (patch)
tree744bac5799c593d1d6f81e7b09581bea626f2cde /include/cru/ui/mapper/Mapper.hpp
parentb90c398de829d1ba5329651d75bae82f5e4085fe (diff)
downloadcru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.gz
cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.bz2
cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.zip
...
Diffstat (limited to 'include/cru/ui/mapper/Mapper.hpp')
-rw-r--r--include/cru/ui/mapper/Mapper.hpp92
1 files changed, 0 insertions, 92 deletions
diff --git a/include/cru/ui/mapper/Mapper.hpp b/include/cru/ui/mapper/Mapper.hpp
deleted file mode 100644
index c52bec70..00000000
--- a/include/cru/ui/mapper/Mapper.hpp
+++ /dev/null
@@ -1,92 +0,0 @@
-#pragma once
-#include "../Base.hpp"
-
-#include "cru/common/ClonablePtr.hpp"
-#include "cru/common/Exception.hpp"
-#include "cru/xml/XmlNode.hpp"
-
-#include <memory>
-#include <type_traits>
-#include <typeindex>
-#include <typeinfo>
-
-namespace cru::ui::mapper {
-template <typename T>
-class BasicMapper;
-
-class CRU_UI_API MapperBase : public Object {
- public:
- explicit MapperBase(std::type_index type_index);
-
- CRU_DELETE_COPY(MapperBase)
- CRU_DELETE_MOVE(MapperBase)
-
- ~MapperBase() override = default;
-
- public:
- std::type_index GetTypeIndex() const { return type_index_; }
-
- template <typename T>
- BasicMapper<T>* StaticCast() {
- return static_cast<BasicMapper<T>*>(this);
- }
-
- template <typename T>
- BasicMapper<T>* DynamicCast() {
- return dynamic_cast<BasicMapper<T>*>(this);
- }
-
- virtual bool SupportMapFromString() { return false; }
- virtual bool SupportMapFromXml() { return false; }
- virtual bool XmlElementIsOfThisType(xml::XmlElementNode* node) {
- return false;
- }
-
- private:
- std::type_index type_index_;
-};
-
-template <typename T>
-class CRU_UI_API BasicMapper : public MapperBase {
- public:
- static_assert(std::is_default_constructible_v<T>,
- "T must be default constructible.");
-
- BasicMapper() : MapperBase(typeid(T)) {}
-
- CRU_DELETE_COPY(BasicMapper)
- CRU_DELETE_MOVE(BasicMapper)
-
- ~BasicMapper() override = default;
-
- virtual T MapFromString(String str) {
- if (!SupportMapFromString()) {
- throw Exception(u"This mapper does not support map from string.");
- }
-
- return DoMapFromString(str);
- }
-
- T MapFromXml(xml::XmlElementNode* node) {
- if (!SupportMapFromXml()) {
- throw Exception(u"This mapper does not support map from xml.");
- }
-
- if (!XmlElementIsOfThisType(node)) {
- throw Exception(u"This xml element is not of mapping type.");
- }
-
- return DoMapFromXml(node);
- }
-
- protected:
- virtual T DoMapFromString(String str) { return {}; }
- virtual T DoMapFromXml(xml::XmlElementNode* node) { return {}; }
-};
-
-template <typename T>
-using BasicRefMapper = BasicMapper<std::shared_ptr<T>>;
-
-template <typename T>
-using BasicPtrMapper = BasicMapper<ClonablePtr<T>>;
-} // namespace cru::ui::mapper