00001
00002 #include <assert.h>
00003 #include <stdio.h>
00004
00029
00030
00161 template<class T>
00162 class base {
00163 private:
00164 enum { INITIAL_SIZE = 20 } bogosity;
00165 static int size;
00166
00167 protected:
00168 static T* table;
00169 static int ix;
00170
00171 public:
00172 base() {}
00173 ~base() {};
00174 void addElem(T elem);
00175 void addTable(T* table, int len);
00176
00177 virtual void insertElem( T elem ) = 0;
00178 virtual void pr() = 0;
00179 };
00180
00181
00186 template<class T> T* base<T>::table = 0;
00187 template<class T> int base<T>::ix = 0;
00188 template<class T> int base<T>::size = 0;
00189
00190
00191 template<class T> void
00192 base<T>::addElem(T elem) {
00193 if (ix == size) {
00194 int NewSize;
00195 if (size == 0)
00196 NewSize = INITIAL_SIZE;
00197 else
00198 NewSize = size * 2;
00199 T* old_table = table;
00200 table = new T [ NewSize ];
00201 assert( table != 0 );
00202 ix = 0;
00203 for (int i = 0; i < size; i++) {
00204 insertElem( old_table[i] );
00205 ix++;
00206 }
00207 if (old_table != 0) {
00208 delete [] old_table;
00209 }
00210 size = NewSize;
00211 }
00212 insertElem( elem );
00213 ix++;
00214 }
00215
00216
00217 template<class T> void
00218 base<T>::addTable(T* tbl, int len)
00219 {
00220 if (tbl != 0 && len > 0) {
00221 for (int i = 0; i < len; i++) {
00222 addElem( tbl[i] );
00223 }
00224 }
00225 }
00226
00227
00228
00229
00230 class StringTable : public base< char *> {
00231 public:
00232 StringTable() {}
00233 void insertElem( char * str );
00234 void pr();
00235 };
00236
00237
00238 class IntTable : public base< int >
00239 {
00240 public:
00241 IntTable();
00242 void insertElem( int i );
00243 void pr();
00244 };
00245