From 8a7948d3528fb75e39eed0cfa004d0442ff599f2 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Thu, 12 Oct 2023 13:01:36 +0100 Subject: [PATCH] Exposed AxisOrder class --- src/metkit/hypercube/HyperCube.cc | 42 +++++++++---------------------- src/metkit/hypercube/HyperCube.h | 15 +++++++++++ src/metkit/mars/MarsRequest.cc | 14 ++++++----- src/metkit/mars/MarsRequest.h | 2 +- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/metkit/hypercube/HyperCube.cc b/src/metkit/hypercube/HyperCube.cc index 7c7ee5ef..2b1820e1 100644 --- a/src/metkit/hypercube/HyperCube.cc +++ b/src/metkit/hypercube/HyperCube.cc @@ -19,45 +19,28 @@ #include "metkit/mars/MarsRequest.h" #include "metkit/mars/Type.h" -namespace metkit { -namespace hypercube { +namespace metkit::hypercube { static metkit::mars::Type& type(const std::string& name) { static metkit::mars::MarsLanguage language("retrieve"); return *language.type(name); } -namespace { -class AxisOrder { -public: // methods - static AxisOrder& instance() { - static AxisOrder instance; - return instance; - } - - const std::vector& axes() { - return axes_; - } - -private: // methods - AxisOrder() { - eckit::Value axis = eckit::YAMLParser::decodeFile(axisYamlFile()); - const eckit::Value axesNames = axis["axes"]; - - for (size_t i = 0; i < axesNames.size(); ++i) { - axes_.push_back(axesNames[i]); - } - } +AxisOrder::AxisOrder() { + eckit::Value axis = eckit::YAMLParser::decodeFile(axisYamlFile()); + const eckit::Value axesNames = axis["axes"]; - eckit::PathName axisYamlFile() { - return "~metkit/share/metkit/axis.yaml"; + for (size_t i = 0; i < axesNames.size(); ++i) { + axes_.push_back(axesNames[i]); } +} -private: // members - std::vector axes_; -}; +AxisOrder& AxisOrder::instance() { + static AxisOrder instance; + return instance; } + class Axis { public: Axis(const std::string& name, const std::vector& values) : @@ -308,5 +291,4 @@ size_t HyperCube::fieldOrdinal(const metkit::mars::MarsRequest& r, bool noholes) return idx; } -} // namespace hypercube -} // namespace metkit +} // namespace metkit::hypercube diff --git a/src/metkit/hypercube/HyperCube.h b/src/metkit/hypercube/HyperCube.h index 32134987..8c720896 100644 --- a/src/metkit/hypercube/HyperCube.h +++ b/src/metkit/hypercube/HyperCube.h @@ -31,6 +31,21 @@ namespace hypercube { class Axis; +class AxisOrder { +public: // methods + static AxisOrder& instance(); + + const std::vector& axes() { return axes_; } + +private: // methods + AxisOrder(); + + eckit::PathName axisYamlFile() { return "~metkit/share/metkit/axis.yaml"; } + +private: // members + std::vector axes_; +}; + class HyperCube { public: HyperCube(const metkit::mars::MarsRequest&); diff --git a/src/metkit/mars/MarsRequest.cc b/src/metkit/mars/MarsRequest.cc index 124cfeb5..bb9f725e 100644 --- a/src/metkit/mars/MarsRequest.cc +++ b/src/metkit/mars/MarsRequest.cc @@ -121,18 +121,20 @@ bool MarsRequest::empty() const { void MarsRequest::print(std::ostream& s) const { - dump(s, "", ""); + dump(s, "", "", true); } -void MarsRequest::dump(std::ostream& s, const char* cr, const char* tab) const { +void MarsRequest::dump(std::ostream& s, const char* cr, const char* tab, bool verb) const { std::list::const_iterator begin = params_.begin(); std::list::const_iterator end = params_.end(); - - s << verb_; - + if (verb) { + s << verb_ << ','; + } + std::string separator = ""; if (begin != end) { - s << ',' << cr << tab; + s << separator << cr << tab; + separator = ","; int a = 0; for (std::list::const_iterator i = begin; i != end; ++i) { diff --git a/src/metkit/mars/MarsRequest.h b/src/metkit/mars/MarsRequest.h index 96edecf8..42985197 100644 --- a/src/metkit/mars/MarsRequest.h +++ b/src/metkit/mars/MarsRequest.h @@ -94,7 +94,7 @@ class MarsRequest { void md5(eckit::MD5&) const; - void dump(std::ostream&, const char* cr = "\n", const char* tab = "\t") const; + void dump(std::ostream&, const char* cr = "\n", const char* tab = "\t", bool verb = true) const; void setValuesTyped(Type*, const std::vector&);