00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef RYTHMOS_TIME_RANGE_DECL_H
00030 #define RYTHMOS_TIME_RANGE_DECL_H
00031
00032 #include "Rythmos_ConfigDefs.h"
00033
00034 namespace Rythmos {
00035
00036
00059 template<class TimeType>
00060 int compareTimeValues( const TimeType &t1, const TimeType &t2 );
00061
00069 template<class TimeType>
00070 class TimeRange
00071 {
00072 public:
00074 TimeRange()
00075 : lower_(0.0), upper_(-1.0)
00076 {}
00078 TimeRange( const TimeType &lower, const TimeType &upper )
00079 : lower_(lower), upper_(upper)
00080 {
00081 }
00083 TimeRange( const TimeRange<TimeType>& tr )
00084 : lower_(tr.lower()), upper_(tr.upper())
00085 {
00086 }
00088 virtual ~TimeRange() {}
00090 bool isValid() const { return (lower_ <= upper_); }
00092 TimeType lower() const { return lower_; }
00094 TimeType upper() const { return upper_; }
00096 TimeType length() const { return (upper_ - lower_); }
00098 virtual bool isInRange ( const TimeType &t ) const
00099 {
00100 return (
00101 compareTimeValues(t,lower_) >= 0
00102 && compareTimeValues(t,upper_) <= 0
00103 );
00104 }
00106 TimeRange<TimeType> copyAndScale( const TimeType &scale ) const
00107 {
00108 TimeRange<TimeType> newRange = *this;
00109 if (!newRange.isValid())
00110 return newRange;
00111 newRange.lower_ *= scale;
00112 newRange.upper_ *= scale;
00113 return newRange;
00114 }
00115
00116 private:
00117 TimeType lower_;
00118 TimeType upper_;
00119 };
00120
00125 template<class TimeType>
00126 TimeRange<TimeType> timeRange(const TimeType lower, const TimeType upper);
00127
00128
00133 template<class TimeType>
00134 TimeRange<TimeType> invalidTimeRange();
00135
00136
00141 template<class TimeType>
00142 std::ostream& operator<<( std::ostream& out, const TimeRange<TimeType>& range );
00143
00144
00148 template<class TimeType>
00149 void asssertInTimeRange( const TimeRange<TimeType> &timeRange,
00150 const TimeType &time );
00151
00152
00159 template<class TimeType>
00160 bool isInRange_cc(const TimeRange<TimeType> &tr, const TimeType &p);
00161
00162
00169 template<class TimeType>
00170 bool isInRange_oc(const TimeRange<TimeType> &tr, const TimeType &p);
00171
00172
00179 template<class TimeType>
00180 bool isInRange_co(const TimeRange<TimeType> &tr, const TimeType &p);
00181
00182
00189 template<class TimeType>
00190 bool isInRange_oo(const TimeRange<TimeType> &tr, const TimeType &p);
00191
00192 template<class TimeType>
00193 class TimeRange_cc : virtual public TimeRange<TimeType>
00194 {
00195 public:
00196 TimeRange_cc(const TimeRange<TimeType>& tr)
00197 :TimeRange<TimeType>(tr)
00198 {
00199 }
00200 TimeRange_cc( const TimeType &lower, const TimeType &upper )
00201 :TimeRange<TimeType>(lower,upper)
00202 {
00203 }
00204 bool isInRange ( const TimeType &t ) const
00205 {
00206 return ( isInRange_cc<TimeType>(*this,t) );
00207 }
00208 };
00209
00210 template<class TimeType>
00211 class TimeRange_co : virtual public TimeRange<TimeType>
00212 {
00213 public:
00214 TimeRange_co(const TimeRange<TimeType>& tr)
00215 :TimeRange<TimeType>(tr)
00216 {
00217 }
00218 TimeRange_co( const TimeType &lower, const TimeType &upper )
00219 :TimeRange<TimeType>(lower,upper)
00220 {
00221 }
00222 bool isInRange ( const TimeType &t ) const
00223 {
00224 return ( isInRange_co<TimeType>(*this,t) );
00225 }
00226 };
00227
00228 template<class TimeType>
00229 class TimeRange_oo : virtual public TimeRange<TimeType>
00230 {
00231 public:
00232 TimeRange_oo(const TimeRange<TimeType>& tr)
00233 :TimeRange<TimeType>(tr)
00234 {
00235 }
00236 TimeRange_oo( const TimeType &lower, const TimeType &upper )
00237 :TimeRange<TimeType>(lower,upper)
00238 {
00239 }
00240 bool isInRange ( const TimeType &t ) const
00241 {
00242 return ( isInRange_oo<TimeType>(*this,t) );
00243 }
00244 };
00245
00246 template<class TimeType>
00247 class TimeRange_oc : virtual public TimeRange<TimeType>
00248 {
00249 public:
00250 TimeRange_oc(const TimeRange<TimeType>& tr)
00251 :TimeRange<TimeType>(tr)
00252 {
00253 }
00254 TimeRange_oc( const TimeType &lower, const TimeType &upper )
00255 :TimeRange<TimeType>(lower,upper)
00256 {
00257 }
00258 bool isInRange ( const TimeType &t ) const
00259 {
00260 return ( isInRange_oc<TimeType>(*this,t) );
00261 }
00262 };
00263
00264
00265 }
00266
00267
00268 #endif //RYTHMOS_TIME_RANGE_DECL_H