From 67dd012c0f49898f1734c46d3bb264f59d056a8e Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 17 Jan 2022 22:55:09 +0800 Subject: ... --- src/ui/mapper/MapperRegistry.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/ui/mapper/MapperRegistry.cpp (limited to 'src/ui/mapper/MapperRegistry.cpp') diff --git a/src/ui/mapper/MapperRegistry.cpp b/src/ui/mapper/MapperRegistry.cpp new file mode 100644 index 00000000..e445a7d0 --- /dev/null +++ b/src/ui/mapper/MapperRegistry.cpp @@ -0,0 +1,29 @@ +#include "cru/ui/mapper/MapperRegistry.hpp" + +namespace cru::ui::mapper { +MapperRegistry::MapperRegistry() {} + +MapperRegistry::~MapperRegistry() { + for (auto mapper : mapper_list_) { + delete mapper; + } +} + +void MapperRegistry::RegisterMapper(MapperBase *mapper) { + if (std::find(mapper_list_.cbegin(), mapper_list_.cend(), mapper) != + mapper_list_.cend()) { + throw Exception(u"This mapper is already registered."); + } + + mapper_list_.push_back(mapper); +} + +void MapperRegistry::UnregisterMapper(MapperBase *mapper) { + auto it = std::find(mapper_list_.begin(), mapper_list_.end(), mapper); + if (it == mapper_list_.end()) { + throw Exception(u"This mapper is not registered."); + } + + mapper_list_.erase(it); +} +} // namespace cru::ui::mapper -- cgit v1.2.3