My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
Length.h
Go to the documentation of this file.
1 #ifndef GCP_UTIL_LENGTH_H
2 #define GCP_UTIL_LENGTH_H
3 
11 #include <iostream>
12 #include <cmath>
13 
14 #include "gcp/util/common/ConformableQuantity.h"
15 
16 namespace gcp {
17  namespace util {
18 
19  class Length : public ConformableQuantity {
20  public:
21 
22  class Centimeters {};
23  class Meters {};
24  class Kilometers {};
25  class Microns {};
26 
27  // Scale factors used by this class
28 
29  static const unsigned cmPerMeter_;
30  static const unsigned cmPerKm_;
31  static const unsigned micronsPerCm_;
32 
33  static const double metersPerMile_;
34  static const double cmPerMile_;
35 
39  Length();
40  Length(const Centimeters& units, double cm);
41  Length(const Meters& units, double m);
42 
46  Length(const Length& length);
47 
51  virtual ~Length();
52 
56  void setCentimeters(double cm)
57  {
58  cm_ = cm;
59  finite_ = finite(cm);
60  }
61 
62  void setMeters(double m)
63  {
64  setCentimeters(m * cmPerMeter_);
65  }
66 
67  void setKilometers(double km)
68  {
69  setCentimeters(km * cmPerMeter_);
70  }
71 
75  inline double centimeters() const {
76  return cm_;
77  }
78 
79  inline double meters() const {
80  return cm_ / cmPerMeter_;
81  }
82 
83  inline double kilometers() const {
84  return cm_ / cmPerKm_;
85  }
86 
87  // Operators
88 
92  Length operator+(Length& length);
93 
97  Length operator-(Length& length);
98 
102  Length operator*(double multFac);
103 
107  double operator/(Length& length);
108 
112  friend std::ostream& operator<<(std::ostream& os, Length& length);
113 
114  void initialize();
115 
116  protected:
117 
118  double cm_;
119 
120  }; // End class Length
121 
122  } // End namespace util
123 } // End namespace gcp
124 
125 
126 
127 
128 #endif // End #ifndef GCP_UTIL_LENGTH_H
double centimeters() const
Definition: Length.h:75
Definition: ConformableQuantity.h:16
Definition: Length.h:23
friend std::ostream & operator<<(std::ostream &os, Length &length)
Definition: Length.cc:90
double operator/(Length &length)
Definition: Length.cc:72
void setCentimeters(double cm)
Definition: Length.h:56
Length()
Definition: Length.cc:21
Definition: Length.h:25
Definition: Length.h:22
virtual ~Length()
Definition: Length.cc:47
Definition: Length.h:24
Length operator-(Length &length)
Definition: Length.cc:62
Length operator+(Length &length)
Definition: Length.cc:52
Definition: Length.h:19
Length operator*(double multFac)
Definition: Length.cc:80