00001
00002 #define CHECKTRUE(expr) {if((expr) == true) return false;}
00003
00004 template<typename T, uint SIZE>
00005 Static<T,SIZE>::Static(){
00006 clear();
00007 }
00008
00009 template<typename T, uint SIZE>
00010 Static<T,SIZE>::Static(uint num, ...){
00011 assert(num <= SIZE);
00012 T* in = (T*)(((char*)&num)+sizeof(uint));
00013 for(uint i=0; i<num; i++)
00014 array[i] = in[i];
00015 last = num;
00016 }
00017
00018 template<typename T, uint SIZE>
00019 Static<T,SIZE>::~Static(void){
00020 clear();
00021 }
00022
00023 template<typename T, uint SIZE>
00024 uint Static<T,SIZE>::size(void){
00025 return last;
00026 }
00027
00028 template<typename T, uint SIZE>
00029 uint Static<T,SIZE>::length(void){
00030 return SIZE;
00031 }
00032
00033 template<typename T, uint SIZE>
00034 bool Static<T,SIZE>::has(T data, uint* out){
00035 for(uint i=0; i<size(); i++)
00036 if(array[i] == data){
00037 if(out) *out=i;
00038 return true;
00039 }
00040 return false;
00041 }
00042
00043 template<typename T, uint SIZE>
00044 T Static<T,SIZE>::get(uint index){
00045 assert(index < SIZE);
00046 return array[index];
00047 }
00048
00049 template<typename T, uint SIZE>
00050 T& Static<T,SIZE>::getRef(uint index){
00051 assert(index < SIZE);
00052 return array[index];
00053 }
00054
00055 template<typename T, uint SIZE>
00056 void Static<T,SIZE>::set(uint index, T data){
00057 if(SIZE <= index) return;
00058 array[index] = data;
00059 }
00060
00061 template<typename T, uint SIZE>
00062 bool Static<T,SIZE>::add(T data){
00063 if(SIZE <= last) return false;
00064 array[last++] = data;
00065 return true;
00066 }
00067
00068 template<typename T, uint SIZE>
00069 bool Static<T,SIZE>::insert(uint index, T data){
00070 if(SIZE <= last || SIZE <= index) return false;
00071 for(uint i=last; index<i; i--)
00072 array[i] = array[i-1];
00073 array[index] = data;
00074 last++;
00075 return true;
00076 }
00077
00078 template<typename T, uint SIZE>
00079 bool Static<T,SIZE>::replace(T oldItem, T newItem){
00080 for(uint i = 0; i < last; i++)
00081 if(array[i] == oldItem)
00082 return array[i] = newItem, true;
00083 return false;
00084 }
00085
00086 template<typename T, uint SIZE>
00087 bool Static<T,SIZE>::replaceIndex(uint index, T newItem){
00088 if(index < last)
00089 return array[index] = newItem, true;
00090 return false;
00091 }
00092
00093 template<typename T, uint SIZE>
00094 void Static<T,SIZE>::remove(T data){
00095 for(uint i = 0; i < last; i++)
00096 if(array[i] == data){
00097 removeIndex(i);
00098 break;
00099 }
00100 }
00101
00102 template<typename T, uint SIZE>
00103 void Static<T,SIZE>::removeIndex(uint index){
00104 assert(index < last);
00105 for(--last; index<last; index++)
00106 array[index] = array[index+1];
00107 memset(&array[last], 0, sizeof(T));
00108 }
00109
00110 template<typename T, uint SIZE>
00111 void Static<T,SIZE>::clear(void){
00112
00113
00114 last = 0;
00115 }
00116
00117 template<typename T, uint SIZE>
00118 T& Static<T,SIZE>::operator [] (uint index){
00119 assert(index < SIZE);
00120 return array[index];
00121 }
00122
00123 template<typename T, uint SIZE>
00124 const T Static<T,SIZE>::operator [] (uint index) const{
00125 assert(index < SIZE);
00126 return array[index];
00127 }
00128
00129 #undef CHECKTRUE