Skip to content

Commit

Permalink
Fixup: workaround shared_ptr requiring a public constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Dec 12, 2024
1 parent 4b3e396 commit 5319b06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/atlas/util/Factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
* nor does it submit to any jurisdiction.
*/

#include "atlas/util/Factory.h"

#include <iostream>

#include "atlas/runtime/Exception.h"
#include "atlas/runtime/Log.h"
#include "atlas/util/Factory.h"

// #define DEBUG_FACTORY_REGISTRATION

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -115,7 +116,7 @@ FactoryBase::~FactoryBase() {
std::shared_ptr<FactoryRegistry> FactoryRegistry::instance(const std::string& factory) {
static std::map<std::string,std::shared_ptr<FactoryRegistry>> 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);
Expand Down
7 changes: 6 additions & 1 deletion src/atlas/util/Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5319b06

Please sign in to comment.