Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

gtlist.hpp

Go to the documentation of this file.
00001 //************************************************************************************
00002 // Module       : gtlist.hpp
00003 // Date         : 8/9/02 (DLR)
00004 // Copyright    : 2002-2006 Copyright University Corporation for Atmospheric
00005 //                Research
00006 // Description  : Encapsulates the methods and data associated with
00007 //                a simple template linked list. This is intended to form 
00008 //                the basic core of all single template argument lists.
00009 //                This class was taken largely from Algorithms and Data 
00010 //                Structures in C++ by Ameraal, although it has been recast 
00011 //                as a template class.
00012 // Derived From : none.
00013 // Modifications:
00014 //************************************************************************************
00015 #if !defined(GTLIST_HPP)
00016 #define GTLIST_HPP
00017 
00018 #include <iostream.h>
00019 #include <string>
00020 #include "gtypes.h"
00021 #include <stdlib.h>
00022 #include "vdbdata.hpp"
00023 #include "gneighbor.hpp"
00024 #include "point.hpp"
00025 
00026 #if !defined(GStringList)
00027 #  define GStringList GTList<string>
00028 #endif
00029 
00030 #if !defined(VDBList)
00031 #  define VDBList GTList<VDBData>
00032 #endif
00033 
00034 #if !defined(GNeighborList)
00035 #  define GNeighborList GTList<GNeighbor>
00036 #endif
00037 
00038 #if !defined(GPointList)
00039 #  define GPointList GTList<Point>
00040 #endif
00041 
00042 #if !defined(GFList)
00043 #  define GFList GTList<GDOUBLE>
00044 #endif
00045 
00046 #if !defined(GIList)
00047 #  define GIList GTList<GINT >
00048 #endif
00049 
00050 #if !defined(GCList)
00051 #  define GCList GTList<char>
00052 #endif
00053 
00054 #if !defined(GpCList)
00055 #  define GpCList GTList<char*>
00056 #endif
00057 
00058 
00059 
00060 #if !defined(TBASICLINKELEM)
00061 #define BASICLINKELEMT
00062 #define TBasicLinkElem BasicLinkElemT<TT>
00063 template<class TT> class BasicLinkElemT {
00064 public:
00065 GINT           id;
00066 GBOOL          cf;
00067 TT             *member;
00068 TBasicLinkElem *next;
00069 TBasicLinkElem *prev;
00070 };
00071 #endif
00072 
00073 
00074 template <class TT> class GTList
00075 {
00076 
00077 public:
00078                           GTList(GBOOL renumber_on_delete=FALSE);
00079                           GTList(GINT  nelems, GBOOL renumber_on_delete=FALSE);
00080                           GTList(const GTList &);
00081                          ~GTList();
00082 
00083          friend ostream&  operator<<(ostream&, GTList<TT>&);
00084          void             add();
00085          void             add(TT *c, GBOOL delete_here=FALSE);
00086          TT               *del(TBasicLinkElem *e);
00087          TT               *del(TT *c);
00088          TT               *del(GINT  id);
00089 inline   void             start(TBasicLinkElem *p=NULL) {
00090            pCurr = ( p!=NULL ? p : pStart );
00091          }
00092          GINT             size() ;
00093 inline   TT               *member() {
00094            return pCurr ? pCurr->member : NULL;
00095          }
00096 inline   TT               *member(GINT  id) {
00097            TBasicLinkElem *e;
00098            if ( (e=find(id)) == NULL ) return NULL;
00099            return e->member;
00100          }
00101 inline   TBasicLinkElem   *next() {
00102            TBasicLinkElem *p = pCurr ? pCurr->next : NULL;
00103            pCurr = p;
00104            return pCurr;
00105          }
00106          TBasicLinkElem   *curr();
00107 inline   TBasicLinkElem   *find(GINT  id){ TBasicLinkElem *p=pCurr;
00108          if ( p && p->id == id ) return p;
00109          else if ( p && p->next && p->next->id == id ) {
00110          next(); return p->next; }
00111 
00112          start(NULL);
00113          while ( (p=curr()) != NULL ) {
00114          if ( p->id == id ) return p; next(); }
00115           return NULL; }
00116 inline   TBasicLinkElem        *find(TT *c) { TBasicLinkElem *p=pCurr;
00117          if ( p && p->member == c ) return p;
00118          else if ( p && p->next && p->next->member == c ) {
00119          next(); return p->next; }
00120   
00121          start(NULL);
00122          while ( (p=curr()) != NULL ) {
00123          if ( p->member == c ) return p; next(); }
00124          return NULL; }
00125 inline   TT               &operator()(const GINT ielem) {
00126            TBasicLinkElem *tt;
00127 #if !defined(GLIST_BOUNDS)
00128            tt=find(ielem);
00129 #else
00130            if ( (tt=find(ielem)) == NULL || tt->member == NULL ) {
00131              cout << "GTList::operator(): Cannot access element " << ielem << endl;
00132              exit(1);
00133            }
00134 #endif
00135            return *(tt->member);
00136          }
00137 inline   TT               &operator[](const GINT ielem) {
00138            TBasicLinkElem *tt;
00139 #if !defined(GLIST_BOUNDS)
00140            tt=find(ielem);
00141 #else
00142            if ( (tt=find(ielem)) == NULL || tt->member == NULL ) {
00143              cout << "GTList::operator[]: Cannot access element " << ielem << endl;
00144              exit(1);
00145            }
00146 #endif
00147            return *(tt->member);
00148          }
00149          GBOOL            renumber();
00150          void             empty();
00151 //       GBOOL            inlist(GSHORT  iproc, GINT  ielem);
00152 
00153 
00154 private:
00155 // Private methods:
00156 
00157 
00158 
00159 // Private data:
00160         GINT                   nid;
00161         GINT                   num;
00162         GBOOL                  doRenumber;
00163         TBasicLinkElem         *pStart;
00164         TBasicLinkElem         *pCurr;
00165         TBasicLinkElem         *pEnd;
00166 
00167 };
00168 #  if defined(_LINUX) || defined(_AIX)
00169 template class GTList<string>;
00170 ostream &operator <<(ostream&, GTList<string>&);
00171 template class GTList<GDOUBLE>;
00172 ostream &operator <<(ostream&, GTList<GDOUBLE>&);
00173 template class GTList<GINT>;
00174 ostream &operator <<(ostream&, GTList<GINT>&);
00175 template class GTList<char>;
00176 ostream &operator <<(ostream&, GTList<char>&);
00177 template class GTList<char*>;
00178 ostream &operator <<(ostream&, GTList<char*>&);
00179 template class GTList<VDBData>;
00180 ostream &operator <<(ostream&, GTList<VDBData>&);
00181 template class GTList<GNeighbor>;
00182 ostream &operator <<(ostream&, GTList<GNeighbor>&);
00183 template class GTList<Point>;
00184 ostream &operator <<(ostream&, GTList<Point>&);
00185 # endif
00186 #endif

Generated on Wed Dec 21 16:00:48 2005 for Geophysics & Astrophysics Spectral Element Adaptive Refinement (GASpAR) 2D Code by  doxygen 1.4.4