Skip to content

Commit f8dc733

Browse files
committed
fix: ControllerInterface map reworked to a static getter
1 parent 221a114 commit f8dc733

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

SerialPrograms/Source/Controllers/ControllerDescriptor.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ namespace PokemonAutomation{
2121
//
2222
// Here we store a map of all controller types in the program.
2323
//
24-
std::map<ControllerInterface, std::unique_ptr<InterfaceType>> ALL_CONTROLLER_INTERFACES;
24+
static std::map<ControllerInterface, std::unique_ptr<InterfaceType>>& all_controller_interfaces(){
25+
static std::map<ControllerInterface, std::unique_ptr<InterfaceType>> instance;
26+
return instance;
27+
}
2528

2629

2730
void InterfaceType::register_factory(
2831
ControllerInterface controller_interface,
2932
std::unique_ptr<InterfaceType> factory
3033
){
31-
auto ret = ALL_CONTROLLER_INTERFACES.emplace(controller_interface, std::move(factory));
34+
auto ret = all_controller_interfaces().emplace(controller_interface, std::move(factory));
3235
if (!ret.second){
3336
throw InternalProgramError(
3437
nullptr, PA_CURRENT_FUNCTION,
@@ -76,7 +79,7 @@ void ControllerOption::load_json(const JsonValue& json){
7679
break;
7780
}
7881

79-
for (const auto& item : ALL_CONTROLLER_INTERFACES){
82+
for (const auto& item : all_controller_interfaces()){
8083
const JsonValue* params = obj->get_value(CONTROLLER_INTERFACE_STRINGS.get_string(item.first));
8184
if (params == nullptr){
8285
continue;

0 commit comments

Comments
 (0)