CARMA C++
Range.h
Go to the documentation of this file.
1 #ifndef SZA_UTIL_RANGE_H
2 #define SZA_UTIL_RANGE_H
3 
13 
14 namespace sza {
15  namespace util {
16 
17  template<class Type>
18  class Range;
19 
20  template <class Type>
21  std::ostream& operator<<(std::ostream& os,
22  const Range<Type>& range);
23 
24  // Class for managing a range
25 
26  template<class Type>
27  class Range {
28  public:
29 
33  Range();
34 
38  Range(Type start, Type stop);
39 
43  virtual ~Range();
44 
45  void setStart(Type start);
46  void setStop(Type stop);
47 
48  Type start();
49  Type stop();
50 
54  friend std::ostream& operator << <>
55  (std::ostream& os, const Range<Type>& range);
56 
60  Range& operator+=(Type incr);
61 
65  Range& operator*=(Type mult);
66 
67  private:
68 
69  Type start_;
70  bool startInit_;
71  Type stop_;
72  bool stopInit_;
73 
74  }; // End class Range
75 
79  template<class Type>
80  Range<Type>::Range() {
81  startInit_ = false;
82  stopInit_ = false;
83  };
84 
85  // Constructor with initialization
86 
87  template<class Type>
88  Range<Type>::Range(Type start, Type stop) {
89  startInit_ = false;
90  stopInit_ = false;
91 
92  setStart(start);
93  setStop(stop);
94  };
95 
99  template<class Type>
100  Range<Type>::~Range() {};
101 
105  template<class Type>
106  void Range<Type>::setStart(Type start) {
107  start_ = start;
108  startInit_ = true;
109  }
110 
114  template<class Type>
115  void Range<Type>::setStop(Type stop) {
116  stop_ = stop;
117  stopInit_ = true;
118  }
119 
123  template<class Type>
124  Type Range<Type>::start() {
125  if(!startInit_) {
126  LogStream errStr;
127  errStr.appendMessage(true, "Start value has not been initialized\n");
128  throw Error(errStr);
129  }
130  return start_;
131  }
132 
136  template<class Type>
137  Type Range<Type>::stop() {
138  if(!startInit_) {
139  LogStream errStr;
140  errStr.appendMessage(true, "End value has not been initialized\n");
141  throw Error(errStr);
142  }
143  return stop_;
144  }
145 
149  template <class Type>
150  std::ostream& operator<<(std::ostream& os,
151  const Range<Type>& range)
152  {
153  os << "(" << range.start_ << "-" << range.stop_ << ")";
154  return os;
155  }
156 
157 
161  template <class Type>
162  Range<Type>& Range<Type>::operator+=(Type incr)
163  {
164  start_ += incr;
165  stop_ += incr;
166 
167  return *this;
168  }
169 
173  template <class Type>
174  Range<Type>& Range<Type>::operator*=(Type mult)
175  {
176  start_ *= mult;
177  stop_ *= mult;
178  return *this;
179  }
180 
181  } // End namespace util
182 } // End namespace sza
183 
184 
185 
186 #endif // End #ifndef SZA_UTIL_RANGE_H
Started: Sun Dec 14 07:19:50 UTC 2003.
Tagged: Fri Nov 14 12:39:33 UTC 2003.