Loading...
Searching...
No Matches
Quantity.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_QUANTITY
32#define ODIM_QUANTITY
33
34#include <data/QuantitySelector.h>
35#include <ostream>
36
37#include <drain/util/ReferenceMap.h>
38#include <drain/util/Range.h>
39
40#include "EncodingODIM.h"
41
42
43namespace rack {
44
45
46
48
51class Quantity : public std::map<char,EncodingODIM> {
52
53public:
54
56 typedef std::map<char,EncodingODIM> map_t;
57
59 typedef std::list<EncodingODIM> list_t;
60
62 // typedef std::map<std::string,std::string> desc_map_t;
63
64 std::string name;
65
67 //drain::StringMatcherList<drain::StringMatcher> keySelector; // could be keyMatcher?
68 //drain::StringMatcherList<FM301KeyMatcher>
69 QuantitySelector keySelector; // could be keyMatcher?
70
72 char defaultType = '\0';
73
74 drain::Range<double> physicalRange;
75
77 /*
78 * A physical value that represents all the measurement results that fall below a detection limit.
79 */
80 double undetectValue = std::numeric_limits<double>::signaling_NaN();
81
82
84 /*
85 Quantity(const std::string & name = "",
86 const drain::Range<double> & range = {},
87 char defaultType='\0',
88 const list_t & l = {}, // brace initializer
89 double undetectValue = std::numeric_limits<double>::signaling_NaN());
90 */
91
93 /*
94 Quantity(const std::string & name,
95 const std::list<std::string> & compatibleVariants,
96 const drain::Range<double> & range, */
97 Quantity(const std::string & name = "",
98 //const std::list<std::string> & compatibleVariants = {},
100 const drain::Range<double> & range = {},
101 char defaultType='\0',
102 const list_t & l = {}, // brace initializer
103 double undetectValue = std::numeric_limits<double>::signaling_NaN());
104
106
109 Quantity(const std::string & name,
110 // const std::list<std::string> & compatibleVariants,
111 const QuantitySelector & compatibleVariants,
112 char defaultType,
113 const list_t & l = {}, // brace initializer
114 double undetectValue = std::numeric_limits<double>::signaling_NaN());
115
116
117 /*
118 inline
119 Quantity(): defaultType('\0'), undetectValue(std::numeric_limits<double>::signaling_NaN()) {
120 }
121 */
122
124 inline
125 Quantity(const Quantity & quantity):
126 map_t(quantity),
127 name(quantity.name),
128 keySelector(quantity.keySelector),
129 defaultType(quantity.defaultType),
130 physicalRange(quantity.physicalRange),
131 undetectValue(quantity.undetectValue) {
132 }
133
134 Quantity & operator=(const Quantity &) = default;
135
136 /*
137 inline
138 Quantity & operator=(const Quantity & quantity){
139 map_t::operator=(quantity);
140 variants.setKeys(quantity);
141 name = quantity.name;
142 defaultType = quantity.defaultType;
143 physicalRange = quantity.physicalRange;
144 undetectValue = quantity.undetectValue;
145 return *this;
146 }
147 */
148
150 /*
151 *
152 * Set defaultType, if unset.
153 */
154 EncodingODIM & set(char typecode);
155
156 void addEncodings(const list_t & l);
157
158
160 const EncodingODIM & get(char typecode = '\0') const;
161
163 const EncodingODIM & get(const std::string & t) const;
164
165 inline
166 bool isApplicable(const std::string & key){ // needed?
167 return keySelector.test(key, false);
168 }
169
171 inline
172 bool hasUndetectValue() const {
173 return !std::isnan(undetectValue);
174 }
175
177
182 inline
183 void setZero(double value){
184 undetectValue = value;
185 }
186
188
191 void setZero(const std::string & value);
192
194 inline
195 void unsetZero(){
196 undetectValue = std::numeric_limits<double>::signaling_NaN();
197 }
198
200
204 inline
205 void setPhysicalRange(double min, double max = std::numeric_limits<double>::max() ){
206 // hasUndetectValue = true;
207 // undetectValue = min;
208 setZero(min);
209 physicalRange.set(min, max);
210 }
211
213 std::ostream & toStream(std::ostream & ostr) const;
214
215
216};
217
218inline
219std::ostream & operator<<(std::ostream & ostr, const Quantity & q){
220 return q.toStream(ostr);
221}
222
223
224
225} // namespace rack
226
227
228#endif
229
230// Rack
Definition Range.h:52
bool test(const std::string &key, bool defaultResult=true) const
Check if key is accepted.
Definition StringMatcherList.h:248
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
Structure for data storage type, scaling and marker codes. Does not contain quantity.
Definition EncodingODIM.h:70
Structure for defining quantity.
Definition Quantity.h:51
void setZero(double value)
Set a value to be used like a real measurement, for example in interpolation.
Definition Quantity.h:183
void setPhysicalRange(double min, double max=std::numeric_limits< double >::max())
Sets absolute or typical range of this quantity.
Definition Quantity.h:205
Quantity(const Quantity &quantity)
Copy constructor.
Definition Quantity.h:125
std::list< EncodingODIM > list_t
List type applicable in constructors.
Definition Quantity.h:59
const EncodingODIM & get(char typecode='\0') const
Retrieve the scaling for a given storage type.
Definition Quantity.cpp:168
double undetectValue
A physical value corresponding a very small (unmeasurable) value has been defined.
Definition Quantity.h:80
std::string name
Container supporting constructors.
Definition Quantity.h:64
std::map< char, EncodingODIM > map_t
Container for default encodings.
Definition Quantity.h:56
QuantitySelector keySelector
Collection of quantities that can be similarly scaled and encoded.
Definition Quantity.h:69
bool hasUndetectValue() const
True, if a value corresponding a very small (unmeasurable) value has been defined.
Definition Quantity.h:172
std::ostream & toStream(std::ostream &ostr) const
Print declared encodings (storage types and scalings)
Definition Quantity.cpp:200
Quantity(const std::string &name="", const QuantitySelector &compatibleVariants={}, const drain::Range< double > &range={}, char defaultType='\0', const list_t &l={}, double undetectValue=std::numeric_limits< double >::signaling_NaN())
Default constructor.
Definition Quantity.cpp:56
void unsetZero()
Confirm that no value should be used as a substitute of undetected value.
Definition Quantity.h:195
char defaultType
Default storage type.
Definition Quantity.h:72
EncodingODIM & set(char typecode)
Declare encoding (a storage type and scaling) for this quantity.
Definition Quantity.cpp:151
Definition AltitudeOp.cpp:42
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631