00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef ARRAY_H
00017 #define ARRAY_H
00018
00019 #ifndef USE_PCH
00020 #include <vector>
00021 #include "debug.h"
00022 #endif
00023
00024 #include "Index.h"
00025
00026
00027
00028 template<typename T>
00029 class Array {
00030 private:
00031 std::vector<T> M_array;
00032 int M_access_count;
00033
00034 public:
00035 Array(void) : M_array(1U), M_access_count(0) { }
00036 std::vector<T> const& vec(void) const { return M_array; }
00037
00038 template<typename INDEX_POOL_TYPE>
00039 T& operator[](Index<INDEX_POOL_TYPE> const& index)
00040 {
00041 unsigned int i = index.index();
00042 if (++M_access_count == 0x40 || i >= M_array.size())
00043 {
00044 M_access_count &= 0x3f;
00045 resize(index);
00046 }
00047 return M_array[i];
00048 }
00049 template<typename INDEX_POOL_TYPE>
00050 T const& operator[](Index<INDEX_POOL_TYPE> const& index) const
00051 {
00052 unsigned int i = index.index();
00053 ASSERT(i < M_array.size());
00054 return M_array[i];
00055 }
00056
00057 private:
00058 template<typename INDEX_POOL_TYPE>
00059 void resize(Index<INDEX_POOL_TYPE> const& index);
00060 };
00061
00062 template<typename T>
00063 template<typename INDEX_POOL_TYPE>
00064 void Array<T>::resize(Index<INDEX_POOL_TYPE> const& index)
00065 {
00066 unsigned int i = index.index();
00067 if (i < M_array.size())
00068 {
00069 int size = index.size();
00070 M_array.resize(size);
00071 std::vector<T>(M_array).swap(M_array);
00072 }
00073 else
00074 {
00075 int size = i + 1;
00076 M_array.reserve(size);
00077 M_array.resize(size);
00078 }
00079 }
00080
00081 #endif // ARRAY_H