LSObjectCollection
Jump to navigation
Jump to search
Just storing this example for later.
Example
class Foo { public: Foo() { } ~Foo() { } char Name[64]; }; class FooType : public LSTypeDefinition { public: // yadda yadda, all the type stuff goes here, but here's the FreeVariable example. this gets called // for each object in the collection when it needs to be destroyed void FreeVariable(LSOBJECTDATA &ObjectData) { Foo *pPtr=(Foo *)ObjectData.Ptr; delete pPtr; } }; LSObjectCollection MyCollection(pFooType,0);// our collection will store Foos, which does not use sub-types so we 0 it void FooBar() { // we have some instance of Foo. if we allocate it, then we need to be allocating all of them. // if we dont, then we need to not be allocating all of them. doesnt matter as long as our pFooType code // handles deallocation if needed Foo *pFoo=new Foo; // convert the pointer to LSOBJECTDATA, which can either be done with a funky typecast or using its union LSOBJECTDATA ObjectData; ObjectData.Ptr=pFoo; // use MyCollection.SetItem MyCollection.SetItem(pFoo->Name,ObjectData); }