14 #ifndef SST_CORE_UNITALGEBRA_H
15 #define SST_CORE_UNITALGEBRA_H
17 #include "sst/core/sst_types.h"
18 #include "sst/core/serialization/serializable.h"
19 #include "sst/core/serialization/serializer.h"
26 #include "sst/core/warnmacros.h"
27 #include "sst/core/decimal_fixedpoint.h"
33 typedef decimal_fixedpoint<3,3> sst_big_num;
42 typedef uint8_t unit_id_t;
48 static std::recursive_mutex unit_lock;
49 static std::map<std::string,unit_id_t> valid_base_units;
50 static std::map<std::string,std::pair<Units,sst_big_num> > valid_compound_units;
51 static std::map<unit_id_t,std::string> unit_strings;
52 static unit_id_t count;
53 static bool initialized;
55 static bool initialize();
58 std::vector<unit_id_t> numerator;
59 std::vector<unit_id_t> denominator;
113 static std::string trim(
const std::string& str);
116 void init(
const std::string& val);
141 void print(std::ostream& stream);
158 template <
typename T>
167 template <
typename T>
176 template <
typename T>
185 template <
typename T>
209 bool hasUnits(
const std::string& u)
const;
214 double getDoubleValue()
const;
215 bool isValueZero()
const;
219 ser & unit.numerator;
220 ser & unit.denominator;
225 case SST::Core::Serialization::serializer::SIZER:
226 case SST::Core::Serialization::serializer::PACK: {
232 case SST::Core::Serialization::serializer::UNPACK: {
235 value = sst_big_num(s);
259 template <
typename T>
260 UnitAlgebra operator* (UnitAlgebra lhs,
const T& rhs)
273 inline UnitAlgebra operator* (UnitAlgebra lhs,
const UnitAlgebra& rhs)
279 template <
typename T>
280 UnitAlgebra operator/ (UnitAlgebra lhs,
const T& rhs)
286 inline UnitAlgebra operator/ (UnitAlgebra lhs,
const UnitAlgebra& rhs)
292 template <
typename T>
293 UnitAlgebra operator+ (UnitAlgebra lhs,
const T& rhs)
299 inline UnitAlgebra operator+ (UnitAlgebra lhs,
const UnitAlgebra& rhs)
305 template <
typename T>
306 UnitAlgebra operator- (UnitAlgebra lhs,
const T& rhs)
312 inline UnitAlgebra operator- (UnitAlgebra lhs,
const UnitAlgebra& rhs)
319 inline std::ostream& operator<< (std::ostream& os,
const UnitAlgebra& r)
325 inline std::ostream& operator<< (std::ostream& os,
const Units& r)
334 #endif //SST_CORE_UNITALGEBRA_H
bool operator>(const UnitAlgebra &v) const
Compare if this object is greater than the argument.
Definition: unitAlgebra.cc:475
Units & operator*=(const Units &v)
Self-multiplication operator.
Definition: unitAlgebra.cc:254
UnitAlgebra & operator/=(const UnitAlgebra &v)
Divide by an argument;.
Definition: unitAlgebra.cc:441
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
void print(std::ostream &stream)
Print to an ostream the value.
Definition: unitAlgebra.cc:383
std::string toString(int32_t precision=6) const
Create a string representation of this decimal_fixedpoint.
Definition: decimal_fixedpoint.h:437
bool operator==(const UnitAlgebra &v) const
Compare if this object is equal to, the argument.
Definition: unitAlgebra.cc:523
bool operator>=(const UnitAlgebra &v) const
Compare if this object is greater than, or equal to, the argument.
Definition: unitAlgebra.cc:487
std::string toString() const
Return a string representation of this value.
Definition: unitAlgebra.cc:394
int64_t getRoundedValue() const
Return the rounded value as a 64bit integer.
Definition: unitAlgebra.cc:559
Units & operator=(const Units &v)
Assignment operator.
Definition: unitAlgebra.cc:247
static void registerBaseUnit(const std::string &u)
Create a new Base Unit type.
Definition: unitAlgebra.cc:193
std::string toStringBestSI() const
Return a string representation of this value Formats the number using SI-prefixes.
Definition: unitAlgebra.cc:403
bool operator==(const Units &lhs) const
Equality Operator.
Definition: unitAlgebra.cc:273
Definition: serializable.h:109
Units & invert()
Perform a reciprocal operation.
Definition: unitAlgebra.cc:287
sst_big_num getValue() const
Return the raw value.
Definition: unitAlgebra.h:211
void printWithBestSI(std::ostream &stream)
Print to an ostream the value Formats the number using SI-prefixes.
Definition: unitAlgebra.cc:388
bool operator!=(const UnitAlgebra &v) const
Compare if this object is not equal to, the argument.
Definition: unitAlgebra.cc:530
UnitAlgebra & invert()
Apply a reciprocal operation to the object.
Definition: unitAlgebra.cc:538
std::string toString() const
Return a String representation if this Unit.
Definition: unitAlgebra.cc:296
UnitAlgebra & operator*=(const UnitAlgebra &v)
Multiply by an argument;.
Definition: unitAlgebra.cc:433
UnitAlgebra & operator+=(const UnitAlgebra &v)
Add an argument;.
Definition: unitAlgebra.cc:449
static void registerCompoundUnit(const std::string &u, const std::string &v)
Create a new Compound Unit type.
Definition: unitAlgebra.cc:204
UnitAlgebra & operator-=(const UnitAlgebra &v)
Subtract an argument;.
Definition: unitAlgebra.cc:462
bool hasUnits(const std::string &u) const
Returns true if the units in the parameter string are found in this object.
Definition: unitAlgebra.cc:547
bool operator<=(const UnitAlgebra &v) const
Compare if this object is less than, or equal to, the argument.
Definition: unitAlgebra.cc:511
bool operator!=(const Units &lhs) const
Inequality Operator.
Definition: unitAlgebra.h:93
Performs Unit math in full precision.
Definition: unitAlgebra.h:107
Units & operator/=(const Units &v)
Self-division operator.
Definition: unitAlgebra.cc:264
Helper class internal to UnitAlgebra.
Definition: unitAlgebra.h:40
bool operator<(const UnitAlgebra &v) const
Compare if this object is less than the argument.
Definition: unitAlgebra.cc:499
Definition: serializable.h:132