Skip to content

Commit

Permalink
fix(merge): Key Schema and TypesRegistry
Browse files Browse the repository at this point in the history
related to PR #26
  • Loading branch information
mcakircali committed Sep 24, 2024
1 parent 24ce773 commit 9f71b93
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 36 deletions.
8 changes: 0 additions & 8 deletions src/fdb5/database/Key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@ void BaseKey::popFrom(const BaseKey& other) {
for (const auto& [keyword, value] : other) { pop(keyword); }
}

void Key::pushFrom(const Key& other) {
for (const auto& [keyword, value] : Reverse(other)) { push(keyword, value); }
}

void Key::popFrom(const Key& other) {
for (const auto& [keyword, value] : other) { pop(keyword); }
}

const std::string &BaseKey::get( const std::string &k ) const {
eckit::StringDict::const_iterator i = keys_.find(k);
if ( i == keys_.end() ) {
Expand Down
5 changes: 3 additions & 2 deletions src/fdb5/database/Key.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ class BaseKey {

void push(const std::string &k, const std::string &v);
void pop(const std::string &k);
void pushFrom(const Key& other);
void popFrom(const Key& other);

void pushFrom(const BaseKey& other);
void popFrom(const BaseKey& other);

const std::string& get( const std::string &k ) const;

Expand Down
6 changes: 0 additions & 6 deletions src/fdb5/rules/Matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ namespace fdb5 {

//----------------------------------------------------------------------------------------------------------------------

Matcher::Matcher() {
}

Matcher::~Matcher() {
}

bool Matcher::optional() const {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion src/fdb5/rules/Matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace fdb5 {

class Key;
class TypedKey;
class Key;
class TypesRegistry;

//----------------------------------------------------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions src/fdb5/rules/Schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ Schema::~Schema() {

//----------------------------------------------------------------------------------------------------------------------

const Rule* Schema::matchingRule(const Key& dbKey, const Key& idxKey) const {
const RuleDatum& Schema::matchingRule(const Key& dbKey, const Key& idxKey) const {

for (const auto& dbRule : rules_) {
if (!dbRule.match(dbKey)) { continue; }
for (const auto& idxRule : dbRule.rules()) {
if (idxRule.match(idxKey)) {
/// @note this assumes that there is only one datum per index
for (const auto& datumRule : idxRule.rules()) { return &datumRule; }
for (const auto& datumRule : idxRule.rules()) { return datumRule; }
}
}
}

LOG_DEBUG_LIB(LibFdb5) << "No rule is matching dbKey=" << dbKey << " and idxKey=" << idxKey << std::endl;

return nullptr;
std::ostringstream msg;
msg << "No rule is matching dbKey=" << dbKey << " and idxKey=" << idxKey << std::endl;
throw eckit::SeriousBug(msg.str(), Here());
}

const RuleDatabase& Schema::matchingRule(const Key& dbKey) const {
Expand All @@ -76,7 +76,7 @@ const RuleDatabase& Schema::matchingRule(const Key& dbKey) const {
if (rule.match(dbKey)) { return rule; }
}

std::stringstream msg;
std::ostringstream msg;
msg << "No rule exists for key " << dbKey;
throw eckit::SeriousBug(msg.str(), Here());
}
Expand Down
3 changes: 1 addition & 2 deletions src/fdb5/rules/Schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ class Schema : private eckit::NonCopyable {

const RuleDatabase& matchingRule(const Key& dbKey) const;

/// @todo return RuleDatum
const Rule* matchingRule(const Key& dbKey, const Key& idxKey) const;
const RuleDatum& matchingRule(const Key& dbKey, const Key& idxKey) const;

void load(const eckit::PathName& path, bool replace = false);

Expand Down
4 changes: 2 additions & 2 deletions src/fdb5/tools/fdb-overlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void FdbOverlay::execute(const CmdArgs& args) {
}
}

std::unique_ptr<DB> dbSource = DB::buildReader(source.canonical(), conf);
std::unique_ptr<DB> dbSource = DB::buildReader(source, conf);
if (!dbSource->exists()) {
std::stringstream ss;
ss << "Source database not found: " << source << std::endl;
Expand All @@ -130,7 +130,7 @@ void FdbOverlay::execute(const CmdArgs& args) {
throw eckit::UserError(ss.str(), Here());
}

std::unique_ptr<DB> dbTarget = DB::buildReader(target.canonical(), conf);
std::unique_ptr<DB> dbTarget = DB::buildReader(target, conf);

if (remove_) {
if (!dbTarget->exists()) {
Expand Down
19 changes: 10 additions & 9 deletions src/fdb5/types/TypesRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,29 @@
#ifndef fdb5_TypesRegistry_H
#define fdb5_TypesRegistry_H

#include <string>
#include <functional>
#include <map>
#include <memory>
#include <optional>
#include <functional>

#include "eckit/memory/NonCopyable.h"
#include <string>

namespace fdb5 {

class Type;

//----------------------------------------------------------------------------------------------------------------------

class TypesRegistry : private eckit::NonCopyable {
class TypesRegistry {

public: // methods

TypesRegistry();

TypesRegistry(const TypesRegistry&) = delete;
TypesRegistry& operator=(const TypesRegistry&) = delete;

TypesRegistry(TypesRegistry&&) = default;
TypesRegistry& operator=(TypesRegistry&&) = default;

~TypesRegistry();

const Type &lookupType(const std::string &keyword) const;
Expand All @@ -45,7 +48,6 @@ class TypesRegistry : private eckit::NonCopyable {
void dump( std::ostream &out ) const;
void dump( std::ostream &out, const std::string &keyword ) const;


private: // members

typedef std::map<std::string, Type *> TypeMap;
Expand All @@ -57,8 +59,7 @@ class TypesRegistry : private eckit::NonCopyable {

friend std::ostream &operator<<(std::ostream &s, const TypesRegistry &x);

void print( std::ostream &out ) const;

void print(std::ostream& out) const;
};

//----------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 9f71b93

Please sign in to comment.