00001 00041 #ifndef _ARRAYLIST_H 00042 #define _ARRAYLIST_H 00043 00044 #include "list.h" 00045 00046 using std::ostream; 00047 00048 namespace container { 00049 00058 class ArrayList: public virtual List { 00059 public: 00060 00061 const static Info* const TYPE_INFO; 00062 00063 protected: 00064 00065 const static int DEFAULT_INITIAL_CAPACITY; 00066 const static int DEFAULT_ADDITIONAL_CAPACITY; 00067 const static int BASE_INDEX; 00068 00073 int capacity; 00074 00079 int additionalCapacity; 00080 00084 Entity ** array; 00085 00091 int current; 00092 00099 ArrayList(); 00100 00107 ArrayList(int initialCapacity, int additionalCapacity); 00108 00120 ArrayList(const ArrayList& pattern); 00121 00135 ArrayList(const ArrayList& pattern, bool deepCopy); 00136 00137 private: 00138 00142 void copyConstructor(const ArrayList& pattern, bool deepCopy = false); 00143 00144 public: 00145 00151 virtual ~ArrayList(); 00152 00153 protected: 00154 00155 /********************* ArrayList Methods (protected) *********************/ 00156 00157 void allocateArray(); 00158 00163 void closeGap(); 00164 00169 void closeGap(int index); 00170 00175 void openGap(int index); 00176 00177 bool isAtCapacity() const; 00178 00179 public: 00180 00181 /********************* List Methods (public) *********************/ 00182 00183 virtual bool isFirst() const; 00184 00185 virtual bool isLast() const; 00186 00187 virtual bool isTail() const; 00188 00189 virtual bool toFirst(); 00190 00191 virtual bool toLast(); 00192 00193 virtual void toTail(); 00194 00195 virtual bool toNext(); 00196 00197 virtual bool toPrev(); 00198 00199 virtual Entity * currentEntity(); 00200 00201 virtual void locateEntity(const Entity &key, int &index, Entity* &entity); 00202 00203 virtual Entity* entityAt(int index); 00204 00205 protected: 00206 00207 /********************* List Methods (protected) *********************/ 00208 00209 virtual bool deleteCurrent_impl(); 00210 00211 virtual Entity * extractCurrentEntity_impl(); 00212 00213 public: 00214 00215 /********************* Object Methods (public) *********************/ 00216 00217 virtual ostream& renderState(ostream& os) const; 00218 00219 virtual const Info* typeInfo() const; 00220 00221 virtual Object* clone(bool deepCopy = false) const = 0; 00222 00223 }; 00224 00225 } // namespace container 00226 #endif /* _ARRAYLIST_H */