Loading...
Searching...
No Matches
StringMatcher.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
32#ifndef DRAIN_KEY_MATCHER
33#define DRAIN_KEY_MATCHER
34
35
36#include <drain/RegExp.h>
37#include <drain/TypeName.h>
38
39
40namespace drain {
41
43
54class StringMatcher : protected drain::RegExp {
55
56public:
57
58 static
59 const std::string regExpSpecialChars;
60
62 const std::string & value;
63
64 inline
65 StringMatcher(const std::string & s = "") : value(regExpString), isRegExp(false){
66 set(s);
67 }
68
69 inline
70 StringMatcher(const char *s) : value(regExpString), isRegExp(false){
71 set(s);
72 }
73
74 inline
75 StringMatcher(const StringMatcher & matcher) : value(regExpString), isRegExp(false){
76 set(matcher.value);
77 }
78
79 inline
80 bool empty() const {
81 return RegExp::empty();
82 };
83
85
88 void set(const std::string & s);
89
90 inline
91 StringMatcher & operator=(const std::string &s){
92 set(s);
93 return *this;
94 }
95
96 inline
97 StringMatcher & operator=(const StringMatcher &s){
98 set(s.value);
99 return *this;
100 }
101
102
103
104 inline
105 bool operator==(const std::string &s) const {
106 return test(s);
107 }
108
109 inline
110 bool operator==(const char *s) const {
111 return test(s);
112 }
113
114 inline
115 bool operator==(const StringMatcher &m) const {
116 return (this->value == m.value) && (this->isRegExp == m.isRegExp);
117 }
118
120
123 bool test(const std::string & s) const;
124
125 const std::string & getType() const;
126
128
135protected:
136
138
139
140};
141
142
143inline
144std::ostream & operator<<(std::ostream & ostr, const StringMatcher & m){
145 ostr << m.value; // string or regExp string.
146 return ostr;
147}
148
149DRAIN_TYPENAME(StringMatcher);
150
151} // drain::
152
153#endif
Definition RegExp.h:58
bool empty() const
Returns true, if expression is empty.
Definition RegExp.h:99
General-purpose key matcher: tests string equality, or regExp, if defined as such.
Definition StringMatcher.h:54
void set(const std::string &s)
Assign a string – which may be a literal or a regular expression.
Definition StringMatcher.cpp:46
bool isRegExp
Checks if the key conforms to ODIM convention: DBZH, VRAD, etc. (capital letters, underscores)
Definition StringMatcher.h:137
const std::string & value
A visible reference to the current string / regExp.
Definition StringMatcher.h:62
bool test(const std::string &s) const
Test with direct string matching or regExp, if defined.
Definition StringMatcher.cpp:70
Definition DataSelector.cpp:1277