Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

legoPSet.H

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------*/
00002 /*  Name:           legoPSet.H                                            */
00003 /*  Designer:       Willie Glover                                         */
00004 /*  Date:           5/16/96                                               */
00005 /*                                                                        */
00006 /*  Description:    Defines template class legoPSet which is a set        */
00007 /*                     container that holds pointers to legoOps and       */
00008 /*                     lRegions.                                          */
00009 /*                                                                        */
00010 /*  12/05/96 WAH:   Added copy constructor for legoPSet.                  */
00011 /*  2/13/97 WAH:    Added Detach method to remove an item without ever    */
00012 /*                  destroying it.                                        */
00013 /*  3/7/97 WAH:     Added Replace method to replace an item with another  */
00014 /*                  item (an in-place swap).                              */
00015 /*  3/16/97 WAH:    Added Search and Insert methods.                      */
00016 /*  2/18/98 WAH:    Made destructor virtual.
00017 /*------------------------------------------------------------------------*/
00018 
00019 #if !defined( LEGOPSET_H )
00020 #define LEGOPSET_H
00021 
00022 //#if !defined( LEGOMORE_H )
00023 //#include "legoMore.H"
00024 //#endif
00025 
00026 #if !defined( LEGOPARR_H )
00027 #include "legoPArr.H"
00028 #endif
00029 
00030 template <class T> class legoPSetIterator;
00031 
00032 template <class T> class legoPSet
00033 {
00034 
00035 protected:
00036 
00037     legoPArr<T> Data;          // this instance of lego array of pointers
00038 
00039 public:
00040 
00041     friend legoPSetIterator<T>;
00042 /*
00043  *   construct a legoPArr of size 4 and increment 4
00044  */
00045     legoPSet() : Data(4,4)
00046     {
00047       //      fprintf(stderr,"Creating LEGOPSET %p\n",this);
00048     }
00049 
00050   legoPSet(const legoPSet<T> &);
00051 
00052     virtual ~legoPSet()
00053     {
00054       //      fprintf(stderr,"Deleting LEGOPSET %p\n",this);
00055     }
00056 
00057     int AddItem( T t )
00058     {
00059        //   if ( Data.Search((void*)t,1) ) { return 0; }
00060           return Data.AddItem((void*)t); 
00061     }
00062 
00063     void Replace ( T item, unsigned index )
00064     {
00065       Data.Replace( item, index );
00066     }
00067 
00068     int IsEmpty() const
00069         { return Data.IsEmpty(); }
00070 
00071     int IsFull() const
00072         { return 0; }
00073 
00074     int GetCount() const
00075         { return Data.GetCount(); }
00076 
00077     T GetItem(unsigned index)
00078         { return Data[index]; }
00079 
00080     void DestroyItem(unsigned index)
00081         { Data.DestroyItem( index ); }
00082 
00083     void Detach(unsigned index)
00084     {
00085       int sd = Data.shouldDelete;
00086 
00087       Data.shouldDelete = false;
00088       Data.DestroyItem( index );
00089       Data.shouldDelete = sd;
00090     }
00091 
00092     void Insert (T item, unsigned index, unsigned count = 1)
00093     {
00094       Data.Insert (item, index, count);
00095     }
00096 
00097     unsigned Search (T item, int direction = +1)
00098     {
00099       return Data.Search (item, direction);
00100     }
00101 
00102 
00103 //
00104 //  int HasMember( const T *t ) const
00105 //      { return Data.Search(t,1) != UINT_MAX; }
00106 //
00107 //  void Flush()
00108 //      { Data.PEmpty(); }
00109 //
00110 //  T *Find( T *t ) const
00111 //      {
00112 //      unsigned loc = Data.Find(t);
00113 //      return ( loc == UINT_MAX ? 0 : STATIC_CAST(T *,Data[loc]) );
00114 //     }
00115 //
00116 //  void ForEach( IterFunc iter, void *args )
00117 //      { Data.ForEach( iter, args, 0, Data.Top() ); }
00118 //
00119 //  T *FirstThat( CondFunc cond, void *args ) const
00120 //      { return Data.FirstThat( cond, args, 0, Data.Top() ); }
00121 //
00122 //  T *LastThat( CondFunc cond, void *args ) const
00123 //      { return Data.LastThat( cond, args, 0, Data.Top() ); }
00124 
00125 };
00126 
00127 template <class T> legoPSet<T>::legoPSet (const legoPSet<T> &orig)
00128 {
00129   //  fprintf(stderr,"Creating LEGOPSET %p\n",this);
00130   Data = orig.Data;
00131 } // end copy constructor
00132 
00133 /*-------------------------- Iterator ----------------------------*/
00134 
00135 template <class T> class legoPSetIterator :
00136     public legoPArrItr<T>
00137 {
00138 
00139 public:
00140 
00141     legoPSetIterator( const legoPArr<T>& s ) :
00142         legoPArrItr<T>(s) {}
00143 
00144 };
00145 
00146 #endif  // LEGOPSET_H

Generated on Mon Jul 21 20:27:42 2003 for TINKER LEGO DOC by doxygen 1.3.2