LLBC_Object *LLBC_Dictionary::Clone() const { LLBC_Dictionary *clone = new LLBC_Dictionary; // Clone object factory. if (_objFactory) { LLBC_ObjectFactory *cloneObjFactory = static_cast<LLBC_ObjectFactory *>(_objFactory->Clone()); clone->SetObjectFactory(cloneObjFactory); LLBC_SAFE_RELEASE(cloneObjFactory); } // Clone all elements. ConstIter it = this->Begin(), endIt = this->End(); for (; it != endIt; it++) { LLBC_Object *cloneObj = ((Obj *)*it)->Clone(); if (it.IsIntKey()) { clone->Insert(it.IntKey(), cloneObj); } else { clone->Insert(it.StrKey(), cloneObj); } LLBC_SAFE_RELEASE(cloneObj); } return clone; }
LLBC_Object *LLBC_Array::Clone() const { LLBC_Array *clone = new LLBC_Array; // Clone object factory. if (_objFactory) { LLBC_ObjectFactory *cloneObjFactory = static_cast<LLBC_ObjectFactory *>(_objFactory->Clone()); clone->SetObjectFactory(cloneObjFactory); LLBC_SAFE_RELEASE(cloneObjFactory); } // Clone all array elements. ConstIter it = Begin(), endIt = End(); for (; it != endIt; it++) { LLBC_Object *cloneObj = (*it)->Clone(); clone->PushBack(cloneObj); LLBC_SAFE_RELEASE(cloneObj); } return clone; }
LLBC_Dictionary::~LLBC_Dictionary() { this->Clear(); free(_bucket); LLBC_SAFE_RELEASE(_objFactory); }
LLBC_Array::~LLBC_Array() { Erase(Begin(), End()); LLBC_XFree(_objs); LLBC_SAFE_RELEASE(_objFactory); }
void LLBC_Dictionary::SetObjectFactory(LLBC_ObjectFactory *factory) { LLBC_SAFE_RELEASE(_objFactory); if ((_objFactory = factory)) { _objFactory->Retain(); } }