CARMA C++
Units.h
Go to the documentation of this file.
1 // $Id: Units.h,v 1.23 2007/10/09 18:25:58 abeard Exp $
2 
30 #ifndef CARMA_SERVICES_UNITS_H
31 #define CARMA_SERVICES_UNITS_H
32 
33 #include <limits>
34 #include <string>
35 
36 struct unittype;
37 
38 
39 namespace carma {
40  namespace services {
41 
46  class Units {
47  public:
49  Units();
51  virtual ~Units();
52 
73  double convert(const char * convertFrom,
74  const char * convertTo) const;
75 
76  double convert(const std::string& convertFrom,
77  const std::string& convertTo) const;
78 
89  double convert(double value,
90  const char * convertFrom,
91  const char * convertTo) const;
92 
93  double convert(double value,
94  const std::string& convertFrom,
95  const std::string& convertTo) const;
96 
97  template < typename T >
98  int numericLimit( ) {
99  ::std::numeric_limits< T > limit;
100 
101  return static_cast< int >(floor(0.5 +log10(1/limit.epsilon())));
102  }
103 
105  inline double tera() const {return(convert("tera", ""));}
106 
108  inline double giga() const {return(convert("giga", ""));}
109 
111  inline double mega() const {return(convert("mega", ""));}
112 
114  inline double kilo() const {return(convert("kilo", ""));}
115 
117  inline double hecto() const {return(convert("hecto", ""));}
118 
120  inline double deca() const {return(convert("deca", ""));}
121 
123  inline double deci() const {return(convert("deci", ""));}
124 
126  inline double centi() const {return(convert("centi", ""));}
127 
129  inline double milli() const {return(convert("milli", ""));}
130 
132  inline double micro() const {return(convert("micro", ""));}
133 
135  inline double nano() const {return(convert("nano", ""));}
136 
138  inline double pico() const {return(convert("pico", ""));}
139 
140  private:
142  bool reciprocalHoldingMasterLock(
143  struct unittype * fromUnit,
144  struct unittype * toUnit,
145  struct unittype * inverseFromUnit) const;
146  };
147  }
148 }
149 
150 #endif //CARMA_SERVICES_UNITS_H
double deca() const
times ten
Definition: Units.h:120
double kilo() const
times one thousand
Definition: Units.h:114
virtual ~Units()
Destructor.
double centi() const
times one hundredth
Definition: Units.h:126
double mega() const
times one million
Definition: Units.h:111
double milli() const
times one thousandth
Definition: Units.h:129
double micro() const
times one million
Definition: Units.h:132
double tera() const
times one trillion
Definition: Units.h:105
double deci() const
times one tenth
Definition: Units.h:123
double hecto() const
times one hundred
Definition: Units.h:117
double convert(const char *convertFrom, const char *convertTo) const
Convert value and units to new units.
double pico() const
times one trillionth
Definition: Units.h:138
double giga() const
times one billion
Definition: Units.h:108
Units()
Constructor.
double nano() const
times one billionth
Definition: Units.h:135
This class is based on the GNU units library.
Definition: Units.h:46