From 5319b068ec9ad02fd77b8424370abcf334ad204e Mon Sep 17 00:00:00 2001 From: Willem Deconinck Date: Thu, 12 Dec 2024 18:04:19 +0100 Subject: [PATCH] Fixup: workaround shared_ptr requiring a public constructor --- src/atlas/util/Factory.cc | 7 ++++--- src/atlas/util/Factory.h | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/atlas/util/Factory.cc b/src/atlas/util/Factory.cc index 869b1d4df..6af5227a6 100644 --- a/src/atlas/util/Factory.cc +++ b/src/atlas/util/Factory.cc @@ -8,11 +8,12 @@ * nor does it submit to any jurisdiction. */ +#include "atlas/util/Factory.h" + #include #include "atlas/runtime/Exception.h" #include "atlas/runtime/Log.h" -#include "atlas/util/Factory.h" // #define DEBUG_FACTORY_REGISTRATION @@ -62,7 +63,7 @@ void FactoryRegistry::remove(const std::string& builder) { factories_.erase(builder); } -FactoryRegistry::FactoryRegistry(const std::string& factory): factory_(factory) { +FactoryRegistry::FactoryRegistry(const std::string& factory, FactoryRegistry::Private): factory_(factory) { #ifdef DEBUG_FACTORY_REGISTRATION std::cout << "Created " << factory << std::endl; #endif @@ -115,7 +116,7 @@ FactoryBase::~FactoryBase() { std::shared_ptr FactoryRegistry::instance(const std::string& factory) { static std::map> registries; if (registries.find(factory) == registries.end()) { - auto [it_pair, inserted] = registries.emplace(factory, new FactoryRegistry(factory)); + auto [it_pair, inserted] = registries.emplace(factory, new FactoryRegistry(factory,Private())); return it_pair->second; } return registries.at(factory); diff --git a/src/atlas/util/Factory.h b/src/atlas/util/Factory.h index a0c4be047..d46d78c7a 100644 --- a/src/atlas/util/Factory.h +++ b/src/atlas/util/Factory.h @@ -27,7 +27,12 @@ class FactoryBase; class FactoryRegistry { private: - FactoryRegistry(const std::string& factory); + struct Private{ explicit Private() = default; }; +public: + // Constructor, essentially private because nobody can create an explicit Private object. + // Construction must happen via instance() function below + FactoryRegistry(const std::string& factory, Private); + virtual ~FactoryRegistry(); private: