Array
The OriginC Array class is a collection of nearly all data types and objects. If Array::IsOwner is TRUE, the array to be owner of the objects memory, the objects will be deleted by the array on resize or during destruction.
EX1
#include <Array.h> class TestBase { public: TestBase() { //printf("TestBase Constructor\n"); } ~TestBase() { //printf("TestBase Destructor\n"); } virtual void DoSomething() { out_str("Base class DoSomething, it should not come here if derived class had this implemented"); } protected: string m_strName; }; class TestA : public TestBase { public: TestA(int n){ m_strName.Format("Class TestA (%d)", n); printf("constructor %s\n", m_strName); } ~TestA(){ printf("Deconstructor %s\n", m_strName); } //virtual void DoSomething(){ printf("%s:Doing my Class A thing.\n", m_strName);} }; class TestB : public TestBase { public: TestB(int n){ m_strName.Format("Class TestB (%d)", n); printf("constructor %s\n", m_strName); } ~TestB(){ printf("Deconstructor %s\n", m_strName); } //virtual void DoSomething(){ printf("%s:Doing my Class B thing.\n", m_strName);} }; void ttt() { Array<TestBase&> myList; myList.SetAsOwner(true);// we don't have to explicitely delete if we tell the Array to own these pointers for(int ii = 0; ii < 10; ii++) { TestBase* pMyClass; if(rnd() > 0.5) pMyClass = new TestA(ii); else pMyClass = new TestB(ii); myList.Add(*pMyClass); } for(int jj = 0; jj < myList.GetSize(); jj++) { TestBase& MyClass = myList.GetAt(jj); MyClass.DoSomething(); } }
Array.h