// Utility to release all old OMObjects from the given container. AAFRESULT ImplAAFRefContainerValue::ReleaseAllObjects(OMReferenceContainer *pContainerProperty) { ASSERTU(pContainerProperty && usesReferenceCounting()); OMReferenceContainerIterator* containerIter = pContainerProperty->createIterator(); if (NULL == containerIter) return AAFRESULT_NOMEMORY; AAFRESULT result = AAFRESULT_SUCCESS; while (AAFRESULT_SUCCEEDED(result) && (containerIter->before() || containerIter->valid())) { if (++(*containerIter)) { OMObject *object = containerIter->currentObject(); ImplAAFStorable *obj = dynamic_cast<ImplAAFStorable*>(object); ASSERTU(NULL != obj); if (NULL == obj) { result = AAFRESULT_INVALID_OBJ; } else { obj->ReleaseReference(); } } } delete containerIter; containerIter = NULL; return AAFRESULT_SUCCESS; }
// Set the value of the OMObjectVector at position index to pObject. AAFRESULT STDMETHODCALLTYPE ImplAAFRefArrayValue::SetObjectAt( ImplAAFStorable* pObject, aafUInt32 index) { AAFRESULT result = AAFRESULT_SUCCESS; if (NULL == pObject) return AAFRESULT_NULL_PARAM; ImplAAFStorable* newStorable = ImplAAFRefValue::ConvertRootToOMStorable(pObject); ASSERTU(NULL != newStorable); if (NULL == newStorable) return AAFRESULT_INVALID_OBJ; // Validate the index... OMObjectVector * pReferenceVector = referenceVector(); ASSERTU (NULL != pReferenceVector); aafUInt32 elementCount = pReferenceVector->count(); if (index >= elementCount) return AAFRESULT_BADINDEX; OMObject *oldStorable = pReferenceVector->setObjectAt(newStorable, index); if (usesReferenceCounting()) { newStorable->AcquireReference(); if (oldStorable) ReleaseOldObject(oldStorable); } return result; }
void ImplAAFRefContainerValue::ReleaseOldObject(OMObject *object) { ASSERTU(object && usesReferenceCounting()); ImplAAFStorable *pOldObject = ImplAAFRefValue::ConvertOMObjectToRoot(object); ASSERTU(NULL != pOldObject); if (NULL == pOldObject) throw AAFRESULT_INVALID_OBJ; // ??? pOldObject->ReleaseReference(); }
// // WriteTo // AAFRESULT STDMETHODCALLTYPE ImplAAFRefArrayValue::WriteTo( OMProperty* pOmProp) { AAFRESULT result = AAFRESULT_SUCCESS; OMObject* object; ImplAAFStorable* obj; if (NULL == property()) { // First empty the current property. OMContainerProperty * pNewContainerProperty = dynamic_cast<OMContainerProperty *>(pOmProp); if (NULL == pNewContainerProperty) return AAFRESULT_INVALID_OBJ; OMReferenceContainer *pNewReferenceContainer = pNewContainerProperty->referenceContainer(); if (NULL == pNewReferenceContainer) return AAFRESULT_INVALID_OBJ; if (usesReferenceCounting()) { result = ReleaseAllObjects(pNewReferenceContainer); if (AAFRESULT_FAILED(result)) return result; } // Make sure that there are no elements in the new property container. pNewReferenceContainer->removeAllObjects(); // Install the new "empty" container property. SetProperty(pOmProp); OMReferenceContainerIterator* tempIterator = _tempStorableVector->createIterator(); if (NULL == tempIterator) { result = AAFRESULT_NOMEMORY; } else { while (AAFRESULT_SUCCEEDED(result) && (tempIterator->before() || tempIterator->valid())) { if (++(*tempIterator)) { object = tempIterator->currentObject(); obj = dynamic_cast<ImplAAFStorable*>(object); ASSERTU(NULL != obj); if (NULL == obj) { result = AAFRESULT_INVALID_OBJ; } else { // if (usesReferenceCounting()) // { // obj->detach(); // } // Add the element from the temporary property container to the property. result = InsertObject(obj); // reference counts if necessary... if (AAFRESULT_SUCCEEDED(result)) { if (usesReferenceCounting()) { obj->ReleaseReference(); } } } } } delete tempIterator; tempIterator = NULL; } // Cleanup the temporary property now the the the pOmProp has been created and initialized. delete _tempStorableVector; _tempStorableVector = NULL; if (AAFRESULT_FAILED(result)) return result; } return (ImplAAFRefContainerValue::WriteTo(pOmProp)); }