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


Main Page   Class Hierarchy   Compound List   File List  

BucketType.h

Go to the documentation of this file.
00001 #ifndef _included_BucketType_h
00002 #define _included_BucketType_h
00003 
00009 /*
00010 *************************************************************************
00011 * If a bucket is filled completely with records, insertrec() and        *
00012 * addrec() copy the WHOLE list to a NEW bucket. The old list is deleted.*
00013 * All references to the old list become invalid during insertrec() and  *
00014 * addrec(). The data is simply copied bevore insertrec() and addrec().  *
00015 *************************************************************************
00016 */
00017 
00018 #include "DAGHParams.h"
00019 #include "SimpleBucketVoid.h"
00020 
00027 template <class Type>
00028 class Bucket : public SimpleBucketVoid
00029   {
00030    union record *cur;
00031 
00032    static inline void copytypedata(char *to, char const *from)
00033         { 
00034           memcpy((void *)to, (void *)from, sizeof(Type));
00035           //for (register int i=0;i<sizeof(Type);i++) to[i] = from[i]; 
00036         }
00037 
00038 public:
00039    inline Bucket(const unsigned bktnum)
00040         :SimpleBucketVoid(sizeof(Type),bktnum), cur(0) {}
00041 
00042    inline Bucket(void const *package)
00043         :SimpleBucketVoid((union record const *) package), cur(0) {}
00044 
00045    inline Bucket(void *package)
00046         :SimpleBucketVoid((union record *) package), cur(0) {}
00047 
00048    inline Bucket(void const *package,unsigned const size, int const n)
00049         :SimpleBucketVoid((union record const *) package, size, n), cur(0) {}
00050 
00051    inline Bucket(Bucket<Type> const &other)
00052         :SimpleBucketVoid(other), cur(0) {}
00053 
00054    inline Type* add(void)
00055         { cur = addrec(); return ( ((Type *) cur->rec.data) ); }
00056    inline Type* add(Type const &t)
00057         { 
00058           Type at(t);
00059           cur = addrec(); 
00060           copytypedata((char *) cur->rec.data, (char *) &at);
00061           return ( ((Type *) cur->rec.data) );
00062         }
00063 
00064    inline Type* insert(void)
00065         { cur = insertrec(cur); return ( ((Type *) cur->rec.data) ); }
00066    inline Type* insert(Type const &t)
00067         { 
00068           Type it(t);
00069           cur = insertrec(cur); 
00070           copytypedata((char *) cur->rec.data, (char *) &it);
00071           return ( ((Type *) cur->rec.data) );
00072         }
00073 
00074    inline Type* first(void)
00075         { 
00076          cur = headrec(); 
00077          return ( (cur != recordNULL && !cur->isempty()) ? \
00078            (Type *) cur->rec.data : (Type *) NULL );
00079         }
00080 
00081    inline Type* last(void) 
00082         { 
00083          cur = tailrec(); 
00084          return ( (cur != recordNULL && !cur->isempty()) ? \
00085            (Type *) cur->rec.data : (Type *) NULL );
00086         }
00087 
00088    inline Type* current(void) const
00089         { 
00090          return ( (cur != recordNULL && !cur->isempty()) ? \
00091            (Type *) cur->rec.data : (Type *) NULL );
00092         }
00093 
00094    Type *remove(void);
00095    Type *prev(void);
00096    Type *next(void);
00097 
00098    inline union record *currec(void)
00099         { return (cur); }
00100 
00101    inline void setcurrec(union record *c)
00102         { cur = c; }
00103 
00104    inline void empty(void)
00105         { SimpleBucketVoid::emptybkt(); cur = recordNULL; }
00106 
00107    inline void split(Bucket<Type>& bt)  {
00108          union record *r == prevrec(cur); 
00109          SimpleBucketVoid::splitbkt((SimpleBucketVoid &)bt, cur);
00110          bt.cur = recordNULL;
00111          cur = r;
00112         }
00113   };
00114 
00115 #if defined(Want_c_files) || (!defined(RS6000) && !defined(SPX))
00116 #include "BucketType.c"
00117 #endif
00118 
00119 #endif


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



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