00001 #ifndef ARRAY_CLASS
00002 #define ARRAY_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "guards.h"
00019
00021
00043 template <class contents>
00044 class array
00045 {
00046 public:
00048 enum special_flags {
00049 NO_SPECIAL_MODES = 0x0,
00050 SIMPLE_COPY = 0x1,
00051 EXPONENTIAL_GROWTH = 0x2,
00052 EXPONE = EXPONENTIAL_GROWTH,
00053 FLUSH_INVISIBLE = 0x4
00054 };
00055
00056 array(int number = 0, const contents *init = NIL,
00057 u_short flags = EXPONENTIAL_GROWTH | FLUSH_INVISIBLE);
00059
00074 array(const array<contents> ©_from);
00076
00077 ~array();
00078
00079 void reset(int number = 0, const contents *initial_contents = NIL);
00081
00082
00083
00084
00085
00086
00087
00088
00089 array &operator = (const array<contents> ©_from);
00091
00092 inline int length() const { return _active_length; }
00094
00095 inline int last() const { return _active_length - 1; }
00097
00098 inline u_short flags() const { return _flags; }
00100
00101 inline bool exponential() const { return _flags & EXPONENTIAL_GROWTH; }
00103
00104 inline bool simple() const { return _flags & SIMPLE_COPY; }
00106
00107 const contents &get(int index) const;
00109
00111 contents &use(int index);
00113
00114 inline const contents &operator [] (int index) const { return get(index); }
00116 inline contents &operator [] (int index) { return use(index); }
00118
00119 outcome put(int index, const contents &to_put);
00121
00123 array concatenation(const array &to_concatenate) const;
00125 array concatenation(const contents &to_concatenate) const;
00127
00128 array &concatenate(const array &to_concatenate);
00130 array &concatenate(const contents &to_concatenate);
00132 array &concatenate(const contents *to_concatenate, int length);
00134
00136 inline array operator + (const array &to_cat) const
00137 { return concatenation(to_cat); }
00139 inline array operator + (const contents &to_concatenate) const
00140 { return concatenation(to_concatenate); }
00142 inline array &operator += (const array &to_concatenate)
00143 { return concatenate(to_concatenate); }
00145 inline array &operator += (const contents &to_concatenate)
00146 { return concatenate(to_concatenate); }
00148
00149 inline const contents *observe() const { return _offset; }
00151
00153 inline contents *access() { return _offset; }
00155
00156 void swap_contents(array<contents> &other);
00158
00161 void snarf(array &new_contents);
00163
00166 array subarray(int start, int end) const;
00168
00172 outcome insert(int index, int new_indices);
00174
00175 outcome overwrite(int index, const array &write_with, int count = -1);
00177
00183 outcome stuff(int length, contents *to_stuff) const;
00185
00188 outcome resize(int new_size, common::how_to_copy way = common::NEW_AT_END);
00190
00201 outcome zap(int start, int end);
00203
00207 outcome shrink();
00209
00210 outcome retrain(int new_size, const contents *to_copy);
00212
00213 enum shift_directions { TO_LEFT, TO_RIGHT };
00215
00216 void shift_data(shift_directions where);
00218
00221
00222
00223 inline int internal_real_length() const { return _real_length; }
00225 inline int internal_offset() const { return int(_offset - _mem_block); }
00227 inline const contents *internal_block_start() const { return _mem_block; }
00229 inline contents *internal_block_start() { return _mem_block; }
00231 inline contents * const *internal_offset_mem() const { return &_offset; }
00233
00234 private:
00235 int _active_length;
00236 int _real_length;
00237 contents *_mem_block;
00238 contents *_offset;
00239 u_short _flags;
00240
00241 outcome allocator_reset(int initial_elements, int blocking);
00243
00246 };
00247
00249 class int_array : public array<int>
00250 {
00251 public:
00252 int_array(int number = 0, const int *initial_contents = 0)
00253 : array<int>(number, initial_contents, SIMPLE_COPY | EXPONE) {}
00255
00258 };
00259
00261 class double_array : public array<double>
00262 {
00263 public:
00264 double_array(int len = 0, double *data = NIL)
00265 : array<double>(len, data, SIMPLE_COPY | EXPONE) {}
00266 double_array(const array<double> &to_copy) : array<double>(to_copy) {}
00267 };
00268
00269 #endif
00270