From d8289105193707daede1a5b59137f18e20f20aeb Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 18 Oct 2024 15:48:14 +0200 Subject: (2/2) rename --- TileBehaviorFactory.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 TileBehaviorFactory.cpp (limited to 'TileBehaviorFactory.cpp') diff --git a/TileBehaviorFactory.cpp b/TileBehaviorFactory.cpp new file mode 100644 index 0000000..99301ac --- /dev/null +++ b/TileBehaviorFactory.cpp @@ -0,0 +1,20 @@ +#include "TileBehaviorFactory.h" +#include "Exception.h" + +using namespace std; + +TileBehavior & TileBehaviorFactory::get_strategy(string type) { + auto & type_map = TileBehaviorFactory::get_collection(); + + if (type_map.contains(type)) + return *type_map.at(type); + + throw Exception("unknown behavior for tile type \"%s\"", type.c_str()); +} + +void TileBehaviorFactory::register_strategy(string type, TileBehavior * strategy) { + auto & type_map = TileBehaviorFactory::get_collection(); + + type_map[type] = strategy; +} + -- cgit v1.2.3