interval.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**********************************************************************
  2. *<
  3. FILE: interval.h
  4. DESCRIPTION: Defines TimeValue and Interval Classes
  5. CREATED BY: Rolf Berteig
  6. HISTORY: created 13 September 1994
  7. 950818 - Added methods for setting start/end individually (gus)
  8. *> Copyright (c) 1994, All Rights Reserved.
  9. **********************************************************************/
  10. #ifndef _INTERVAL_H_
  11. #define _INTERVAL_H_
  12. class Interval {
  13. private:
  14. TimeValue start;
  15. TimeValue end;
  16. public:
  17. /*
  18. Constructors:
  19. */
  20. CoreExport Interval( TimeValue s, TimeValue e );
  21. Interval() { SetEmpty(); }
  22. int operator==( const Interval& i ) { return( i.start==start && i.end==end ); }
  23. CoreExport int InInterval(const TimeValue t);
  24. int InInterval(const Interval interval) { return InInterval( interval.Start() ) && InInterval( interval.End() ); }
  25. int Empty() { return (start == TIME_NegInfinity) && (end == TIME_NegInfinity); }
  26. void Set ( TimeValue s, TimeValue e ) { start = s; end = e; }
  27. void SetStart ( TimeValue s ) { start = s; }
  28. void SetEnd ( TimeValue e ) { end = e; }
  29. void SetEmpty() { start = TIME_NegInfinity; end = TIME_NegInfinity; }
  30. void SetInfinite() { start = TIME_NegInfinity; end = TIME_PosInfinity; }
  31. void SetInstant(const TimeValue t) { start = end = t; }
  32. TimeValue Start() const { return start; }
  33. TimeValue End() const { return end; }
  34. TimeValue Duration() const { return end-start+TimeValue(1); } // end points included
  35. // intersection of intervals
  36. CoreExport Interval operator&(const Interval i) const;
  37. Interval& operator&=(const Interval i) { return (*this = (*this&i)); }
  38. Interval& operator+=(const TimeValue t) { if (t<start) start=t; if (t>end) end=t; return *this; }
  39. };
  40. #define FOREVER Interval(TIME_NegInfinity, TIME_PosInfinity)
  41. #define NEVER Interval(TIME_NegInfinity, TIME_NegInfinity)
  42. #endif