00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #if !defined(GTBUFFER_HPP)
00013 #define GTBUFFER_HPP
00014
00015 #include "gtypes.h"
00016 #include <iostream.h>
00017 #include <stdlib.h>
00018
00019 #if !defined(GNIDBuffer )
00020 # define GNIDBuffer GBuffer<GNODEID>
00021 #endif
00022
00023 #if !defined(GIBuffer )
00024 # define GIBuffer GBuffer<GINT >
00025 #endif
00026
00027 #if !defined(GLBuffer )
00028 # define GLBuffer GBuffer<GLONG >
00029 #endif
00030
00031 #if !defined(GWBuffer )
00032 # define GWBuffer GBuffer<GWORD>
00033 #endif
00034
00035 #if !defined(GDWBuffer )
00036 # define GDWBuffer GBuffer<GDWORD>
00037 #endif
00038
00039 #if !defined(GKEYBuffer)
00040 # define GKEYBuffer GBuffer<GKEY>
00041 #endif
00042
00043 #if !defined(GSBuffer )
00044 # define GSBuffer GBuffer<GSHORT>
00045 #endif
00046
00047 #if !defined(GUIBuffer)
00048 # define GUIBuffer GBuffer<GUSHORT>
00049 #endif
00050
00051 #if !defined(GByteBuffer)
00052 # define GByteBuffer GBuffer<GBYTE>
00053 #endif
00054
00055 #if !defined(GUCharBuffer)
00056 # define GUCharBuffer GBuffer<GUCHAR>
00057 #endif
00058
00059 #if !defined(GDBuffer )
00060 # define GDBuffer GBuffer<GDOUBLE>
00061 #endif
00062
00063 #if !defined(GBTBUFFER)
00064 # define GBTBuffer GBuffer<BDYTYPE>
00065 #endif
00066
00067 #if !defined(GETBuffer )
00068 # define GETBuffer GBuffer<ELEMTYPE>
00069 #endif
00070
00071 #if !defined(GCHBuffer)
00072 # define GCHBuffer GBuffer<GCHandle>
00073 #endif
00074
00075
00076 template<class TBUFF> class GBuffer
00077 {
00078
00079
00080 private:
00081
00082
00083 void DeleteDynamic();
00084 void sift_down(const GINT l, const GINT r);
00085
00086
00087 GINT n;
00088 TBUFF *data;
00089
00090
00091 public:
00092 GBuffer();
00093 GBuffer(GINT size);
00094 GBuffer(TBUFF *buffer, GINT n);
00095 GBuffer(const GBuffer &);
00096
00097 ~GBuffer();
00098
00099
00100 void operator=(GBuffer<TBUFF> &);
00101 void operator=(TBUFF m);
00102 inline TBUFF &operator()(const GINT i) {
00103 #if defined(GARRAY_BOUNDS)
00104 if ( i >= n || i < 0 ) {
00105 cout << "GBuffer<T>::(): access error: index=" << i << "; max=" << n << endl;
00106 exit(1);
00107 }
00108 #endif
00109 return *(data+i); }
00110 inline TBUFF &operator[](const GINT i) const {
00111 #if defined(GARRAY_BOUNDS)
00112 if ( i >= n || i < 0 ) {
00113 cout << "GBuffer<T>::[]: access error: index=" << i << "; max=" << n << endl;
00114 while(1);
00115 exit(1);
00116 }
00117 #endif
00118 return *(data+i); }
00119
00120 #if 1
00121 #if defined (GBUFF_DEF_GINT )
00122 friend ostream& operator<<(ostream &, GBuffer<GINT > &);
00123 #endif
00124 #if defined (GBUFF_DEF_GLONG)
00125 friend ostream& operator<<(ostream &, GBuffer<GLONG> &);
00126 #endif
00127 #if defined (GBUFF_DEF_GDWORD)
00128 friend ostream& operator<<(ostream &, GBuffer<GDWORD> &);
00129 #endif
00130 #if defined (GBUFF_DEF_GSHORT)
00131 friend ostream& operator<<(ostream &, GBuffer<GSHORT>& );
00132 #endif
00133 #if defined (GBUFF_DEF_GUSHORT)
00134 friend ostream& operator<<(ostream &, GBuffer<GUSHORT>& );
00135 #endif
00136 #if defined (GBUFF_DEF_BYTE)
00137 friend ostream& operator<<(ostream &, GBuffer<GBYTE> &);
00138 #endif
00139 #if defined (GBUFF_DEF_GDOUBLE)
00140 friend ostream& operator<<(ostream &, GBuffer<GDOUBLE>& );
00141 #endif
00142 #if defined (GBUFF_DEF_BDYTYPE)
00143 friend ostream& operator<<(ostream &, GBuffer<BDYTYPE>& );
00144 #endif
00145 #if defined (GBUFF_DEF_ELEMTYPE)
00146 friend ostream& operator<<(ostream &, GBuffer<ELEMTYPE>& );
00147 #endif
00148 #if defined (GBUFF_DEF_GKEY)
00149 friend ostream& operator<<(ostream &, GBuffer<GKEY>& );
00150 #endif
00151 #if defined (GBUFF_DEF_GNODEID)
00152 friend ostream& operator<<(ostream &, GBuffer<GNODEID>& );
00153 #endif
00154 #if defined (GBUFF_DEF_GCHANDLE)
00155 friend ostream& operator<<(ostream &, GBuffer<GCHandle>& );
00156 #endif
00157 #else
00158 friend ostream& operator<<(ostream &s, const GBuffer<TBUFF> &v);
00159 #endif
00160
00161
00162
00163 GINT dim() const ;
00164 TBUFF *Data();
00165 GBOOL Resize(GINT order);
00166 GBOOL contains(TBUFF imember, GINT &index, TBUFF floor);
00167 GBOOL contains(TBUFF imember, GINT istart, GINT num, GINT &index, TBUFF floor);
00168 GBOOL contains(GWORD imember, GINT &index, GINT ihilo, TBUFF floor);
00169 GBOOL contains(TBUFF imember, GINT &index);
00170 GBOOL distinct(GINT *&index, GINT &n_distinct, TBUFF floor=-1);
00171 void Set(const TBUFF);
00172 void GetSection(GBuffer<TBUFF> §ion, GINT *ilist, GINT nlist);
00173 GBuffer<TBUFF> &GetSection(GINT *ilist, GINT nlist);
00174 void sortlohi();
00175 void sortincreasing();
00176 void sortdecreasing();
00177
00178
00179 };
00180 #if defined(_LINUX) || defined(_AIX)
00181 template class GBuffer<GDOUBLE>;
00182 ostream &operator <<(ostream&, const GBuffer<GDOUBLE>&);
00183 #if defined(GBUFF_DEF_GINT )
00184 template class GBuffer<GINT >;
00185 ostream &operator <<(ostream&, const GBuffer<GINT >&);
00186 #endif
00187 #if defined(GBUFF_DEF_GLONG )
00188 template class GBuffer<GLONG >;
00189 ostream &operator <<(ostream&, const GBuffer<GLONG>&);
00190 #endif
00191 #if defined(GBUFF_DEF_GDWORD)
00192 template class GBuffer<GDWORD>;
00193 ostream &operator <<(ostream&, const GBuffer<GDWORD>&);
00194 #endif
00195 #if defined(GBUFF_DEF_GKEY)
00196 template class GBuffer<GKEY>;
00197 ostream &operator <<(ostream&, const GBuffer<GKEY>&);
00198 #endif
00199 #if defined(GBUFF_DEF_GSHORT)
00200 template class GBuffer<GSHORT>;
00201 ostream &operator <<(ostream&, const GBuffer<GSHORT>&);
00202 #endif
00203 #if defined(GBUFF_DEF_GUSHORT)
00204 template class GBuffer<GUSHORT>;
00205 ostream &operator <<(ostream&, const GBuffer<GUSHORT>&);
00206 #endif
00207 #if defined (GBUFF_DEF_GSHORT)
00208 template class GBuffer<GBYTE>;
00209 ostream &operator <<(ostream&, const GBuffer<GBYTE>&);
00210 #endif
00211 #if defined (GBUFF_DEF_BDYTYPE)
00212 template class GBuffer<BDYTYPE>;
00213 ostream &operator <<(ostream&, const GBuffer<BDYTYPE>&);
00214 #endif
00215 #if defined (GBUFF_DEF_ELEMTYPE)
00216 template class GBuffer<ELEMTYPE>;
00217 ostream &operator <<(ostream&, const GBuffer<ELEMTYPE>&);
00218 #endif
00219 #if defined (GBUFF_DEF_GCHANDLE)
00220 template class GBuffer<GCHandle>;
00221 ostream &operator <<(ostream&, const GBuffer<GCHandle>&);
00222 #endif
00223 #if defined (GBUFF_DEF_UCHAR)
00224 template class GBuffer<GUCHAR>;
00225 ostream &operator <<(ostream&, const GBuffer<GUCHAR>&);
00226 #endif
00227 #if defined (GBUFF_DEF_GNODEID)
00228 template class GBuffer<GNODEID>;
00229 ostream &operator <<(ostream&, const GBuffer<GNODEID>&);
00230 #endif
00231 #endif
00232 #endif