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 #if defined(__clang__)
27 #pragma clang diagnostic push
28 #pragma clang diagnostic ignored "-Wdeprecated-register"
31 #include <boost/multiprecision/cpp_dec_float.hpp>
33 #if defined(__clang__)
34 #pragma clang diagnostic pop
37 #include <boost/version.hpp>
41 typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<40,boost::int16_t> > sst_dec_float;
50 typedef uint8_t unit_id_t;
56 static std::recursive_mutex unit_lock;
57 static std::map<std::string,unit_id_t> valid_base_units;
58 static std::map<std::string,std::pair<Units,sst_dec_float> > valid_compound_units;
59 static std::map<unit_id_t,std::string> unit_strings;
60 static unit_id_t count;
61 static bool initialized;
63 static bool initialize();
66 std::vector<unit_id_t> numerator;
67 std::vector<unit_id_t> denominator;
71 void addUnit(std::string, sst_dec_float& multiplier,
bool invert);
85 Units(std::string units, sst_dec_float& multiplier);
118 static std::string trim(std::string str);
119 void init(std::string val);
142 void print(std::ostream& stream);
159 template <
typename T>
168 template <
typename T>
196 ser & unit.numerator;
197 ser & unit.denominator;
202 case SST::Core::Serialization::serializer::SIZER:
203 case SST::Core::Serialization::serializer::PACK: {
204 std::string s = value.str(40, std::ios_base::fixed);
208 case SST::Core::Serialization::serializer::UNPACK: {
211 value = sst_dec_float(s);
235 template <
typename T>
236 UnitAlgebra operator* (UnitAlgebra lhs,
const T& rhs)
242 template <
typename T>
243 UnitAlgebra operator* (
const T& lhs, UnitAlgebra rhs)
249 inline UnitAlgebra operator* (UnitAlgebra& lhs,
const UnitAlgebra rhs)
255 template <
typename T>
256 UnitAlgebra operator/ (UnitAlgebra lhs,
const T& rhs)
262 inline std::ostream& operator<< (std::ostream& os,
const UnitAlgebra& r)
268 inline std::ostream& operator<< (std::ostream& os,
const Units& r)
277 #endif //SST_CORE_UNITALGEBRA_H
bool operator>(const UnitAlgebra &v) const
Compare if this object is greater than the argument.
Definition: unitAlgebra.cc:452
Units & operator*=(const Units &v)
Self-multiplication operator.
Definition: unitAlgebra.cc:257
UnitAlgebra & operator/=(const UnitAlgebra &v)
Divide by an argument;.
Definition: unitAlgebra.cc:444
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:386
sst_dec_float getValue() const
Return the raw value.
Definition: unitAlgebra.h:190
bool operator>=(const UnitAlgebra &v) const
Compare if this object is greater than, or equal to, the argument.
Definition: unitAlgebra.cc:464
std::string toString() const
Return a string representation of this value.
Definition: unitAlgebra.cc:397
bool hasUnits(std::string u) const
Returns true if the units in the parameter string are found in this object.
Definition: unitAlgebra.cc:509
static void registerBaseUnit(std::string u)
Create a new Base Unit type.
Definition: unitAlgebra.cc:196
int64_t getRoundedValue() const
Return the rounded value as a 64bit integer.
Definition: unitAlgebra.cc:521
static void registerCompoundUnit(std::string u, std::string v)
Create a new Compount Unit type.
Definition: unitAlgebra.cc:207
Units & operator=(const Units &v)
Assignment operator.
Definition: unitAlgebra.cc:250
std::string toStringBestSI() const
Return a string representation of this value Formats the number using SI-prefixes.
Definition: unitAlgebra.cc:406
bool operator==(const Units &lhs) const
Equality Operator.
Definition: unitAlgebra.cc:276
Definition: serializable.h:108
Units & invert()
Perform a reciprocal operation.
Definition: unitAlgebra.cc:290
void printWithBestSI(std::ostream &stream)
Print to an ostream the value Formats the number using SI-prefixes.
Definition: unitAlgebra.cc:391
UnitAlgebra & invert()
Apply a reciprocal operation to the object.
Definition: unitAlgebra.cc:501
std::string toString() const
Return a String representation if this Unit.
Definition: unitAlgebra.cc:299
UnitAlgebra & operator*=(const UnitAlgebra &v)
Multiply by an argument;.
Definition: unitAlgebra.cc:436
bool operator<=(const UnitAlgebra &v) const
Compare if this object is less than, or equal to, the argument.
Definition: unitAlgebra.cc:488
bool operator!=(const Units &lhs) const
Inequality Operator.
Definition: unitAlgebra.h:98
Performs Unit math in full precision.
Definition: unitAlgebra.h:112
Units & operator/=(const Units &v)
Self-division operator.
Definition: unitAlgebra.cc:267
Helper class internal to UnitAlgebra.
Definition: unitAlgebra.h:48
bool operator<(const UnitAlgebra &v) const
Compare if this object is less than the argument.
Definition: unitAlgebra.cc:476
Definition: serializable.h:128