HOPS
HOPS class reference
MHO_Unit.hh
Go to the documentation of this file.
1 #include <array>
2 #include <string>
3 
4 namespace hops
5 {
6 
15 class MHO_Unit
16 {
17  public:
18  MHO_Unit(): fStringRep("");
19  MHO_Unit(const std::string& unit);
20  virtual ~MHO_Unit();
21 
22  //setter and getter for string representation
23  void SetUnitString(const std::string unit) { Parse(unit); };
24 
25  std::string GetUnitString() const { return ConstructString(); }
26 
27  // operator overloads for multiplication and division
28  MHO_Unit operator*(const MHO_Unit& other) const;
29  MHO_Unit operator/(const MHO_Unit& other) const;
30 
31  // operator overloads for compound assignment
32  MHO_Unit& operator*=(const MHO_Unit& other);
33  MHO_Unit& operator/=(const MHO_Unit& other);
34 
35  //raise the unit to an integer power
36  void RaiseToPower(int power);
37 
38  //invert the unit:
39  void Invert();
40 
41  // equality operator
42  bool operator==(const MHO_Unit& other) const;
43 
44  //assignment operator
45  MHO_Unit& operator=(const MHO_Unit& other);
46 
47  private:
48  std::string fStringRep;
49 
50  //the base SI units specified are:
51  //[ length, time, mass, ampere, temperature, luminosity, quantity (mole) ]
52 
53  //but we don't deal with mole's very much so I think we would would probably rather use:
54  //[ length, time, mass, ampere, temperature, luminosity, radians ]
55  std::array< int, 7 > fExp;
56 
57  virtual void
58  Parse(const std::string& repl); //takes a string and determines the appropriate unit exponents, and sets them in fExp
59  //should be able to handle statements like "m/s" "s^{-1}" or "kg*m^2/s^2" as well as some compound SI units like joule "J" or tesla "T", etc.
60 
61  virutal std::string ConstructString() const; //constructs a human readable string from the base unit exponents
62 
63  //at some point we may want to add the ability to support common pre-factors (e.g. k for kilo, M for Mega, u for micro, etc.)
64 };
65 
66 } // namespace hops
Definition: MHO_Unit.hh:16
bool operator==(const MHO_Unit &other) const
void RaiseToPower(int power)
MHO_Unit & operator=(const MHO_Unit &other)
void SetUnitString(const std::string unit)
Definition: MHO_Unit.hh:23
MHO_Unit & operator*=(const MHO_Unit &other)
MHO_Unit() MHO_Unit(const std::string &unit)
MHO_Unit & operator/=(const MHO_Unit &other)
MHO_Unit operator*(const MHO_Unit &other) const
virtual ~MHO_Unit()
MHO_Unit operator/(const MHO_Unit &other) const
std::string GetUnitString() const
Definition: MHO_Unit.hh:25
Definition: MHO_ChannelLabeler.hh:17