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 = {},
99 const QuantitySelector & 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 /*
135 inline
136 Quantity & operator=(const Quantity & quantity){
137 map_t::operator=(quantity);
138 variants.setKeys(quantity);
139 name = quantity.name;
140 defaultType = quantity.defaultType;
141 physicalRange = quantity.physicalRange;
142 undetectValue = quantity.undetectValue;
143 return *this;
144 }
145 */
146
148 /*
149 *
150 * Set defaultType, if unset.
151 */
152 EncodingODIM & set(char typecode);
153
154 void addEncodings(const list_t & l);
155
156
158 const EncodingODIM & get(char typecode = '\0') const;
159
161 const EncodingODIM & get(const std::string & t) const;
162
163 inline
164 bool isApplicable(const std::string & key){ // needed?
165 return keySelector.test(key, false);
166 }
167
169 inline
170 bool hasUndetectValue() const {
171 return !std::isnan(undetectValue);
172 }
173
175
180 inline
181 void setZero(double value){
182 undetectValue = value;
183 }
184
186
189 void setZero(const std::string & value);
190
192 inline
193 void unsetZero(){
194 undetectValue = std::numeric_limits<double>::signaling_NaN();
195 }
196
198
202 inline
203 void setPhysicalRange(double min, double max = std::numeric_limits<double>::max() ){
204 // hasUndetectValue = true;
205 // undetectValue = min;
206 setZero(min);
207 physicalRange.set(min, max);
208 }
209
211 std::ostream & toStream(std::ostream & ostr) const;
212
213
214};
215
216inline
217std::ostream & operator<<(std::ostream & ostr, const Quantity & q){
218 return q.toStream(ostr);
219}
220
221
222
223} // namespace rack
224
225
226#endif
227
228// Rack
Definition Range.h:52
bool test(const std::string &key, bool defaultResult=true) const
Check if key is accepted.
Definition StringMatcherList.h:249
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:181
void setPhysicalRange(double min, double max=std::numeric_limits< double >::max())
Sets absolute or typical range of this quantity.
Definition Quantity.h:203
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:170
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:193
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 DataSelector.cpp:44