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;
63 void addUnit(std::string, sst_big_num& multiplier,
bool invert);
77 Units(std::string units, sst_big_num& multiplier);
110 static std::string trim(std::string str);
111 void init(std::string val);
134 void print(std::ostream& stream);
138 void printWithBestSI(std::ostream& stream);
144 std::string toStringBestSI()
const;
151 template <
typename T>
160 template <
typename T>
180 bool hasUnits(std::string u)
const;
184 int64_t getRoundedValue()
const;
188 ser & unit.numerator;
189 ser & unit.denominator;
194 case SST::Core::Serialization::serializer::SIZER:
195 case SST::Core::Serialization::serializer::PACK: {
201 case SST::Core::Serialization::serializer::UNPACK: {
204 value = sst_big_num(s);
228 template <
typename T>
235 template <
typename T>
248 template <
typename T>
255 inline std::ostream& operator<< (std::ostream& os,
const UnitAlgebra& r)
261 inline std::ostream& operator<< (std::ostream& os,
const Units& r)
270 #endif //SST_CORE_UNITALGEBRA_H Units & operator*=(const Units &v)
Self-multiplication operator.
Definition: unitAlgebra.cc:257
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
std::string toString(int32_t precision=6) const
Create a string representation of this decimal_fixedpoint.
Definition: decimal_fixedpoint.h:426
std::string toString() const
Return a string representation of this value.
Definition: unitAlgebra.cc:397
static void registerBaseUnit(std::string u)
Create a new Base Unit type.
Definition: unitAlgebra.cc:196
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
sst_big_num getValue() const
Return the raw value.
Definition: unitAlgebra.h:182
Definition: serializable.h:109
Units & invert()
Perform a reciprocal operation.
Definition: unitAlgebra.cc:290
bool operator!=(const Units &lhs) const
Inequality Operator.
Definition: unitAlgebra.h:90
bool operator==(const Units &lhs) const
Equality Operator.
Definition: unitAlgebra.cc:276
std::string toString() const
Return a String representation if this Unit.
Definition: unitAlgebra.cc:299
Performs Unit math in full precision.
Definition: unitAlgebra.h:104
Units & operator/=(const Units &v)
Self-division operator.
Definition: unitAlgebra.cc:267
Helper class internal to UnitAlgebra.
Definition: unitAlgebra.h:40
Definition: serializable.h:130