AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

BBoxList.h

Go to the documentation of this file.
00001 #ifndef _included_BBoxList_h
00002 #define _included_BBoxList_h
00003 
00009 #include "DAGHDefaults.h"
00010 
00011 #include "BucketType.h"
00012 #include "BBox.h"
00013 #include "Coords.h"
00014 #include "ObjectCounter.h"
00015 
00016 #include <iostream.h>
00017 #include <fstream.h>
00018 #include "streams_CompConf.h"
00019 
00020 #define BBoxListNULL ((BBoxList *) NULL)
00021 
00022 #ifndef DefBBoxListSize
00023 #define DefBBoxListSize              (128)
00024 #endif
00025 
00026 // #ifdef __GNUG__
00027 // template class Bucket<BBox>;
00028 // #endif
00029 
00030 typedef Bucket<BBox> Bucket_BBox; 
00031 
00037 class BBoxList : public Bucket<BBox>, public ObjectCounter
00038   {
00039    friend ostream& operator << (ostream& s, const BBoxList& bbl);
00040 
00041    friend ofstream& operator << (ofstream& s, const BBoxList& bbl);
00042    friend ifstream& operator >> (ifstream& s, BBoxList& bbl);
00043    friend strstream& operator << (strstream& s, const BBoxList& bbl);
00044    friend strstream& operator >> (strstream& s, BBoxList& bbl);
00045 
00046    friend class BBox;
00047 
00048    int num;
00049 
00050 private:
00051    static inline void copytypedata(BBox *to, BBox const *from)
00052         { *to = *from; }
00053 
00054    /*************************************************************************/
00055    /*** Set list statistics ***/
00056    /*************************************************************************/
00057    inline int setstats(void)
00058      {
00059       num = 0;
00060       for ( BBox *b=first();b!=BBoxNULL;b=next() ) num++;
00061       return num;
00062      }
00063 
00064 public:
00065    /*************************************************************************/
00066    /*** Constructors ***/
00067    /*************************************************************************/
00068    inline BBoxList()
00069         : Bucket<BBox>(DefBBoxListSize), num(0) {}
00070 
00071    // We need dumarg because the SP2 does implicit conversions
00072    // from anything to this class
00073    inline BBoxList(unsigned const maxnum, const int dumarg) 
00074         : Bucket<BBox>(maxnum), num(0) {}
00075 
00076    inline BBoxList(void const *package, unsigned const size, const int n)
00077         : Bucket<BBox>(package, size, n), num(0)
00078         { setstats(); }
00079 
00080    /*$inline BBoxList(void const *package)
00081         : Bucket<BBox>(package), num(0)
00082         { setstats(); }
00083 
00084    inline BBoxList(void *package)
00085         : Bucket<BBox>(package), num(0)
00086         { setstats(); }$*/
00087 
00088    inline BBoxList(BBoxList const &other)
00089         : Bucket<BBox>(other), num(other.num) {}
00090 
00091    BBoxList &operator = (const BBoxList&);
00092 
00093    /*************************************************************************/
00094    /*** Destructor ***/
00095    /*************************************************************************/
00096    inline ~BBoxList(void) {}
00097 
00098    /*************************************************************************/
00099    /*** Query functions ***/
00100    /*************************************************************************/
00101    inline int number() const { return(num); }
00102    inline int isempty() const { return(num == 0); }
00103 
00104    /*************************************************************************/
00105    /* Empty the list */
00106    /*************************************************************************/
00107    inline void empty(void)
00108         { Bucket<BBox>::empty(); num = 0; }
00109 
00110    /*************************************************************************/
00111    /* BBoxList operators */
00112    /*************************************************************************/
00113    int difference(BBoxList& bbl, const BBox& lhs, const BBox& rhs);
00114    int intersection(BBoxList& bbl, const BBox& lhs, const BBox& rhs);
00115    void operator -= (const BBoxList &rhs); /* Difference */
00116    void operator -= (const BBox &rhs); 
00117    void operator *= (const BBoxList &rhs); /* Intersection */
00118    void operator *= (const BBox &rhs); 
00119    //BBoxList *operator * (BBoxList const &rhs); /* intersection */
00120    //void operator += (BBoxList const &rhs); /* union */
00121    //BBoxList *operator + (BBoxList const &rhs); /* union */
00122 
00123 private:
00124    /*************************************************************************/
00125    /* Nest with another list - This needs work */
00126    /*************************************************************************/
00127    void nest(const BBoxList &rhs);
00128 
00129 public:
00130    /*************************************************************************/
00131    /* Merge bounding boxes in the list is possible */
00132    /*************************************************************************/
00133    void mergeboxes(const short* olap);
00134 
00135    /*************************************************************************/
00136    /* Combine two bbl's */
00137    /*************************************************************************/
00138    void combine(const BBoxList &rhs);
00139    
00140    /*************************************************************************/
00141    /* Reduce the list in a single bounding box */
00142    /*************************************************************************/
00143    BBox reduce();
00144 
00145    /*************************************************************************/
00146    /* List manipulation functions */
00147    /*************************************************************************/
00148    inline BBox *add()
00149       { num++; return (Bucket<BBox>::add()); }
00150    inline BBox *add(BBox const &bb)
00151       { num++; return (Bucket<BBox>::add(bb)); }
00152    inline BBox *insert(BBox const &bb)
00153       { num++; return (Bucket<BBox>::insert(bb)); }
00154    inline void remove(void)
00155       { 
00156         BBox *bb = current();
00157         if (bb) { num--; Bucket<BBox>::remove(); }
00158       }
00159 
00160    /*************************************************************************/
00161    /* Split the list bucket */
00162    /*************************************************************************/
00163    inline void split(BBoxList &bbl)
00164      {
00165       Bucket<BBox>::split((Bucket<BBox> &) bbl);
00166       bbl.setstats(); num -= bbl.num;
00167      }
00168   };
00169 
00170 ostream& operator<<(ostream&, const BBoxList&);
00171 ofstream& operator<<(ofstream&, const BBoxList&);
00172 ifstream& operator>>(ifstream&, BBoxList&);
00173 
00174   /*************************************************************************/
00175   /* interface routines */
00176   /*************************************************************************/
00177   inline BBox *first(BBoxList &bbl)
00178         { return (bbl.first()); }
00179   inline BBox *next(BBoxList &bbl)
00180         { return (bbl.next()); }
00181   inline BBox *prev(BBoxList &bbl)
00182         { return (bbl.prev()); }
00183   inline BBox *current(BBoxList &bbl)
00184         { return (bbl.current()); }
00185   inline BBox *last(BBoxList &bbl)
00186         { return (bbl.last()); }
00187 
00188   inline void add(BBoxList &bbl, BBox const &bb)
00189         { bbl.add(bb); }
00190   inline void insert(BBoxList &bbl, BBox const &bb)
00191         { bbl.insert(bb); }
00192   inline void remove(BBoxList &bbl)
00193         { bbl.remove(); }
00194 
00195   inline int number(BBoxList const &bbl)
00196         { return (bbl.number()); }
00197   inline int isempty(BBoxList const &bbl)
00198         { return (bbl.isempty()); }
00199 
00200   inline void empty(BBoxList &bbl)
00201         { bbl.empty(); }
00202 #endif


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04