So I started work on a simple ArrayList, which is type safe and plays nicely with the smart pointer.
It is lacking about half of the functaionlity it should have (notably removes, and the FIFO LIFO add/remove variants.)
but it proves the concept, indeed I made bunches of pointers and passed them in and out and etc. and everything got released properly. I for one am happy to leave the delete keyword behind =)
#if !defined(ARRAYLIST_H)#define ARRAYLIST_H#include "assert.h"#include "object.h"#include "pointer.h"template <class T> class ArrayList : public Object{private: Pointer** list; unsigned int size;public: ArrayList(void) { list=0; size=0; } ~ArrayList(void) { clear(); } bool add(Pointer o) { size++; Pointer** newl=new Pointer*[size]; assert(newl); if(list) { newl=(Pointer**)memcpy(newl,list,sizeof(Pointer*)*size); delete[] list; } list=newl; Pointer* ptr=new Pointer(o); list[size-1]=ptr; return true; } bool addAll(Pointer al) { unsigned int oldsize=size; size+=al->size; Pointer** newl=new Pointer*[size]; assert(newl); if(list) { newl=(Pointer**)memcpy(newl,list,sizeof(Pointer*)*size); delete[] list; } list=newl; Pointer* ptr; for(int i=0;isize;i++) { ptr=new Pointer(al->get(i)); list[oldsize+i]=ptr; } return true; } Pointer get(unsigned int index) { assert(index < size); return *list[index]; } Pointer set(unsigned int index,Pointer o) { assert(index < size); Pointer p=get(index); *list[index]=o; return p; } void clear(void) { if(list) { Pointer** lptr=list; for(int i=0;i { delete *lptr; lptr++; } delete[] list; list=0; size=0; } }};#endif