Loading...
Searching...
No Matches
ODIMPath.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31#ifndef ODIM_PATH
32#define ODIM_PATH
33
34
35#include <drain/Log.h>
36#include <ostream>
37//#include <cmath>
38#include <string>
39#include <map>
40//#include <algorithm>
41
42#include <drain/util/Path.h>
43#include <drain/util/Flags.h>
44
45
46namespace rack {
47
48
72//struct odim_id {};
73//typedef drain::GlobalFlags<odim_id> odim_flags;
74
75class ODIMPathElem;
76
77std::ostream & operator<<(std::ostream & ostr, const ODIMPathElem & p);
78
79
80
83
84public:
85
86
87 // typedef drain::Flagger flag_t;
88 // typedef drain::Flagger::dict_t dict_t;
89 // typedef drain::Flagger::ivalue_t group_t;
90
92 typedef unsigned int group_t;
93 //typedef drain::Flagger2<drain::SingleFlagger<group_t> > flag_t;
95 typedef flag_t::dict_t dict_t;
96
98 static const group_t NONE = 0;
99
102 static const group_t ROOT = 1;
103
104
106 static const group_t DATASET = 2; // 8; // one bit (16) must be unique
107
109 static const group_t DATA = 4; // 16;
110
112 static const group_t ARRAY = 8; // low index, to appear before QUALITY (below)
113
115 static const group_t QUALITY = 16;
116
119
121 static const group_t ALL_LEVELS = (ROOT | DATASET | DATA); // | QUALITY
122
123
124
125
127 static const group_t WHAT = 32;
128
130 static const group_t WHERE = 64;
131
133 static const group_t HOW = 128; // ylennysmerkki
134
137
138
140 static const group_t ALL_GROUPS = 255; // 511!
141
143 static const group_t PALETTE = 256;
144
146 static const group_t LEGEND = 512;
147
149
152 //static const group_t OTHER = 255 ^ IS_INDEXED; // OTHER is not indexed...
153 static const group_t OTHER = 1024; // Assume OTHER is not indexed.
154 //static const group_t _SCAN = 2048; // Extension
155 //static const group_t _MOMENT = 4096; // Extension
156
157
159 static const group_t IS_INDEXED = (DATASET | DATA | QUALITY ); // | _SCAN | _MOMENT);
160
161
162 static inline
163 bool isIndexed(group_t group){
164 return (group & IS_INDEXED) > 0;
165 }
166
167 static inline
168 bool isQuality(group_t group){
169 return (group == QUALITY);
170 }
171
172
173 static
174 const dict_t & getDictionary();
175
176 group_t group;
177
178
179 // Running index of the element. Applied also as a lower limit in path matching.
180 typedef int index_t;
181 index_t index;
182
183 static
184 const index_t INDEX_MAX;
185
186
187 // Change 2024/01: default index 0->1
189 inline
190 ODIMPathElem(group_t group = ROOT, index_t index = 1) : group(group), index(index){
191 }
192
193 /*
194 inline
195 ODIMPathElem(group_t group, index_t index) : group(group), index(index){ //, indexMax(index) { // root=NONE
196 }
197 */
198
199 // TODO: CHECK: -Wdeprecated-copy fires because this copy constructor is user-declared but
200 // operator=(const ODIMPathElem&) is not (only the templated operator=(const T&) below exists);
201 // the implicit copy-assignment operator does a plain memberwise copy (always copying
202 // currentStr), which differs from this constructor's conditional copy (only when group==OTHER).
203 // Confirm whether copy-construction and copy-assignment are meant to behave the same way.
205 inline
206 ODIMPathElem(const ODIMPathElem &e) : group(e.group), index(e.index){ // , indexMax(e.indexMax) {
207 if (e.group == OTHER)
208 currentStr = e.currentStr;
209 }
210
212 inline
213 ODIMPathElem(const std::string &s) : group(ROOT), index(0){ //, indexMax(0){
214 set(s);
215 }
216
218 inline
219 ODIMPathElem(const char *s): group(ROOT), index(0){ //, indexMax(0) {
220 set(s);
221 }
222
223 virtual inline
224 ~ODIMPathElem(){};
225
226 void reset();
227
229
234 template <class T>
235 inline
236 ODIMPathElem & operator=(const T &s){
237 set(s);
238 return *this;
239 }
240
241
243
246 inline
247 ODIMPathElem & operator=(const char *s){
248 set(s);
249 return *this;
250 }
251
252 // ?? Require explicit indexing.
253 // ?? ODIMPathMatcher uses mixed groups, so "data2|what" should result index=2, not index=0.
254
256 /*
257 virtual inline
258 bool set(group_t g, index_t i = 0){
259 group = g;
260 index = i;
261 //indexMax = i; // not relevant, or check
262 if ((i>0) && !isIndexed(g)){
263 drain::Logger mout(__FILE__, __FUNCTION__);
264 mout.note("index (" , i , ") given for non-indexed element:" , *this );
265 return false;
266 }
267 return (g != ODIMPathElem::OTHER);
268 }
269 */
270
272 virtual inline
273 //bool
274 void set(group_t g, index_t i = 0){
275 group = g;
276 index = i;
277 //indexMax = i; // not relevant, or check
278 if ((i>0) && !isIndexed(g)){
280 mout.note("index (" , i , ") given for non-indexed element:" , *this );
281 return; // false;
282 }
283 return; // (g != ODIMPathElem::OTHER);
284 }
285
287
294 virtual inline
295 void set(const std::string &s){
296 reset();
297 //return
298 add(s);
299 }
300
302 inline
303 bool is(group_t g) const {
304 return (group == g);
305 }
306
308 inline
309 bool isRoot() const {
310 return (group == ROOT);
311 }
312
314 inline
315 bool empty() const {
316 return isRoot();
317 }
318
319
321 /*
322 inline
323 bool isUnset() const {
324 return (group == NONE);
325 }
326 */
327
329 inline
330 bool isIndexed() const {
331 return isIndexed(this->group);
332 }
333
335 /*
336 * Warning: DATA and DATASET "belong" to quality?... (QUALITY = DATASET | DATA )
337 */
338 inline
339 bool belongsTo(int groupFilter) const {
340 // Notice: filter must fully "cover" group bits (especially because QUALITY = DATASET | DATA )
341 return ((this->group & groupFilter) == this->group);
342 //return ((this->group & groupFilter) != 0);
343 }
344
345 inline
346 group_t getType() const {
347 return this->group;
348 }
349
350 inline
351 index_t getIndex() const {
352 return index;
353 }
354
356 const std::string & getPrefix() const;
357
358 char getCharCode() const;
359
361 static
362 const std::string & getKey(group_t g);
363
365 inline
366 const std::string & getKey() const {
367 return getKey(this->group);
368 }
369
371 virtual
372 std::ostream & toStream(std::ostream & sstr) const;
373
375 // virtual std::ostream & toStream(std::ostream & sstr) const;
376
377
378 const std::string & str() const {
379 if (this->group != OTHER){ // for OTHER, its already set.
380 std::stringstream sstr;
381 toStream(sstr);
382 //sstr << *this;
383 currentStr = sstr.str();
384 }
385 return currentStr;
386 }
387
388 /*
389 inline
390 const std::string & getStr() const {
391 std::stringstream sstr;
392 toStream(sstr);
393 //sstr << *this;
394 str = sstr.str();
395 return str;
396 }
397 */
398 inline
399 operator const std::string &() const {
400 return str();
401 }
402
404 virtual
405 bool extractPrefix(const std::string &s, bool indexed);
406
407protected:
408
409 //bool
410 void add(const std::string &s);
411
412
414 // In ODIMPathMatcher, an index range will be extracted.
415 virtual
416 void extractIndex(const std::string &s);
417
418 // Experimental. for index int and Range!
419 template <class T>
420 static
421 void extractIndex(const std::string &s, T & idx);
422
423 mutable
424 std::string currentStr;
425
426
427};
428
429template <>
430void ODIMPathElem::extractIndex(const std::string &s, ODIMPathElem::index_t & idx);
431
432
433extern ODIMPathElem odimROOT;
434extern ODIMPathElem odimWHERE;
435extern ODIMPathElem odimWHAT;
436extern ODIMPathElem odimARRAY;
437
439bool operator<(const ODIMPathElem & e1, const ODIMPathElem & e2);
440
441bool operator==(const ODIMPathElem & e1, const ODIMPathElem & e2);
442
443inline
444bool operator!=(const ODIMPathElem & e1, const ODIMPathElem & e2){
445 return ! operator==(e1, e2);
446}
447
448
449inline
450std::ostream & operator<<(std::ostream & ostr, const ODIMPathElem & p) {
451 p.toStream(ostr);
452 return ostr;
453}
454
455inline
456std::istream & operator>>(std::istream & istr, ODIMPathElem & p) {
457 std::string s;
458 drain::StringTools::read<512>(istr, s);
459 //istr >> s;
460 p.set(s);
461 return istr;
462}
463
464
465typedef drain::Path<ODIMPathElem,'/',true,false,true> ODIMPath;
466
467typedef std::list<ODIMPath> ODIMPathList;
468
469typedef std::vector<ODIMPathElem> ODIMPathElemSeq;
470
474typedef std::map<std::string,ODIMPathElem> ODIMPathElemMap;
475
478
479 // Main function
480 inline
481 bool operator()(const ODIMPathElem & p1, const ODIMPathElem & p2) const {
482 // return (p1<p2);
483 return !(p1<p2);
484 }
485
486}; // end class
487
488
491
492public:
493
494 inline
495 ODIMPathElem2(): elangle(0.0) {};
496
497 virtual inline
498 ~ODIMPathElem2(){};
499
500 inline
501 ODIMPathElem2(const ODIMPathElem & elem, const double elangle, const std::string & date, const std::string & time):
502 ODIMPathElem(elem), elangle(elangle), timestamp(date+time) {
503 }
504
505 double elangle;
506 std::string timestamp;
507
508
509};
510
511
512inline
513std::ostream & operator<<(std::ostream & ostr, const ODIMPathElem2 & elem) {
514 return ostr << (const ODIMPathElem &)elem << '-' << elem.timestamp << '-' << elem.elangle;
515}
516
517
520 inline
521 bool operator()(const ODIMPathElem2 & e1, const ODIMPathElem2 & e2) const {
522 return e1.timestamp < e2.timestamp;
523 }
524};
525
528 inline
529 bool operator()(const ODIMPathElem2 & e1, const ODIMPathElem2 & e2) const {
530 return e1.elangle < e2.elangle;
531 }
532};
533
534
535/*
536inline
537std::ostream & operator<<(std::ostream & ostr, const ODIMPath & p) {
538 return p.toStream(ostr);
539}
540*/
541
542
543} // namespace rack
544
545
546#endif
547
548// Rack
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:61
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Definition Path.h:135
Definition Flags.h:62
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
DOC: Add class description.
Definition ODIMPath.h:490
DOC: Add class description.
Definition ODIMPath.h:82
const std::string & getKey() const
Debugging/logging. Returns standard name. Does not check if type is OTHER.
Definition ODIMPath.h:366
ODIMPathElem(const std::string &s)
Constructor from string.
Definition ODIMPath.h:213
static const group_t WHAT
Metadata group /what , at any depth.
Definition ODIMPath.h:127
static const group_t IS_INDEXED
Group index mask for groups that have an index.
Definition ODIMPath.h:159
virtual void set(const std::string &s)
Assign a string to this path element.
Definition ODIMPath.h:295
static const group_t LEGEND
Metadata array describing values in the image data (DATA). EXPERIMENTAL.
Definition ODIMPath.h:146
static const group_t DATASET
First level group, /dataset + digit .
Definition ODIMPath.h:106
const std::string & getPrefix() const
Returns the name without the index.
Definition ODIMPath.cpp:198
static const group_t ALL_LEVELS
Abbreviation for linking (referencing) attributes at different levels (tree depths).
Definition ODIMPath.h:121
ODIMPathElem(const ODIMPathElem &e)
Copy constructor.
Definition ODIMPath.h:206
static const group_t PALETTE
Palette data (to be linked). EXPERIMENTAL.
Definition ODIMPath.h:143
bool is(group_t g) const
Abbreviation of (group == NONE)
Definition ODIMPath.h:303
bool empty() const
Equivalent to isRoot(). This method is required in recognizing the leading empty string....
Definition ODIMPath.h:315
virtual std::ostream & toStream(std::ostream &sstr) const
For string presentation.
Definition ODIMPath.cpp:320
bool isRoot() const
Abbreviation of (group == ROOT)
Definition ODIMPath.h:309
bool belongsTo(int groupFilter) const
Checks if the element belongs to any of groups given.
Definition ODIMPath.h:339
ODIMPathElem & operator=(const char *s)
Calls set(const std::string &) .
Definition ODIMPath.h:247
virtual bool extractPrefix(const std::string &s, bool indexed)
Given the non-numeric prefix of a group, like "dataset" or "data", set the group.
Definition ODIMPath.cpp:144
virtual void set(group_t g, index_t i=0)
The fundamental assignment operator.
Definition ODIMPath.h:274
static const group_t ROOT
Definition ODIMPath.h:102
static const group_t OTHER
User defined group, name stored as a separate string. The string may still contain numbers,...
Definition ODIMPath.h:153
static const group_t HOW
Metadata group /how , at any depth.
Definition ODIMPath.h:133
static const group_t ATTRIBUTE_GROUPS
Group index mask for groups that contain only meta data.
Definition ODIMPath.h:136
static const group_t NONE
None (undefined)
Definition ODIMPath.h:98
unsigned int group_t
In H5, "groups" correspond to directories or folders in file system.
Definition ODIMPath.h:92
bool isIndexed() const
Abbreviation of (group == NONE)
Definition ODIMPath.h:330
const std::string & str() const
Writes the name, including the index, to output stream.
Definition ODIMPath.h:378
static const group_t QUALITY
Special group on first or second level, /quality + digit , used for storing quality data.
Definition ODIMPath.h:115
static const group_t DATA_GROUPS
Group index mask for groups under which data arrays (ARRAY type) are found.
Definition ODIMPath.h:118
ODIMPathElem(group_t group=ROOT, index_t index=1)
Default constructor.
Definition ODIMPath.h:190
static const group_t ALL_GROUPS
User defined group, name stored as a separate string. Index allowed, but only catenated in the string...
Definition ODIMPath.h:140
static const group_t DATA
Second level group, /data + digit .
Definition ODIMPath.h:109
static const group_t WHERE
Metadata group /where , at any depth.
Definition ODIMPath.h:130
ODIMPathElem(const char *s)
Constructor from C string.
Definition ODIMPath.h:219
static const group_t ARRAY
Data group "data", at deepest level, like /dataset4/data2/quality1/data.
Definition ODIMPath.h:112
virtual void extractIndex(const std::string &s)
Given a string starting with a numeral, try to extract the index.
Definition ODIMPath.cpp:138
ODIMPathElem & operator=(const T &s)
Redirects to set(const std::string &) .
Definition ODIMPath.h:236
Definition AltitudeOp.cpp:42
bool operator<(const ODIMPathElem &e1, const ODIMPathElem &e2)
Important!
Definition ODIMPath.cpp:259
std::map< std::string, ODIMPathElem > ODIMPathElemMap
Definition ODIMPath.h:474
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631
DOC: Add class description.
Definition ODIMPath.h:527
DOC: Add class description.
Definition ODIMPath.h:519
DOC: Add class description.
Definition ODIMPath.h:477