CARMA C++
Length.h
1 #ifndef SZA_UTIL_LENGTH_H
2 #define SZA_UTIL_LENGTH_H
3 
11 #include "carma/szautil/ConformableQuantity.h"
12 #include "carma/szautil/Matrix.h"
13 #include "carma/szautil/Time.h"
14 
15 #include <iostream>
16 #include <cmath>
17 
18 namespace sza {
19  namespace util {
20 
21  class Length : public ConformableQuantity {
22  public:
23 
24  class Centimeters {};
25  class Meters {};
26  class Kilometers {};
27  class Microns {};
28 
29  // Scale factors used by this class
30 
31  static const unsigned cmPerM_ = 100;
32  static const unsigned cmPerKm_ = 100000;
33  static const unsigned micronsPerCm_ = 10000;
34 
38  Length();
39  Length(const Centimeters& units, double cm);
40  Length(const Meters& units, double m);
41  Length(const Kilometers& units, double km);
42 
46  Length(const Length& length);
47 
51  virtual ~Length();
52 
56  void setCentimeters(double cm);
57 
58  void setMeters(double m)
59  {
60  setCentimeters(m * cmPerM_);
61  }
62 
63  void setKilometers(double km)
64  {
65  setCentimeters(km * cmPerKm_);
66  }
67 
71  inline double centimeters() const {
72  return cm_;
73  }
74 
75  inline double meters() const {
76  return cm_ / cmPerM_;
77  }
78 
79  inline double kilometers() const {
80  return cm_ / cmPerKm_;
81  }
82 
83  inline double microns() const {
84  return cm_ * micronsPerCm_;
85  }
86 
87  Time time();
88 
89  // Operators
90 
94  void operator=(Length& length) {
95  cm_ = length.cm_;
96  }
97 
98  void operator=(const Length& length) {
99  cm_ = length.cm_;
100  }
101 
105  Length operator+(Length& length);
106  Length operator+(const Length& length);
107 
111  Length operator-(Length& length);
112  Length operator-(const Length& length);
113 
117  Length operator*(double multFac);
118  void operator*=(double multFac);
119 
123  double operator/(const Length& length);
124  double operator/(Length& length);
125 
126  Length operator/(double fac);
127  void operator/=(double fac);
128 
129  void operator+=(const Length& length);
130  void operator+=(Length& length);
131 
132  void operator-=(const Length& length);
133  void operator-=(Length& length);
134 
135  bool operator==(const Length& length);
136  bool operator==(Length& length);
137 
141  friend std::ostream& operator<<(std::ostream& os, Length& length);
142  friend std::ostream& operator<<(std::ostream& os, const Length& length);
143 
144  void initialize();
145 
146  protected:
147 
148  double cm_;
149 
150  }; // End class Length
151 
152  // Define a right matrix multiplier operator
153 
154  Vector<Length> operator*(Matrix<double>& mat, Vector<Length>& vec);
155 
156  void operator/=(Vector<Length>& vec, double fac);
157 
158  Vector<Length> operator*(Vector<double>& vec, Length& fac);
159 
160  } // End namespace util
161 } // End namespace sza
162 
163 
164 
165 #endif // End #ifndef SZA_UTIL_LENGTH_H