BAPS/packing/BP/Interval.h

00001 /**********************************************************************
00002  *
00003  * Filename    : Interval.h
00004  * Author      : Chen Li Wen
00005  *
00006  * Version     : 1.0 
00007  * Date        : 09-27-98
00008  *
00009  * Description : Header file for class Interval. It keeps an interval, 
00010  *               which can be open, close, or half open. It supports 
00011  *               all interval operations:
00012  *               --- Union: return the union of two intersecting 
00013  *                          intervals;
00014  *               --- Intersect: return the intersection of two
00015  *                              intervals;
00016  *               --- SymDiff: return the symmitric difference of two 
00017  *                            intervals;
00018  *               --- Length: return the size of the interval.
00019  *
00020  * Reference   : nil
00021  *
00022  * Notes       : nil
00023  *
00024  * Changes     : 
00025  *
00026  * Copyright   : Copyright (c) 1998
00027  *               All rights reserved by
00028  *               Resource Allocation and Scheduling Group
00029  *               Department of Computer Science
00030  *               School of Computing
00031  *               National University of Singapore
00032  *
00033  **********************************************************************/
00034 
00035 #ifndef __INTERVAL_H__
00036 #define __INTERVAL_H__
00037 
00038 
00039 #include "PackDef.h"
00040 
00041 
00042 #include <iostream.h>
00043 
00044 
00045 class Interval
00046 {
00047    public:
00048       
00049       //
00050       // Each interval contains four parameters: the left point,
00051       // the right point, the open or close status of each end.
00052       //    0: close; 
00053       //    1: open.
00054       //
00055       
00056       Interval();
00057       Interval(double aLeftPoint, 
00058                double aRightPoint, 
00059                int    aLeftStatus = 0, 
00060                int    aRightStatus = 0);
00061       Interval(const Interval & aInterval);
00062       ~Interval();
00063 
00064 
00065       //
00066       // Assignment operator.
00067       //
00068       
00069       Interval & operator=(const Interval & aInterval);
00070 
00071 
00072       //
00073       // Equality operators.
00074       //
00075       
00076       Bool operator==(const Interval & aInterval) const;
00077       Bool operator!=(const Interval & aInterval) const;
00078 
00079       
00080       //
00081       // Debugger facility
00082       //
00083       
00084       void Print() const;
00085 
00086       
00087       //
00088       // Access methods
00089       //
00090       
00091       double GetLeftPoint()   const { return mLeftPoint; }
00092       double GetRightPoint()  const { return mRightPoint; }
00093       double GetLength()      const { return (mRightPoint - mLeftPoint); }
00094       int    GetLeftStatus()  const { return mLeftStatus; }
00095       int    GetRightStatus() const { return mRightStatus; }
00096 
00097 
00098       //
00099       // Modification methods
00100       //
00101       
00102       void SetLeftPoint(double aLeftPoint)   { mLeftPoint = aLeftPoint; }
00103       void SetRightPoint(double aRightPoint) { mRightPoint = aRightPoint; }
00104       void SetLeftStatus(int aLeftStatus)    { mLeftStatus = aLeftStatus; }
00105       void SetRightStatus(int aRightStatus)  { mRightStatus = aRightStatus; }
00106       
00107       
00108       //
00109       // Determine interval is empty or not.
00110       //
00111       
00112       Bool IsEmpty() const 
00113            { return ((*this).GetLength() == 0 ? TRUE : FALSE); }
00114       
00115       
00116       //
00117       // Check whether the two intervals can be combined to 
00118       // a single interval.
00119       //
00120       
00121       friend Bool NextTo(const Interval& Lhs, const Interval& Rhs);
00122       
00123 
00124       //
00125       // Only when the two intervals are next to each other.
00126       //
00127       
00128       friend Interval 
00129              Union(const Interval& Lhs, const Interval& Rhs);
00130       
00131 
00132       //
00133       // No constraint.
00134       //
00135       
00136       friend Interval 
00137              Intersect(const Interval & Lhs, const Interval & Rhs);
00138       friend int
00139              compare(const Interval & Lhs, const Interval & Rhs);
00140       friend ostream &
00141              operator<<(ostream & aOstream, const Interval & aInterval);
00142       friend istream &
00143              operator>>(istream & aIstream, Interval & aInterval);
00144          
00145          
00146    private:
00147    
00148       double mLeftPoint;
00149       double mRightPoint;
00150       int    mLeftStatus;
00151       int    mRightStatus;
00152 };
00153 
00154 
00155 #endif

Generated on Tue Sep 9 15:40:10 2008 for BAP by  doxygen 1.5.3