metkitlib 1.16.0.9__cp312-cp312-manylinux_2_28_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. metkitlib/__init__.py +3 -0
  2. metkitlib/bin/bufr-sanity-check +0 -0
  3. metkitlib/bin/compare-mars-requests.py +265 -0
  4. metkitlib/bin/mars-archive-script +0 -0
  5. metkitlib/bin/parse-mars-request +0 -0
  6. metkitlib/include/metkit/api/metkit_c.h +255 -0
  7. metkitlib/include/metkit/codes/BUFRDecoder.h +47 -0
  8. metkitlib/include/metkit/codes/BufrContent.h +43 -0
  9. metkitlib/include/metkit/codes/CodesContent.h +67 -0
  10. metkitlib/include/metkit/codes/CodesHandleDeleter.h +41 -0
  11. metkitlib/include/metkit/codes/CodesSplitter.h +40 -0
  12. metkitlib/include/metkit/codes/GRIBDecoder.h +42 -0
  13. metkitlib/include/metkit/codes/GribAccessor.h +75 -0
  14. metkitlib/include/metkit/codes/GribHandle.h +121 -0
  15. metkitlib/include/metkit/codes/GribIterator.h +48 -0
  16. metkitlib/include/metkit/codes/LibEccodes.h +38 -0
  17. metkitlib/include/metkit/codes/MallocCodesContent.h +46 -0
  18. metkitlib/include/metkit/codes/api/CodesAPI.h +365 -0
  19. metkitlib/include/metkit/codes/api/CodesTypes.h +93 -0
  20. metkitlib/include/metkit/codes/api/GeoIterator.h +104 -0
  21. metkitlib/include/metkit/codes/api/KeyIterator.h +187 -0
  22. metkitlib/include/metkit/config/LibMetkit.h +56 -0
  23. metkitlib/include/metkit/fields/FieldIndex.h +58 -0
  24. metkitlib/include/metkit/fields/FieldIndexList.h +40 -0
  25. metkitlib/include/metkit/fields/SimpleFieldIndex.h +41 -0
  26. metkitlib/include/metkit/hypercube/HyperCube.h +105 -0
  27. metkitlib/include/metkit/hypercube/HyperCubePayloaded.h +88 -0
  28. metkitlib/include/metkit/mars/BaseProtocol.h +95 -0
  29. metkitlib/include/metkit/mars/ClientTask.h +206 -0
  30. metkitlib/include/metkit/mars/DHSProtocol.h +106 -0
  31. metkitlib/include/metkit/mars/MarsExpandContext.h +42 -0
  32. metkitlib/include/metkit/mars/MarsExpansion.h +83 -0
  33. metkitlib/include/metkit/mars/MarsExpension.h +28 -0
  34. metkitlib/include/metkit/mars/MarsHandle.h +83 -0
  35. metkitlib/include/metkit/mars/MarsLanguage.h +106 -0
  36. metkitlib/include/metkit/mars/MarsLocation.h +100 -0
  37. metkitlib/include/metkit/mars/MarsParsedRequest.h +44 -0
  38. metkitlib/include/metkit/mars/MarsParser.h +70 -0
  39. metkitlib/include/metkit/mars/MarsRequest.h +198 -0
  40. metkitlib/include/metkit/mars/MarsRequestHandle.h +79 -0
  41. metkitlib/include/metkit/mars/Matcher.h +88 -0
  42. metkitlib/include/metkit/mars/Param.b +43 -0
  43. metkitlib/include/metkit/mars/Param.h +84 -0
  44. metkitlib/include/metkit/mars/ParamID.h +306 -0
  45. metkitlib/include/metkit/mars/Parameter.h +87 -0
  46. metkitlib/include/metkit/mars/Quantile.h +73 -0
  47. metkitlib/include/metkit/mars/RequestEnvironment.h +58 -0
  48. metkitlib/include/metkit/mars/StepRange.b +43 -0
  49. metkitlib/include/metkit/mars/StepRange.h +164 -0
  50. metkitlib/include/metkit/mars/StepRangeNormalise.h +95 -0
  51. metkitlib/include/metkit/mars/Type.h +265 -0
  52. metkitlib/include/metkit/mars/TypeAny.h +39 -0
  53. metkitlib/include/metkit/mars/TypeDate.h +42 -0
  54. metkitlib/include/metkit/mars/TypeEnum.h +67 -0
  55. metkitlib/include/metkit/mars/TypeExpver.h +40 -0
  56. metkitlib/include/metkit/mars/TypeFloat.h +41 -0
  57. metkitlib/include/metkit/mars/TypeInteger.h +55 -0
  58. metkitlib/include/metkit/mars/TypeLowercase.h +38 -0
  59. metkitlib/include/metkit/mars/TypeMixed.h +47 -0
  60. metkitlib/include/metkit/mars/TypeParam.h +45 -0
  61. metkitlib/include/metkit/mars/TypeRange.h +41 -0
  62. metkitlib/include/metkit/mars/TypeRegex.h +49 -0
  63. metkitlib/include/metkit/mars/TypeTime.h +44 -0
  64. metkitlib/include/metkit/mars/TypeToByList.h +137 -0
  65. metkitlib/include/metkit/mars/TypeToByListQuantile.h +41 -0
  66. metkitlib/include/metkit/mars/TypesFactory.h +92 -0
  67. metkitlib/include/metkit/metkit_config.h +26 -0
  68. metkitlib/include/metkit/metkit_ecbuild_config.h +72 -0
  69. metkitlib/include/metkit/metkit_version.h +30 -0
  70. metkitlib/include/metkit/pointdb/DataSource.h +91 -0
  71. metkitlib/include/metkit/pointdb/FieldIndexer.h +128 -0
  72. metkitlib/include/metkit/pointdb/GribDataSource.h +47 -0
  73. metkitlib/include/metkit/pointdb/GribFieldInfo.h +76 -0
  74. metkitlib/include/metkit/pointdb/GribHandleDataSource.h +58 -0
  75. metkitlib/include/metkit/pointdb/PointIndex.h +121 -0
  76. metkitlib/include/metkit/pointdb/bits.h +1834 -0
  77. metkitlib/include/metkit/pointdb/masks.h +22 -0
  78. metkitlib/include/metkit/tool/MetkitTool.h +79 -0
  79. metkitlib/lib64/cmake/metkit/metkit-config-version.cmake +43 -0
  80. metkitlib/lib64/cmake/metkit/metkit-config.cmake +112 -0
  81. metkitlib/lib64/cmake/metkit/metkit-import.cmake +14 -0
  82. metkitlib/lib64/cmake/metkit/metkit-targets-relwithdebinfo.cmake +46 -0
  83. metkitlib/lib64/cmake/metkit/metkit-targets.cmake +116 -0
  84. metkitlib/lib64/libmetkit.so +0 -0
  85. metkitlib/lib64/pkgconfig/metkit.pc +33 -0
  86. metkitlib/share/metkit/axis.yaml +63 -0
  87. metkitlib/share/metkit/bufr-subtypes.yaml +140 -0
  88. metkitlib/share/metkit/chemids.yaml +209 -0
  89. metkitlib/share/metkit/language.yaml +1707 -0
  90. metkitlib/share/metkit/modifiers.yaml +341 -0
  91. metkitlib/share/metkit/obstype.yaml +182 -0
  92. metkitlib/share/metkit/odb/marsrequest.yaml +9 -0
  93. metkitlib/share/metkit/param-matching.yaml +16 -0
  94. metkitlib/share/metkit/paramids.yaml +24034 -0
  95. metkitlib/share/metkit/params-static.yaml +212 -0
  96. metkitlib/share/metkit/params.yaml +9833 -0
  97. metkitlib/share/metkit/reportype.yaml +525 -0
  98. metkitlib/share/metkit/shortname-context.yaml +192 -0
  99. metkitlib-1.16.0.9.dist-info/METADATA +75 -0
  100. metkitlib-1.16.0.9.dist-info/RECORD +104 -0
  101. metkitlib-1.16.0.9.dist-info/WHEEL +5 -0
  102. metkitlib-1.16.0.9.dist-info/licenses/AUTHORS +12 -0
  103. metkitlib-1.16.0.9.dist-info/licenses/LICENSE +190 -0
  104. metkitlib-1.16.0.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,100 @@
1
+ /*
2
+ * (C) Copyright 1996- ECMWF.
3
+ *
4
+ * This software is licensed under the terms of the Apache Licence Version 2.0
5
+ * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * In applying this licence, ECMWF does not waive the privileges and immunities
7
+ * granted to it by virtue of its status as an intergovernmental organisation nor
8
+ * does it submit to any jurisdiction.
9
+ */
10
+
11
+ /// @author Tiago Quintino
12
+
13
+ /// @date Dec 2015
14
+
15
+ #ifndef metkit_MarsLocation_H
16
+ #define metkit_MarsLocation_H
17
+
18
+
19
+ #include "eckit/config/Configuration.h"
20
+ #include "metkit/mars/MarsRequest.h"
21
+
22
+ namespace eckit {
23
+ class JSON;
24
+ class Stream;
25
+ } // namespace eckit
26
+
27
+ namespace metkit {
28
+ namespace mars {
29
+
30
+ //----------------------------------------------------------------------------------------------------------------------
31
+
32
+ /// MarsLocation represents a MarsRequest associated with the hostname and port.
33
+ /// From this location, the data can be directly retrieved without going through a queueing system.
34
+ /// It assumes all the data identified by the request can be got from the same location.
35
+ /// This is useful to identify and retrieve data directly from memory.
36
+ ///
37
+ /// If we consider that a MarsRequest is analogue to a URI, then a MarsLocation is an analogue to a URL
38
+
39
+ class MarsLocation {
40
+
41
+ public: // methods
42
+
43
+ // - Constructors
44
+
45
+ MarsLocation(const MarsRequest& r, const std::string& hostname, int port);
46
+ MarsLocation(eckit::Stream&);
47
+ MarsLocation(const eckit::Configuration&);
48
+
49
+ // -- Destructor
50
+
51
+ ~MarsLocation();
52
+
53
+ // -- Operators
54
+
55
+ operator eckit::Value() const;
56
+
57
+ void json(eckit::JSON&) const;
58
+
59
+ const MarsRequest& request() const;
60
+
61
+ std::string hostname() const;
62
+
63
+ int port() const;
64
+
65
+
66
+ private: // members
67
+
68
+ MarsRequest request_;
69
+ std::string hostname_;
70
+ int port_;
71
+
72
+ private: // methods
73
+
74
+ void print(std::ostream&) const;
75
+ void encode(eckit::Stream&) const;
76
+
77
+ // -- Class members
78
+
79
+
80
+ friend std::ostream& operator<<(std::ostream& s, const MarsLocation& r) {
81
+ r.print(s);
82
+ return s;
83
+ }
84
+
85
+ friend eckit::JSON& operator<<(eckit::JSON& s, const MarsLocation& r) {
86
+ r.json(s);
87
+ return s;
88
+ }
89
+
90
+ friend eckit::Stream& operator<<(eckit::Stream& s, const MarsLocation& r) {
91
+ r.encode(s);
92
+ return s;
93
+ }
94
+ };
95
+
96
+ //----------------------------------------------------------------------------------------------------------------------
97
+ } // namespace mars
98
+ } // namespace metkit
99
+
100
+ #endif
@@ -0,0 +1,44 @@
1
+ /*
2
+ * (C) Copyright 1996- ECMWF.
3
+ *
4
+ * This software is licensed under the terms of the Apache Licence Version 2.0
5
+ * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * In applying this licence, ECMWF does not waive the privileges and immunities
7
+ * granted to it by virtue of its status as an intergovernmental organisation nor
8
+ * does it submit to any jurisdiction.
9
+ */
10
+
11
+ /// @author Manuel Fuentes
12
+ /// @author Baudouin Raoult
13
+ /// @author Tiago Quintino
14
+
15
+ /// @date Sep 96
16
+
17
+ #pragma once
18
+
19
+ #include "metkit/mars/MarsRequest.h"
20
+
21
+ namespace metkit::mars {
22
+
23
+ //----------------------------------------------------------------------------------------------------------------------
24
+
25
+ class MarsParsedRequest : public MarsRequest {
26
+ public:
27
+
28
+ MarsParsedRequest(const std::string& verb, size_t line);
29
+ virtual ~MarsParsedRequest() = default;
30
+
31
+ virtual void info(std::ostream&) const;
32
+ friend std::ostream& operator<<(std::ostream& s, const MarsParsedRequest& r) {
33
+ r.info(s);
34
+ return s;
35
+ }
36
+
37
+ private:
38
+
39
+ std::size_t line_;
40
+ };
41
+
42
+ //----------------------------------------------------------------------------------------------------------------------
43
+
44
+ } // namespace metkit::mars
@@ -0,0 +1,70 @@
1
+ /*
2
+ * (C) Copyright 1996- ECMWF.
3
+ *
4
+ * This software is licensed under the terms of the Apache Licence Version 2.0
5
+ * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * In applying this licence, ECMWF does not waive the privileges and immunities
7
+ * granted to it by virtue of its status as an intergovernmental organisation nor
8
+ * does it submit to any jurisdiction.
9
+ */
10
+
11
+ /// @author Baudouin Raoult
12
+ /// @date Jun 2012
13
+
14
+ #pragma once
15
+
16
+ #include "eckit/parser/StreamParser.h"
17
+ #include "eckit/types/Types.h"
18
+ #include "metkit/mars/MarsParsedRequest.h"
19
+
20
+ namespace metkit::mars {
21
+
22
+ class MarsExpandContext;
23
+ class MarsRequest;
24
+
25
+
26
+ //----------------------------------------------------------------------------------------------------------------------
27
+
28
+
29
+ class MarsParserCallback {
30
+ public:
31
+
32
+ virtual void operator()(const MarsExpandContext&, const MarsRequest&) = 0;
33
+
34
+ protected:
35
+
36
+ virtual ~MarsParserCallback() = default;
37
+ };
38
+
39
+
40
+ //----------------------------------------------------------------------------------------------------------------------
41
+
42
+
43
+ class MarsParser : public eckit::StreamParser {
44
+
45
+ public: // methods
46
+
47
+ MarsParser(std::istream& in);
48
+
49
+ std::vector<MarsParsedRequest> parse();
50
+
51
+ void parse(MarsParserCallback& cb);
52
+
53
+ static void quoted(std::ostream& out, const std::string& value);
54
+
55
+ private: // methods
56
+
57
+ MarsParsedRequest parseRequest();
58
+ std::string parseVerb();
59
+ std::string parseKeyword();
60
+ std::vector<std::string> parseValues();
61
+ std::string parseValue();
62
+ std::string parseIndent();
63
+ std::string parseIndents();
64
+
65
+ std::string parseString(char c);
66
+ };
67
+
68
+ //----------------------------------------------------------------------------------------------------------------------
69
+
70
+ } // namespace metkit::mars
@@ -0,0 +1,198 @@
1
+ /*
2
+ * (C) Copyright 1996- ECMWF.
3
+ *
4
+ * This software is licensed under the terms of the Apache Licence Version 2.0
5
+ * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * In applying this licence, ECMWF does not waive the privileges and immunities
7
+ * granted to it by virtue of its status as an intergovernmental organisation nor
8
+ * does it submit to any jurisdiction.
9
+ */
10
+
11
+ /// @author Manuel Fuentes
12
+ /// @author Baudouin Raoult
13
+ /// @author Tiago Quintino
14
+
15
+ /// @date Sep 96
16
+
17
+ #ifndef metkit_MarsRequest_H
18
+ #define metkit_MarsRequest_H
19
+
20
+ #include <optional>
21
+ #include "eckit/value/Value.h"
22
+ #include "metkit/mars/Parameter.h"
23
+
24
+ namespace eckit {
25
+ class MD5;
26
+ namespace message {
27
+ class Message;
28
+ }
29
+ } // namespace eckit
30
+
31
+ struct metkit_marsrequest_t;
32
+
33
+ namespace metkit::mars {
34
+
35
+ class Type;
36
+ class MarsRequest;
37
+
38
+ //----------------------------------------------------------------------------------------------------------------------
39
+
40
+ class MarsRequest {
41
+ public: // methods
42
+
43
+ MarsRequest();
44
+
45
+ explicit MarsRequest(const std::string&);
46
+ explicit MarsRequest(eckit::Stream&, bool lowercase = false);
47
+
48
+ MarsRequest(const std::string&, const std::map<std::string, std::string>&);
49
+ MarsRequest(const std::string&, const eckit::Value&);
50
+
51
+ explicit MarsRequest(const eckit::message::Message&);
52
+
53
+ ~MarsRequest() = default;
54
+
55
+ bool operator<(const MarsRequest& other) const;
56
+
57
+ // eckit::Value& operator[](const std::string&);
58
+ const std::string& operator[](const std::string&) const;
59
+
60
+ operator eckit::Value() const;
61
+
62
+ const std::string& verb() const;
63
+
64
+ size_t countValues(const std::string&) const;
65
+ bool has(const std::string&) const;
66
+
67
+ bool is(const std::string& param, const std::string& value) const;
68
+
69
+ const std::vector<std::string>& values(const std::string&, bool emptyOk = false) const;
70
+
71
+ // Returns reference to values or nullopt if not found
72
+ std::optional<std::reference_wrapper<const std::vector<std::string>>> get(const std::string& keyword) const;
73
+
74
+ template <class T>
75
+ size_t getValues(const std::string& name, std::vector<T>& v, bool emptyOk = false) const;
76
+
77
+ void getParams(std::vector<std::string>&) const;
78
+ std::vector<std::string> params() const;
79
+
80
+ std::list<Parameter>& parameters() { return params_; }
81
+
82
+ const std::list<Parameter>& parameters() const { return params_; }
83
+
84
+ void verb(const std::string&);
85
+
86
+ void values(const std::string&, const std::vector<std::string>&);
87
+
88
+ template <class T>
89
+ void setValue(const std::string& name, const T& value);
90
+
91
+ void setValue(const std::string& name, const char* value);
92
+
93
+ void unsetValues(const std::string&);
94
+
95
+ /// Splits a MARS request into multiple requests along the provided key
96
+ std::vector<MarsRequest> split(const std::string& keys) const;
97
+
98
+ /// Splits a MARS request into multiple requests along the indicated keys
99
+ std::vector<MarsRequest> split(const std::vector<std::string>& keys) const;
100
+
101
+ /// Merges one MarsRequest into another
102
+ /// @todo Improve performance -- uses O(N^2) search / merge in std::list's
103
+ void merge(const MarsRequest& other);
104
+
105
+ /// Create a new MarsRequest from this one with only the given set of keys
106
+ MarsRequest subset(const std::set<std::string>&) const;
107
+
108
+ void json(eckit::JSON&, bool array = false) const;
109
+
110
+ void md5(eckit::MD5&) const;
111
+
112
+ void dump(std::ostream&, const char* cr = "\n", const char* tab = "\t", bool verb = true) const;
113
+
114
+ void setValuesTyped(Type*, const std::vector<std::string>&);
115
+
116
+ bool filter(const MarsRequest& filter);
117
+ bool matches(const MarsRequest& filter) const;
118
+ bool empty() const;
119
+
120
+ size_t count() const;
121
+
122
+ MarsRequest extract(const std::string& category) const;
123
+
124
+ void erase(const std::string& param);
125
+
126
+ std::string asString() const;
127
+
128
+ public: // static methods
129
+
130
+ static MarsRequest parse(const std::string& s, bool strict = false);
131
+ static std::vector<MarsRequest> parse(std::istream&, bool strict = false);
132
+
133
+ /// Implementation in api/metkit_c.cc
134
+ static const MarsRequest& fromOpaque(const metkit_marsrequest_t* request);
135
+
136
+ private: // members
137
+
138
+ std::string verb_;
139
+ std::list<Parameter> params_;
140
+
141
+ private: // methods
142
+
143
+ void print(std::ostream&) const;
144
+ void encode(eckit::Stream&) const;
145
+
146
+ std::list<Parameter>::const_iterator find(const std::string&) const;
147
+ std::list<Parameter>::iterator find(const std::string&);
148
+
149
+ // -- Class members
150
+
151
+ static eckit::ClassSpec classSpec_;
152
+ static eckit::Reanimator<MarsRequest> reanimator_;
153
+
154
+ friend std::ostream& operator<<(std::ostream& s, const MarsRequest& r) {
155
+ r.print(s);
156
+ return s;
157
+ }
158
+
159
+ friend eckit::JSON& operator<<(eckit::JSON& s, const MarsRequest& r) {
160
+ r.json(s);
161
+ return s;
162
+ }
163
+
164
+ friend eckit::Stream& operator<<(eckit::Stream& s, const MarsRequest& r) {
165
+ r.encode(s);
166
+ return s;
167
+ }
168
+ };
169
+
170
+
171
+ template <class T>
172
+ size_t MarsRequest::getValues(const std::string& name, std::vector<T>& v, bool emptyOk) const {
173
+ const std::vector<std::string>& s = values(name, emptyOk);
174
+
175
+ eckit::Translator<std::string, T> t;
176
+
177
+ v.clear();
178
+
179
+ for (std::vector<std::string>::const_iterator j = s.begin(); j != s.end(); ++j) {
180
+ v.push_back(t(*j));
181
+ }
182
+
183
+ return v.size();
184
+ }
185
+
186
+
187
+ template <class T>
188
+ void MarsRequest::setValue(const std::string& name, const T& value) {
189
+ eckit::Translator<T, std::string> t;
190
+ std::vector<std::string> v(1, t(value));
191
+ values(name, v);
192
+ }
193
+
194
+ //----------------------------------------------------------------------------------------------------------------------
195
+
196
+ } // namespace metkit::mars
197
+
198
+ #endif
@@ -0,0 +1,79 @@
1
+ /*
2
+ * (C) Copyright 1996- ECMWF.
3
+ *
4
+ * This software is licensed under the terms of the Apache Licence Version 2.0
5
+ * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * In applying this licence, ECMWF does not waive the privileges and immunities
7
+ * granted to it by virtue of its status as an intergovernmental organisation nor
8
+ * does it submit to any jurisdiction.
9
+ */
10
+
11
+ // File MarsRequestHandle.h
12
+ // Baudouin Raoult - (c) ECMWF Feb 12
13
+
14
+ #ifndef MarsRequestHandle_H
15
+ #define MarsRequestHandle_H
16
+
17
+ #include <memory>
18
+
19
+ #include "eckit/exception/Exceptions.h"
20
+ #include "eckit/io/DataHandle.h"
21
+
22
+ #include "metkit/mars/BaseProtocol.h"
23
+ #include "metkit/mars/MarsRequest.h"
24
+
25
+ namespace metkit {
26
+ namespace mars {
27
+
28
+ class MarsRequestHandle : public eckit::DataHandle {
29
+ public:
30
+
31
+ class RetryTransfer : public eckit::Exception {
32
+ virtual bool retryOnClient() const { return true; }
33
+
34
+ public:
35
+
36
+ RetryTransfer(const std::string& what) : eckit::Exception(what) {}
37
+ };
38
+
39
+ public:
40
+
41
+ MarsRequestHandle(eckit::Stream&);
42
+
43
+ MarsRequestHandle(const metkit::mars::MarsRequest& request, const eckit::Configuration& database);
44
+
45
+ MarsRequestHandle(const metkit::mars::MarsRequest& request, metkit::mars::BaseProtocol* protocol);
46
+
47
+ ~MarsRequestHandle();
48
+
49
+ // -- Overridden methods (from Streamable)
50
+ virtual std::string className() const override { return "MarsRequestHandle"; }
51
+ virtual const eckit::ReanimatorBase& reanimator() const override;
52
+ static const eckit::ClassSpec& classSpec();
53
+
54
+ private: // members
55
+
56
+ metkit::mars::MarsRequest request_;
57
+
58
+ std::unique_ptr<BaseProtocol> protocol_;
59
+
60
+ bool opened_;
61
+
62
+ private: // members
63
+
64
+ void print(std::ostream&) const override;
65
+ void encode(eckit::Stream&) const override;
66
+
67
+ eckit::Length openForRead() override;
68
+ void openForWrite(const eckit::Length&) override;
69
+ void openForAppend(const eckit::Length&) override;
70
+ long read(void*, long) override;
71
+ long write(const void*, long) override;
72
+ void close() override;
73
+ bool canSeek() const override;
74
+ };
75
+
76
+ } // namespace mars
77
+ } // namespace metkit
78
+
79
+ #endif
@@ -0,0 +1,88 @@
1
+ /*
2
+ * (C) Copyright 2025- ECMWF.
3
+ *
4
+ * This software is licensed under the terms of the Apache Licence Version 2.0
5
+ * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * In applying this licence, ECMWF does not waive the privileges and immunities
7
+ * granted to it by virtue of its status as an intergovernmental organisation nor
8
+ * does it submit to any jurisdiction.
9
+ */
10
+
11
+ /// @author Chris Bradley
12
+ /// @date Sep 2025
13
+
14
+ #pragma once
15
+
16
+ #include <functional>
17
+ #include <map>
18
+ #include <string>
19
+ #include <variant>
20
+ #include "eckit/utils/Regex.h"
21
+ #include "metkit/mars/MarsRequest.h"
22
+
23
+ namespace metkit::mars {
24
+
25
+ class RequestLike;
26
+
27
+ /// Parse a match expression into a map of key:regex pairs
28
+ /// @param expr is a series of comma separated key:regex pairs e.g.
29
+ /// "expver=(0001|o[0-9a-z]{3}),dataset=^climate-dt$"
30
+ std::map<std::string, eckit::Regex> parseMatchString(const std::string& expr);
31
+
32
+ // -------------------------------------------------------------------------------------------------------------
33
+
34
+ /// For matching requests against a set of key:regex conditions. For constructing select/exclude filters.
35
+
36
+ class Matcher {
37
+
38
+ public:
39
+
40
+ /// Policy for handling requests with multiple values for a given key.
41
+ enum class Policy {
42
+ All, ///< Require all values to match
43
+ Any ///< Require at least one value to match
44
+ };
45
+
46
+ /// Policy for handling keys in the matcher that are absent in the request.
47
+ enum class MatchMissingPolicy {
48
+ MatchOnMissing,
49
+ DontMatchOnMissing
50
+ };
51
+ static constexpr auto MatchOnMissing = MatchMissingPolicy::MatchOnMissing;
52
+ static constexpr auto DontMatchOnMissing = MatchMissingPolicy::DontMatchOnMissing;
53
+
54
+
55
+ public:
56
+
57
+ /// Construct a matcher from a map of key:regex pairs
58
+ Matcher(std::map<std::string, eckit::Regex> regexMap, Policy policy);
59
+
60
+ Matcher(const std::string& expr, Policy policy);
61
+
62
+ bool match(const RequestLike& request, MatchMissingPolicy matchOnMissing = MatchOnMissing) const;
63
+ bool match(const MarsRequest& request, MatchMissingPolicy matchOnMissing = MatchOnMissing) const;
64
+
65
+ private:
66
+
67
+ std::map<std::string, eckit::Regex> regexMap_;
68
+ Policy policy_;
69
+ };
70
+
71
+ // ----------------------------------------------------------------------------------------------------------------------
72
+
73
+ /// Interface to access keyword / value(s) pairs across similar types.
74
+ /// Designed to allow uniform access to keywords / values for MarsRequest / fdb5::Key
75
+ class RequestLike {
76
+ public:
77
+
78
+ using values_t = std::variant<std::reference_wrapper<const std::string>, ///< single value
79
+ std::reference_wrapper<const std::vector<std::string>> ///< multiple values
80
+ >;
81
+
82
+ virtual ~RequestLike() = default;
83
+
84
+ /// Get a reference_wrapper to the value(s) for the given keyword, or nullopt if not found
85
+ virtual std::optional<values_t> get(const std::string& keyword) const = 0;
86
+ };
87
+
88
+ } // namespace metkit::mars
@@ -0,0 +1,43 @@
1
+
2
+ Param(eckit::Bless& b):
3
+ table_(b(&table_)),
4
+ value_(b(&value_))
5
+ {
6
+ }
7
+
8
+ Param(eckit::Evolve b):
9
+ table_(b("Param","table_")),
10
+ value_(b("Param","value_"))
11
+ {
12
+ }
13
+
14
+ static const char* specName() { return "Param"; }
15
+ static void isa(TypeInfo* t) { eckit::Isa::add(t,specName()); }
16
+ static eckit::Isa* isa() { return eckit::Isa::get(specName()); }
17
+
18
+ static void schema(eckit::Schema& s)
19
+ {
20
+ s.start(specName(),sizeof(Param));
21
+ s.member("table_",member_size(Param,table_),member_offset(Param,table_),"long");
22
+ s.member("value_",member_size(Param,value_),member_offset(Param,value_),"long");
23
+ s.end(specName());
24
+ }
25
+
26
+
27
+ void describe(std::ostream& s,int depth = 0) const {
28
+ eckit::_startClass(s,depth,specName());
29
+ eckit::_describe(s,depth+1,"table_",table_);
30
+ eckit::_describe(s,depth+1,"value_",value_);
31
+ eckit::_endClass(s,depth,specName());
32
+ }
33
+
34
+
35
+
36
+ void _export(eckit::Exporter& h) const {
37
+ eckit::_startClass(h,"Param");
38
+ eckit::_export(h,"table_",table_);
39
+ eckit::_export(h,"value_",value_);
40
+ eckit::_endClass(h,"Param");
41
+ }
42
+
43
+