diff --git a/src/fdb5/rules/Rule.cc b/src/fdb5/rules/Rule.cc index 6879ad3a9..1da254628 100644 --- a/src/fdb5/rules/Rule.cc +++ b/src/fdb5/rules/Rule.cc @@ -11,6 +11,7 @@ #include "fdb5/rules/Rule.h" #include +#include #include "eckit/config/Resource.h" @@ -26,11 +27,9 @@ namespace fdb5 { //---------------------------------------------------------------------------------------------------------------------- -Rule::Rule(const Schema &schema, - size_t line, - std::vector &predicates, std::vector &rules, - const std::map &types): - schema_(schema), registry_(new TypesRegistry()), line_(line) { +Rule::Rule(const Schema& schema, size_t line, std::vector& predicates, std::vector& rules, + const std::map& types) + : schema_(schema), registry_(std::make_shared()), line_(line) { std::swap(predicates, predicates_); std::swap(rules, rules_); for (std::map::const_iterator i = types.begin(); i != types.end(); ++i) { diff --git a/src/fdb5/rules/Schema.cc b/src/fdb5/rules/Schema.cc index b345e4306..ee80efdeb 100644 --- a/src/fdb5/rules/Schema.cc +++ b/src/fdb5/rules/Schema.cc @@ -11,6 +11,7 @@ #include #include #include +#include #include "eckit/exception/Exceptions.h" @@ -25,15 +26,13 @@ namespace fdb5 { //---------------------------------------------------------------------------------------------------------------------- -Schema::Schema() : registry_(new TypesRegistry()) { +Schema::Schema() : registry_(std::make_shared()) { } -} - -Schema::Schema(const eckit::PathName &path) : registry_(new TypesRegistry()) { +Schema::Schema(const eckit::PathName& path) : Schema() { load(path); } -Schema::Schema(std::istream& s) : registry_(new TypesRegistry()) { +Schema::Schema(std::istream& s) : Schema() { load(s); } @@ -238,16 +237,20 @@ SchemaRegistry& SchemaRegistry::instance() { } const Schema& SchemaRegistry::get(const eckit::PathName& path) { - std::lock_guard lock(m_); - auto it = schemas_.find(path); - if (it != schemas_.end()) { - return *it->second; + std::lock_guard lock(m_); + + auto iter = schemas_.find(path); + + if (iter == schemas_.end()) { + bool done = false; + + std::tie(iter, done) = schemas_.emplace(path, std::make_unique(path)); + + ASSERT(done); } - Schema* p = new Schema(path); - ASSERT(p); - schemas_[path] = std::unique_ptr(p); - return *schemas_[path]; + ASSERT(iter->second); + return *iter->second; } //----------------------------------------------------------------------------------------------------------------------