diff options
author | crupest <crupest@outlook.com> | 2022-01-17 22:55:09 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-01-17 22:55:09 +0800 |
commit | 67dd012c0f49898f1734c46d3bb264f59d056a8e (patch) | |
tree | 780dc9c50868a8e7b89e68b463a60745fce72ae9 /src/ui/mapper/MapperRegistry.cpp | |
parent | 81f7d5faaaf79149070a901a4f299aee70c46379 (diff) | |
download | cru-67dd012c0f49898f1734c46d3bb264f59d056a8e.tar.gz cru-67dd012c0f49898f1734c46d3bb264f59d056a8e.tar.bz2 cru-67dd012c0f49898f1734c46d3bb264f59d056a8e.zip |
...
Diffstat (limited to 'src/ui/mapper/MapperRegistry.cpp')
-rw-r--r-- | src/ui/mapper/MapperRegistry.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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 |