00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(GTBUFFER_HPP)
00012 #define GTBUFFER_HPP
00013
00014 #include "gtypes.h"
00015 #include <iostream.h>
00016 #include <stdlib.h>
00017
00018 #if !defined(GNIDBuffer )
00019 # define GNIDBuffer GBuffer<GNODEID>
00020 #endif
00021
00022 #if !defined(GIBuffer )
00023 # define GIBuffer GBuffer<GINT >
00024 #endif
00025
00026 #if !defined(GLBuffer )
00027 # define GLBuffer GBuffer<GLONG >
00028 #endif
00029
00030 #if !defined(GWBuffer )
00031 # define GWBuffer GBuffer<GWORD>
00032 #endif
00033
00034 #if !defined(GDWBuffer )
00035 # define GDWBuffer GBuffer<GDWORD>
00036 #endif
00037
00038 #if !defined(GKEYBuffer)
00039 # define GKEYBuffer GBuffer<GKEY>
00040 #endif
00041
00042 #if !defined(GSBuffer )
00043 # define GSBuffer GBuffer<GSHORT>
00044 #endif
00045
00046 #if !defined(GUIBuffer)
00047 # define GUIBuffer GBuffer<GUSHORT>
00048 #endif
00049
00050 #if !defined(GByteBuffer)
00051 # define GByteBuffer GBuffer<GBYTE>
00052 #endif
00053
00054 #if !defined(GUCharBuffer)
00055 # define GUCharBuffer GBuffer<GUCHAR>
00056 #endif
00057
00058 #if !defined(GDBuffer )
00059 # define GDBuffer GBuffer<GDOUBLE>
00060 #endif
00061
00062 #if !defined(GBTBUFFER)
00063 # define GBTBuffer GBuffer<BDYTYPE>
00064 #endif
00065
00066 #if !defined(GETBuffer )
00067 # define GETBuffer GBuffer<ELEMTYPE>
00068 #endif
00069
00070 #if !defined(GCHBuffer)
00071 # define GCHBuffer GBuffer<GCHandle>
00072 #endif
00073
00074
00075 template<class TBUFF> class GBuffer
00076 {
00077
00078
00079 private:
00080
00081
00082 void DeleteDynamic();
00083 void sift_down(const GINT l, const GINT r);
00084
00085
00086 GINT n;
00087 GINT *itmp;
00088 TBUFF *data;
00089 TBUFF *tunique;
00090
00091
00092 public:
00093 GBuffer();
00094 GBuffer(GINT size);
00095 GBuffer(TBUFF *buffer, GINT n);
00096 GBuffer(const GBuffer &);
00097
00098 ~GBuffer();
00099
00100
00101 void operator=(GBuffer<TBUFF> &);
00102 void operator=(TBUFF m);
00103 inline TBUFF &operator()(const GINT i) {
00104 #if defined(GARRAY_BOUNDS)
00105 if ( i >= n || i < 0 ) {
00106 cout << "GBuffer<T>::(): access error: index=" << i << "; max=" << n << endl;
00107 exit(1);
00108 }
00109 #endif
00110 return *(data+i); }
00111 inline TBUFF &operator[](const GINT i) const {
00112 #if defined(GARRAY_BOUNDS)
00113 if ( i >= n || i < 0 ) {
00114 cout << "GBuffer<T>::[]: access error: index=" << i << "; max=" << n << endl;
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);
00171 GBOOL distinct(GINT *&index, GINT &n_distinct);
00172 void Set(const TBUFF);
00173 void GetSection(GBuffer<TBUFF> §ion, GINT *ilist, GINT nlist);
00174 GBuffer<TBUFF> &GetSection(GINT *ilist, GINT nlist);
00175 void sortlohi();
00176 void sortincreasing();
00177 void sortdecreasing();
00178
00179
00180 };
00181 #if defined(_LINUX) || defined(_AIX)
00182 template class GBuffer<GDOUBLE>;
00183 ostream &operator <<(ostream&, const GBuffer<GDOUBLE>&);
00184 #if defined(GBUFF_DEF_GINT )
00185 template class GBuffer<GINT >;
00186 ostream &operator <<(ostream&, const GBuffer<GINT >&);
00187 #endif
00188 #if defined(GBUFF_DEF_GLONG )
00189 template class GBuffer<GLONG >;
00190 ostream &operator <<(ostream&, const GBuffer<GLONG>&);
00191 #endif
00192 #if defined(GBUFF_DEF_GDWORD)
00193 template class GBuffer<GDWORD>;
00194 ostream &operator <<(ostream&, const GBuffer<GDWORD>&);
00195 #endif
00196 #if defined(GBUFF_DEF_GKEY)
00197 template class GBuffer<GKEY>;
00198 ostream &operator <<(ostream&, const GBuffer<GKEY>&);
00199 #endif
00200 #if defined(GBUFF_DEF_GSHORT)
00201 template class GBuffer<GSHORT>;
00202 ostream &operator <<(ostream&, const GBuffer<GSHORT>&);
00203 #endif
00204 #if defined(GBUFF_DEF_GUSHORT)
00205 template class GBuffer<GUSHORT>;
00206 ostream &operator <<(ostream&, const GBuffer<GUSHORT>&);
00207 #endif
00208 #if defined (GBUFF_DEF_GSHORT)
00209 template class GBuffer<GBYTE>;
00210 ostream &operator <<(ostream&, const GBuffer<GBYTE>&);
00211 #endif
00212 #if defined (GBUFF_DEF_BDYTYPE)
00213 template class GBuffer<BDYTYPE>;
00214 ostream &operator <<(ostream&, const GBuffer<BDYTYPE>&);
00215 #endif
00216 #if defined (GBUFF_DEF_ELEMTYPE)
00217 template class GBuffer<ELEMTYPE>;
00218 ostream &operator <<(ostream&, const GBuffer<ELEMTYPE>&);
00219 #endif
00220 #if defined (GBUFF_DEF_GCHANDLE)
00221 template class GBuffer<GCHandle>;
00222 ostream &operator <<(ostream&, const GBuffer<GCHandle>&);
00223 #endif
00224 #if defined (GBUFF_DEF_UCHAR)
00225 template class GBuffer<GUCHAR>;
00226 ostream &operator <<(ostream&, const GBuffer<GUCHAR>&);
00227 #endif
00228 #if defined (GBUFF_DEF_GNODEID)
00229 template class GBuffer<GNODEID>;
00230 ostream &operator <<(ostream&, const GBuffer<GNODEID>&);
00231 #endif
00232 #endif
00233 #endif