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#include <stdexcept>
37
38#include <drain/Log.h>
39#include <drain/Type.h>
40#include <drain/util/ReferenceMap.h>
41#include <drain/util/StringMatcherList.h>
42#include <drain/util/Range.h>
43
44#include "EncodingODIM.h"
45
46
47namespace rack {
48
49
50
52
55class Quantity : public std::map<char,EncodingODIM> {
56
57public:
58
60 typedef std::map<char,EncodingODIM> map_t;
61
63 typedef std::list<EncodingODIM> list_t;
64
66 // typedef std::map<std::string,std::string> desc_map_t;
67
68 std::string name;
69
71 //drain::StringMatcherList<drain::StringMatcher> keySelector; // could be keyMatcher?
72 //drain::StringMatcherList<FM301KeyMatcher>
73 QuantitySelector keySelector; // could be keyMatcher?
74
76 char defaultType = '\0';
77
78 drain::Range<double> physicalRange;
79
81 /*
82 * A physical value that represents all the measurement results that fall below a detection limit.
83 */
84 double undetectValue = std::numeric_limits<double>::signaling_NaN();
85
86
88 /*
89 Quantity(const std::string & name = "",
90 const drain::Range<double> & range = {},
91 char defaultType='\0',
92 const list_t & l = {}, // brace initializer
93 double undetectValue = std::numeric_limits<double>::signaling_NaN());
94 */
95
97 /*
98 Quantity(const std::string & name,
99 const std::list<std::string> & compatibleVariants,
100 const drain::Range<double> & range, */
101 Quantity(const std::string & name = "",
102 //const std::list<std::string> & compatibleVariants = {},
103 const QuantitySelector & compatibleVariants = {},
104 const drain::Range<double> & range = {},
105 char defaultType='\0',
106 const list_t & l = {}, // brace initializer
107 double undetectValue = std::numeric_limits<double>::signaling_NaN());
108
110
113 Quantity(const std::string & name,
114 // const std::list<std::string> & compatibleVariants,
115 const QuantitySelector & compatibleVariants,
116 char defaultType,
117 const list_t & l = {}, // brace initializer
118 double undetectValue = std::numeric_limits<double>::signaling_NaN());
119
120
121 /*
122 inline
123 Quantity(): defaultType('\0'), undetectValue(std::numeric_limits<double>::signaling_NaN()) {
124 }
125 */
126
128 inline
129 Quantity(const Quantity & quantity):
130 map_t(quantity),
131 name(quantity.name),
132 keySelector(quantity.keySelector),
133 defaultType(quantity.defaultType),
134 physicalRange(quantity.physicalRange),
135 undetectValue(quantity.undetectValue) {
136 }
137
138 /*
139 inline
140 Quantity & operator=(const Quantity & quantity){
141 map_t::operator=(quantity);
142 variants.setKeys(quantity);
143 name = quantity.name;
144 defaultType = quantity.defaultType;
145 physicalRange = quantity.physicalRange;
146 undetectValue = quantity.undetectValue;
147 return *this;
148 }
149 */
150
152 /*
153 *
154 * Set defaultType, if unset.
155 */
156 EncodingODIM & set(char typecode);
157
158 void addEncodings(const list_t & l);
159
160
162 const EncodingODIM & get(char typecode = '\0') const;
163
165 const EncodingODIM & get(const std::string & t) const;
166
167 inline
168 bool isApplicable(const std::string & key){ // needed?
169 return keySelector.test(key, false);
170 }
171
173 inline
174 bool hasUndetectValue() const {
175 return !std::isnan(undetectValue);
176 }
177
179
184 inline
185 void setZero(double value){
186 undetectValue = value;
187 }
188
190
193 void setZero(const std::string & value);
194
196 inline
197 void unsetZero(){
198 undetectValue = std::numeric_limits<double>::signaling_NaN();
199 }
200
202
206 inline
207 void setPhysicalRange(double min, double max = std::numeric_limits<double>::max() ){
208 // hasUndetectValue = true;
209 // undetectValue = min;
210 setZero(min);
211 physicalRange.set(min, max);
212 }
213
215 std::ostream & toStream(std::ostream & ostr) const;
216
217
218};
219
220inline
221std::ostream & operator<<(std::ostream & ostr, const Quantity & q){
222 return q.toStream(ostr);
223}
224
225
226
227} // namespace rack
228
229
230#endif
231
232// Rack
Definition Range.h:52
bool test(const std::string &key, bool defaultResult=true) const
Check if key is accepted.
Definition StringMatcherList.h:273
Structure for data storage type, scaling and marker codes. Does not contain quantity.
Definition EncodingODIM.h:75
Structure for defining quantity.
Definition Quantity.h:55
void setZero(double value)
Set a value to be used like a real measurement, for example in interpolation.
Definition Quantity.h:185
void setPhysicalRange(double min, double max=std::numeric_limits< double >::max())
Sets absolute or typical range of this quantity.
Definition Quantity.h:207
Quantity(const Quantity &quantity)
Copy constructor.
Definition Quantity.h:129
std::list< EncodingODIM > list_t
List type applicable in constructors.
Definition Quantity.h:63
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:84
std::string name
Container supporting constructors.
Definition Quantity.h:68
std::map< char, EncodingODIM > map_t
Container for default encodings.
Definition Quantity.h:60
QuantitySelector keySelector
Collection of quantities that can be similarly scaled and encoded.
Definition Quantity.h:73
bool hasUndetectValue() const
True, if a value corresponding a very small (unmeasurable) value has been defined.
Definition Quantity.h:174
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:197
char defaultType
Default storage type.
Definition Quantity.h:76
EncodingODIM & set(char typecode)
Declare encoding (a storage type and scaling) for this quantity.
Definition Quantity.cpp:151
Definition DataSelector.cpp:44