interval.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: interval.h
00004 
00005     DESCRIPTION:  Defines TimeValue and Interval Classes
00006 
00007     CREATED BY: Rolf Berteig
00008 
00009     HISTORY: created 13 September 1994
00010              950818 - Added methods for setting start/end individually (gus)
00011 
00012  *> Copyright (c) 1994, All Rights Reserved.
00013  **********************************************************************/
00014 
00015 
00016 #pragma once
00017 #include "maxheap.h"
00018 #include "coreexp.h"
00019 #include "maxtypes.h"
00020 
00033 class Interval: public MaxHeapOperators {
00034     private:
00035         TimeValue   start;
00036         TimeValue   end;
00037 
00038     public:     
00039         /* 
00040          Constructors:
00041          */     
00050         CoreExport Interval( TimeValue s, TimeValue e );
00053         Interval() { SetEmpty(); } 
00054 
00057         int operator==( const Interval& i ) { return( i.start==start && i.end==end ); }
00066         CoreExport int InInterval(const TimeValue t) const;
00076         int InInterval(const Interval interval) const { return InInterval( interval.Start() ) && InInterval( interval.End() ); }
00080         int Empty() { return (start == TIME_NegInfinity) && (end == TIME_NegInfinity); }
00081 
00088         void Set       ( TimeValue s, TimeValue e ) { start = s; end = e; }
00093         void SetStart  ( TimeValue s )              { start = s;          }
00098         void SetEnd    ( TimeValue e )              { end = e;            }
00099 
00102         void SetEmpty() { start = TIME_NegInfinity; end = TIME_NegInfinity; }
00106         void SetInfinite() { start = TIME_NegInfinity; end = TIME_PosInfinity; }
00108         void SetInstant(const TimeValue t) { start = end = t; }
00110         TimeValue Start() const { return start; }
00112         TimeValue End() const { return end; }
00117         TimeValue Duration() const { return end-start+TimeValue(1); } // end points included
00118 
00119         // intersection of intervals
00126         CoreExport Interval operator&(const Interval i) const;
00131         Interval& operator&=(const Interval i) { return (*this = (*this&i)); }
00134         Interval& operator+=(const TimeValue t) { if (t<start) start=t; if (t>end) end=t; return *this; }
00135 };
00136 
00137 #define FOREVER Interval(TIME_NegInfinity, TIME_PosInfinity)
00138 #define NEVER Interval(TIME_NegInfinity, TIME_NegInfinity)
00139 
00140 
00141