Skip to content

Commit

Permalink
Merge branch 'develop' into feature/mtg2
Browse files Browse the repository at this point in the history
  • Loading branch information
sebvi committed Aug 6, 2024
2 parents 6443479 + 502d01e commit 5805a75
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 67 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ ecbuild_add_option( FEATURE ODB
DESCRIPTION "Add support for ODB data"
REQUIRED_PACKAGES "NAME odc VERSION 1.0" )

# METKIT config files support

ecbuild_add_option( FEATURE METKIT_CONFIG
DEFAULT ON
DESCRIPTION "Install metkit configuration files" )

# Temporary
ecbuild_add_option( FEATURE FAIL_ON_CCSDS
DESCRIPTION "Fail on CCSDS"
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.14
1.11.19
5 changes: 5 additions & 0 deletions src/metkit/config/LibMetkit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ eckit::PathName LibMetkit::paramYamlFile() {
eckit::PathName LibMetkit::paramStaticYamlFile() {
return "~metkit/share/metkit/params-static.yaml";
}

eckit::PathName LibMetkit::shortnameContextYamlFile() {
return "~metkit/share/metkit/shortname-context.yaml";
}

eckit::PathName LibMetkit::paramIDYamlFile() {
return "~metkit/share/metkit/paramids.yaml";
}
Expand Down
1 change: 1 addition & 0 deletions src/metkit/config/LibMetkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class LibMetkit : public eckit::system::Library {
static eckit::PathName paramStaticYamlFile();
static eckit::PathName paramIDYamlFile();
static eckit::PathName paramMatchingYamlFile();
static eckit::PathName shortnameContextYamlFile();
static eckit::PathName bufrSubtypesYamlFile();

static const LibMetkit& instance();
Expand Down
17 changes: 10 additions & 7 deletions src/metkit/mars/MarsLanguage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ static bool isnumeric(const std::string& s) {
}

std::string MarsLanguage::bestMatch(const MarsExpandContext& ctx, const std::string& name,
const std::vector<std::string>& values, bool fail, bool quiet,
const std::vector<std::string>& values, bool fail, bool quiet, bool fullMatch,
const std::map<std::string, std::string>& aliases) {
size_t score = 1;
size_t score = (fullMatch ? name.length() : 1);
std::vector<std::string> best;

static bool strict = eckit::Resource<bool>("$METKIT_LANGUAGE_STRICT_MODE", false);
Expand Down Expand Up @@ -221,9 +221,9 @@ std::string MarsLanguage::bestMatch(const MarsExpandContext& ctx, const std::str
}
}

static std::string empty;
if (best.empty()) {
if (!fail) {
static std::string empty;
if (!fail) {
return empty;
}

Expand All @@ -250,7 +250,10 @@ std::string MarsLanguage::bestMatch(const MarsExpandContext& ctx, const std::str
return best[0];
}


if (!fail) {
return empty;
}

std::ostringstream oss;
oss << "Ambiguous value '" << name << "' could be";

Expand Down Expand Up @@ -279,7 +282,7 @@ std::string MarsLanguage::expandVerb(const MarsExpandContext& ctx, const std::st
// }

// return cache_[verb] = bestMatch(verb, verbs_, true);
return bestMatch(ctx, verb, verbs_, true, true);
return bestMatch(ctx, verb, verbs_, true, true, false);
}

class TypeHidden : public Type {
Expand Down Expand Up @@ -322,7 +325,7 @@ MarsRequest MarsLanguage::expand(const MarsExpandContext& ctx, const MarsRequest
p = (*c).second;
}
else {
p = cache_[*j] = bestMatch(ctx, *j, keywords_, true, false, aliases_);
p = cache_[*j] = bestMatch(ctx, *j, keywords_, true, false, false, aliases_);
}

// if (seen.find(p) != seen.end()) {
Expand Down
1 change: 1 addition & 0 deletions src/metkit/mars/MarsLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MarsLanguage : private eckit::NonCopyable {
const std::vector<std::string>& values,
bool fail,
bool quiet,
bool fullMatch,
const StringMap& aliases = StringMap());

static eckit::Value jsonFile(const std::string& name);
Expand Down
7 changes: 4 additions & 3 deletions src/metkit/mars/MarsRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void MarsRequest::dump(std::ostream& s, const char* cr, const char* tab, bool ve
s << cr << cr;
}

void MarsRequest::json(eckit::JSON& s) const {
void MarsRequest::json(eckit::JSON& s, bool array) const {
s.startObject();
// s << "_verb" << verb_;
std::list<Parameter>::const_iterator begin = params_.begin();
Expand All @@ -173,15 +173,16 @@ void MarsRequest::json(eckit::JSON& s) const {
s << (*i).name();
const std::vector<std::string>& v = (*i).values();

if (v.size() != 1) {
bool list = v.size() != 1 || (array && (*i).type().multiple());
if (list) {
s.startList();
}

for (std::vector<std::string>::const_iterator k = v.begin(); k != v.end(); ++k) {
s << (*k);
}

if (v.size() != 1) {
if (list) {
s.endList();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/metkit/mars/MarsRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class MarsRequest {
/// Create a new MarsRequest from this one with only the given set of keys
MarsRequest subset(const std::set<std::string>&) const;

void json(eckit::JSON&) const;
void json(eckit::JSON&, bool array=false) const;

void md5(eckit::MD5&) const;

Expand Down
4 changes: 4 additions & 0 deletions src/metkit/mars/Type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ bool Type::flatten() const {
return flatten_;
}

bool Type::multiple() const {
return multiple_;
}

size_t Type::count(const std::vector<std::string>& values) const {
return flatten_ ? values.size() : 1;
}
Expand Down
1 change: 1 addition & 0 deletions src/metkit/mars/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Type : public eckit::Counted {

virtual const std::vector<std::string>& flattenValues(const MarsRequest& request);
virtual bool flatten() const;
virtual bool multiple() const;

virtual bool filter(const std::vector<std::string>& filter,
std::vector<std::string>& values) const;
Expand Down
2 changes: 1 addition & 1 deletion src/metkit/mars/TypeEnum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool TypeEnum::expand(const MarsExpandContext& ctx, std::string& value) const {
return true;
}

std::string v = MarsLanguage::bestMatch(ctx, value, values_, false, false, mapping_);
std::string v = MarsLanguage::bestMatch(ctx, value, values_, false, false, false, mapping_);
if (v.empty()) {
return false;
}
Expand Down
Loading

0 comments on commit 5805a75

Please sign in to comment.