00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #if !defined(GFIELDLIST_HPP)
00014 #define GFIELDLIST_HPP
00015
00016 #include "gtypes.h"
00017 #include "field2d.hpp"
00018 #include <iostream.h>
00019 #include <stdlib.h>
00020
00021 #if !defined(GFIELDLIST_MEM)
00022 #define GFIELDLIST_MEM
00023 struct FieldListSt {
00024 GINT id;
00025 GBOOL cf;
00026 Field2D *member;
00027 FieldListSt *next;
00028 FieldListSt *prev;
00029 };
00030 #endif
00031
00032
00033
00034 class GFieldList
00035 {
00036
00037 public:
00038 GFieldList(GBOOL renumber_on_delete=FALSE);
00039 GFieldList(const GFieldList &);
00040 ~GFieldList();
00041
00042 void operator=(const GDOUBLE a);
00043 void operator=(GFieldList &v);
00044 void SetTimeLevel(GINT ilevel);
00045
00046 void add(const GINT NTimeLevels, Elem2D *e, GSHORT ntmp=2);
00047 void add(Field2D *c);
00048 Field2D *del(FieldListSt *c);
00049 Field2D *del(Field2D *c);
00050 Field2D *del(Elem2D *e);
00051 Field2D *del(GINT id);
00052 inline void start(FieldListSt *p=NULL) {
00053 pCurr = ( p!=NULL ? p : pStart );
00054 }
00055 GINT size() const;
00056 inline Field2D *member() {
00057 return pCurr ? pCurr->member : NULL;
00058 }
00059 inline Field2D *member(GINT id) {
00060 FieldListSt *e;
00061 if ( (e=find(id)) == NULL ) return NULL;
00062 return e->member;
00063 }
00064 inline FieldListSt *next() {
00065 FieldListSt *p = pCurr ? pCurr->next : NULL;
00066 pCurr = p; return pCurr;
00067 }
00068 FieldListSt *curr();
00069 inline FieldListSt *find(GINT id) { FieldListSt *p=pCurr;
00070 if ( p && p->id == id ) return p;
00071 else if ( p && p->next && p->next->id == id ) {
00072 next(); return p->next; }
00073 start(NULL);
00074 while ( (p=curr()) != NULL ) {
00075 if ( p->id == id ) return p; next(); }
00076 return NULL; }
00077 inline FieldListSt *find(Field2D *f) { FieldListSt *p=pCurr;
00078 if ( p && p->member == f ) return p;
00079 else if ( p && p->next && p->next->member == f ) {
00080 next(); return p->next; }
00081 start(NULL);
00082 while ( (p=curr()) != NULL ) {
00083 if ( p->member == f ) return p; next(); }
00084 return NULL; }
00085 FieldListSt *find(Elem2D *);
00086 GDOUBLE &operator()(const GSHORT nLevel, const GINT iElem, const GINT i);
00087 GDOUBLE &operator()(const GINT iElem, const GINT i);
00088 GVector *X (const GINT iElem, const GSHORT idir);
00089 GDOUBLE &X (const GINT iElem, const GSHORT idir, const GINT i);
00090 GINT dim(const GINT iElem, const GSHORT idir);
00091 GBOOL renumber();
00092 void empty();
00093 inline Field2D *&operator()(const GINT iElem) {
00094 FieldListSt *tt;
00095 #if !defined(GLIST_BOUNDS)
00096 tt=find(iElem);
00097 #else
00098 if ( (tt=find(iElem)) == NULL ) {
00099 cout << "GFieldList::operator(): Cannot access element " << iElem << endl;
00100 exit(1);
00101 }
00102 #endif
00103 return tt->member ;
00104 }
00105 inline Field2D *&operator[](const GINT iElem) {
00106 FieldListSt *tt;
00107 #if !defined(GLIST_BOUNDS)
00108 tt=find(iElem);
00109 #else
00110 if ( (tt=find(iElem)) == NULL ) {
00111 cout << "GFieldList::operator[]: Cannot access element " << iElem << endl;
00112 exit(1);
00113 }
00114 #endif
00115 return tt->member ;
00116 }
00117 friend ostream& operator<<(ostream&, GFieldList &);
00118
00119 private:
00120
00121
00122
00123 GINT nid;
00124 GINT num;
00125 GINT iLevel_;
00126 GBOOL doRenumber;
00127 FieldListSt *pStart;
00128 FieldListSt *pCurr;
00129 FieldListSt *pEnd;
00130
00131 };
00132 #endif
00133