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

glinoplist.hpp

Go to the documentation of this file.
00001 //************************************************************************************//
00002 // Module       : glinoplist.hpp
00003 // Date         : 7/17/03 (DLR)
00004 // Copyright    : 2003-2006 Copyright University Corporation for Atmospheric
00005 //                Research
00006 // Description  : Encapsulates the methods and data associated with
00007 //                a simple LinOp linked list. This class was taken
00008 //                largely from Algorithms and Data Structures in C++
00009 //                by Ameraal, although it has been recast.
00010 // Derived From : none.
00011 // Modifications:
00012 //************************************************************************************//
00013 #if !defined(GLINOPLIST_HPP)
00014 #define GLINOPLIST_HPP
00015 
00016 #include "gtypes.h"
00017 #include <iostream.h>
00018 #include <stdlib.h>
00019 #include "linop.hpp"
00020 
00021 
00022 
00023 #if !defined(GLINOPELEM)
00024 #define GLINOPELEM
00025 class GLinOpElem {
00026 public:
00027 GINT      id;
00028 GBOOL     cf;
00029 LinOp     *member;
00030 GLinOpElem *next;
00031 GLinOpElem *prev;
00032 }; 
00033 #endif
00034 
00035 
00036 class GLinOpList
00037 {
00038 public:
00039                           GLinOpList(GBOOL renumber_on_delete=FALSE);
00040                           GLinOpList(GINT  nelems, GBOOL renumber_on_delete=FALSE);
00041                           GLinOpList(const GLinOpList &){};
00042                          ~GLinOpList();
00043 
00044          void             add(LinOp *c, GBOOL delete_here=TRUE);
00045          LinOp            *del(GLinOpElem *c);
00046          LinOp            *del(LinOp *c);
00047          LinOp            *del(GINT  id);
00048 inline   void             start(GLinOpElem *p=NULL) {
00049            pCurr = ( p!=NULL ? p : pStart );
00050          }
00051          GINT             size() ;
00052 inline   LinOp            *member() {
00053            return pCurr ? pCurr->member : NULL;
00054          }
00055          LinOp            *member(GINT  id) {
00056            GLinOpElem *e;
00057            if ( (e=find(id)) == NULL ) return NULL;
00058            return e->member;
00059          }
00060 inline   GLinOpElem       *next() {
00061            GLinOpElem *p = pCurr ? pCurr->next : NULL;
00062            pCurr = p; return pCurr;
00063          }
00064          GLinOpElem       *curr();
00065 inline   GLinOpElem       *find(GINT  id) {
00066            GLinOpElem *p=pCurr;
00067            // check from current pointer first:
00068            if ( p && p->id == id ) return p;
00069            else if ( p && p->next && p->next->id == id ) {
00070               next();
00071               return p->next;
00072            }
00073            start(NULL); // start at beginning and search:
00074            while ( (p=curr()) != NULL ) { 
00075              if ( p->id == id ) return p;
00076              next();
00077            }
00078            return NULL;
00079          }
00080 inline   GLinOpElem       *find(LinOp *member) {
00081            GLinOpElem *p=pCurr;
00082            // check from current pointer first:
00083            if ( p && p->member == member ) return p; 
00084            else if ( p && p->next && p->next->member == member ) {
00085              next();
00086              return p->next;
00087            }
00088            start(NULL); // start at beginning and search:
00089            while ( (p=curr()) != NULL ) {
00090              if ( p->member == member ) return p;
00091              next();
00092            }
00093            return NULL;
00094          }
00095 inline   LinOp            *&operator()(const GINT  iElem) {
00096            GLinOpElem  *tt;
00097 #if !defined(GLIST_BOUNDS)
00098            tt=find(iElem);
00099 #else
00100            if ( (tt=find(iElem)) == NULL ) {
00101              cout << "GTTList::operator(): Cannot access element " << iElem << endl;
00102              exit(1);
00103            }
00104 #endif
00105            return tt->member;
00106          }
00107 inline   LinOp            *&operator[](const GINT  iElem) {
00108            GLinOpElem  *tt;
00109 #if !defined(GLIST_BOUNDS)
00110            tt=find(iElem);
00111 #else
00112            if ( (tt=find(iElem)) == NULL ) {
00113              cout << "GTTList::operator[]: Cannot access element " << iElem << endl;
00114              exit(1);
00115            }
00116 #endif
00117            return tt->member;
00118          }
00119          GBOOL            renumber();
00120          void             empty();
00121 //       friend ostream&  operator<<(ostream&, GLinOpList&);
00122 
00123 private:
00124 // Private methods:
00125 
00126 
00127 
00128 // Private data:
00129         GINT               nid;
00130         GINT               num;
00131         GBOOL              doRenumber;
00132         GLinOpElem         *pStart;
00133         GLinOpElem         *pCurr;
00134         GLinOpElem         *pEnd;
00135 
00136 };
00137 #endif
00138 

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