Loading...
Searching...
No Matches
ODIMPathMatcher.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_MATCHER
32#define ODIM_PATH_MATCHER
33
34
35//#include <drain/Dictionary.h>
36#include <drain/util/Flags.h>
37#include <drain/util/Range.h>
38
39#include "ODIMPath.h"
40
41
42namespace rack {
43
45/*
46 * Index range [index,indexMax] is applied in testing path elements of a same group.
47 * \see ODIMPathMatcher
48 */
50
51public:
52
54 inline
55 ODIMPathElemMatcher(ODIMPathElem::group_t groups = ROOT, index_t index = 0, index_t indexMax = INDEX_MAX) :
56 // ODIMPathElem(group, index),
57 // index(index),
58 // indexMax(indexMax),
59 flags(ODIMPathElem::getDictionary(), this->group, '|'){
60 this->group = groups;
61 this->index = index;
62 this->indexMax = indexMax;
63 };
64
65
67 inline
70 // index(e.index),
71 // indexMax(e.indexMax),
72 flags(ODIMPathElem::getDictionary(), this->group, '|') {
73 this->group = e.group; // needed?
74 this->index = e.index;
75 this->indexMax = e.indexMax;
76 }
77
79 inline
81 // ODIMPathElem(e),
82 // index(e.index),
83 // indexMax(0xffff),
84 flags(ODIMPathElem::getDictionary(), this->group, '|') {
85 this->group = e.group; // needed?
86 this->index = e.index;
87 this->indexMax = INDEX_MAX; // ??
88 }
89
91 inline
92 ODIMPathElemMatcher(const std::string &s) :
93 // index(0),
94 // indexMax(0xffff),
95 flags(ODIMPathElem::getDictionary(), this->group, '|') {
96
97 // TODO: virtual reset(){}
98 group = 0;
99 index = 0;
100 this->indexMax = INDEX_MAX;
101 set(s);
102 }
103
104 virtual
106
107 // ambiguous! index 5 could mean range 5:5 or 0:0xffff ?
108
109
110 virtual
111 //bool
112 void set(const std::string &s);
113
114
115 inline
116 bool isSingle() const {
117 return (!isIndexed()) || (index == indexMax);
118 }
119
120 inline
122 index = 0;
123 indexMax = INDEX_MAX;
124 group = g;
125 return *this;
126 }
127
128 inline
129 ODIMPathElemMatcher & operator=(const std::string &s){
130 index = 0;
131 indexMax = INDEX_MAX;
132 set(s);
133 return *this;
134 }
135
136
138 bool test(const ODIMPathElem & elem) const;
139
140 // Applied only as a upper limit in path matching.
141 index_t indexMax;
142
143 //drain::Flagger flags;
144 //drain::Flagger2<drain::MultiFlagger<group_t> > flags;
146 //drain::MultiFlagger<group_t> flags;
147
148 virtual
149 std::ostream & toStream(std::ostream & sstr) const;
150
151 // FUTURE extension:
152 typedef drain::Range<index_t> idx_range_t;
153
154
155protected:
156
158 virtual
159 void extractIndex(const std::string &s);
160
161
162 virtual
163 bool extractPrefix(const std::string &s, bool indexed);
164
165
166};
167
168
169// Note: Elem, not MatcherElem
170template <>
171void ODIMPathElem::extractIndex(const std::string &s, ODIMPathElemMatcher::idx_range_t & idx);
172
173inline
174std::ostream & operator<<(std::ostream & ostr, const ODIMPathElemMatcher & p) {
175 p.toStream(ostr);
176 return ostr;
177}
178
179//template <>
180//char drain::TextReader::scanSegmentToValue(std::istream & istr, const std::string & endChars, ODIMPathElemMatcher::idx_range_t & dst);
181
182
183
185
190class ODIMPathMatcher : public drain::Path<ODIMPathElemMatcher> {
191
192public:
193
196 separator.acceptTrailing = true;
197 }
198
202
203 template<typename ... T>
204 ODIMPathMatcher(const ODIMPathElem & elem, const T &... rest){
205 separator.acceptTrailing = true;
206 setElems(elem, rest...);
207 //updateBean(); ?
208 }
209
211 ODIMPathMatcher(const std::string & path){
212 separator.acceptTrailing = true;
213 set(path);
214 //assign(path);
215 }
216
218 ODIMPathMatcher(const char * path){
219 separator.acceptTrailing = true;
220 set(path);
221 // assign(path);
222 }
223
224
226 // void parse(const std::string & path);
227
229 bool ensureLimitingSlash();
230
231
233 bool isLiteral() const;
234
236 void extractPath(ODIMPath & path) const;
237
239 bool match(const rack::ODIMPath & path) const;
240
242 bool matchHead(const rack::ODIMPath & path) const;
243
245 bool matchTail(const rack::ODIMPath & path) const;
246
248 bool matchElem(const rack::ODIMPathElem & elem, bool defaultValue = true) const;
249
250};
251
252
253
254} // namespace rack
255
256
257#endif
Definition Flags.h:217
Definition Path.h:135
Definition Range.h:52
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
Element in a chain in testing a path for a match.
Definition ODIMPathMatcher.h:49
virtual void set(const std::string &s)
Assign a string to this path element.
Definition ODIMPathMatcher.cpp:46
ODIMPathElemMatcher(const ODIMPathElem &e)
Constructor from ODIMPathElem.
Definition ODIMPathMatcher.h:80
ODIMPathElemMatcher(const ODIMPathElemMatcher &e)
Copy constructor.
Definition ODIMPathMatcher.h:68
virtual std::ostream & toStream(std::ostream &sstr) const
For string presentation.
Definition ODIMPathMatcher.cpp:344
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 ODIMPathMatcher.cpp:139
ODIMPathElemMatcher(ODIMPathElem::group_t groups=ROOT, index_t index=0, index_t indexMax=INDEX_MAX)
Default constructor.
Definition ODIMPathMatcher.h:55
ODIMPathElemMatcher(const std::string &s)
Constructor from string.
Definition ODIMPathMatcher.h:92
bool test(const ODIMPathElem &elem) const
Test if the elem has the same group, and elem.index is within [index,indexMax].
Definition ODIMPathMatcher.cpp:192
virtual void extractIndex(const std::string &s)
Extracts index range of type index[:indexMax].
Definition ODIMPathMatcher.cpp:91
DOC: Add class description.
Definition ODIMPath.h:82
static const group_t ROOT
Definition ODIMPath.h:102
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
virtual void extractIndex(const std::string &s)
Given a string starting with a numeral, try to extract the index.
Definition ODIMPath.cpp:138
Structure for testing if a path matches a given sequence of path elements.
Definition ODIMPathMatcher.h:190
bool isLiteral() const
Checks if corresponds to a single path, implying that all the index ranges are singletons.
Definition ODIMPathMatcher.cpp:231
ODIMPathMatcher(const std::string &path)
Almost copy constructor.
Definition ODIMPathMatcher.h:211
bool matchHead(const rack::ODIMPath &path) const
Match leading part of path.
Definition ODIMPathMatcher.cpp:269
bool ensureLimitingSlash()
Resolves "where|where".
Definition ODIMPathMatcher.cpp:66
bool matchTail(const rack::ODIMPath &path) const
Match trailing part of path.
Definition ODIMPathMatcher.cpp:297
ODIMPathMatcher(const char *path)
Almost copy constructor.
Definition ODIMPathMatcher.h:218
bool matchElem(const rack::ODIMPathElem &elem, bool defaultValue=true) const
Match single element. If matcher path does not contain it, return defaultValue.
Definition ODIMPathMatcher.cpp:324
ODIMPathMatcher()
Basic constructor.
Definition ODIMPathMatcher.h:195
ODIMPathMatcher(const ODIMPathMatcher &matcher)
Copy constructor.
Definition ODIMPathMatcher.h:200
void extractPath(ODIMPath &path) const
Convert to a single path, assuming uniqueness. Future option: extract all the enumerated paths.
Definition ODIMPathMatcher.cpp:242
bool match(const rack::ODIMPath &path) const
Match the leading part of path , if matcher starts with root. Else, match the trailing part.
Definition ODIMPathMatcher.cpp:255
Definition Data.h:1473
Definition AltitudeOp.cpp:42
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631
bool & acceptTrailing
If true, allow trailing empty elements (appearing as repeated separators)
Definition Path.h:78