AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::CreateValue(ImplAAFPropertyValue ** ppPropVal, aafUInt32 dataSize) { if (! ppPropVal) return AAFRESULT_NULL_PARAM; ImplAAFPropValDataSP pvd; ImplAAFPropValData * tmp; tmp = (ImplAAFPropValData*) CreateImpl (CLSID_AAFPropValData); if (!tmp) return AAFRESULT_NOMEMORY; pvd = tmp; // the pvd smart pointer will maintain a reference for us... tmp->ReleaseReference (); //Initialize pvd to this type HRESULT hr = pvd->Initialize(this); if (AAFRESULT_FAILED(hr)) return hr; //deal with dataSize - Allocate bits if this param is non-zero if (dataSize) { //Allocate the necesary bits aafMemPtr_t pTargetData = 0; hr = pvd->AllocateBits(dataSize, &pTargetData); if (AAFRESULT_FAILED (hr)) return hr; }//if dataSize else //we're effectively creating an "Empty" value ; *ppPropVal = pvd; ASSERTU (*ppPropVal); (*ppPropVal)->AcquireReference (); return AAFRESULT_SUCCESS; }//CreateValue()
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefCharacter::CreateValueFromCharacter ( aafCharacter character, ImplAAFPropertyValue ** ppCharacterValue) { TRACE("ImplAAFTypeDefCharacter::CreateValueFromCharacter"); if (! ppCharacterValue) return AAFRESULT_NULL_PARAM; aafUInt32 cbChar = NativeSize(); // Create a temporary pointer to copy to the smartptr ImplAAFPropValData * tmp = (ImplAAFPropValData *)CreateImpl(CLSID_AAFPropValData); if (NULL == tmp) return AAFRESULT_NOMEMORY; ImplAAFPropValDataSP pv; pv = tmp; tmp->ReleaseReference(); // we don't need this reference anymore. tmp = 0; //Initialize check_hr ( pv->Initialize(this) ); //Allocate appropriate bits aafMemPtr_t pBits = NULL; check_hr ( pv->AllocateBits (cbChar, &pBits) ); //Set the bits to incoming character ASSERT("Valid bits", pBits != 0); memcpy (pBits, &character, cbChar); *ppCharacterValue = pv; (*ppCharacterValue)->AcquireReference (); return AAFRESULT_SUCCESS; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefString::AppendElements ( ImplAAFPropertyValue * pInPropVal, aafMemPtr_t pElements) { if (! pInPropVal) return AAFRESULT_NULL_PARAM; if (! pElements) return AAFRESULT_NULL_PARAM; if (! IsRegistered ()) return AAFRESULT_NOT_REGISTERED; AAFRESULT hr; // Get the property value's embedded type and // check if it's the same as the base type. ImplAAFTypeDefSP pIncomingType; if( AAFRESULT_FAILED( pInPropVal->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; ImplAAFTypeDefSP pBaseType; hr = GetType (&pBaseType); //do the size thing ... ASSERTU (pBaseType->IsFixedSize ()); pBaseType->AttemptBuiltinRegistration (); ASSERTU (pBaseType->IsRegistered ()); // Size of individual elements aafUInt32 elementSize = pBaseType->NativeSize (); // Get the current size of the property aafUInt32 originalDataSize; ImplAAFPropValDataSP pvd; pvd = dynamic_cast<ImplAAFPropValData *>(pInPropVal); ASSERTU (pvd); hr = pvd->GetBitsSize (&originalDataSize); //get the data aafMemPtr_t pOriginalData = NULL; hr = pvd->GetBits (&pOriginalData); ASSERTU(hr == AAFRESULT_SUCCESS); ///// //Now, find out what additional size we need based on the new data coming in. //first, see how many elements we have aafMemPtr_t pNewData = pElements; aafUInt32 newElemCount =0; //outer loop of the entire memory buffer passed in ... while (pNewData) { aafUInt32 count_of_zeroes = 0; //inner loop - chunking in size of elementSize for (aafUInt32 i=0; i<elementSize; i++, pNewData++) if (*pNewData == 0) count_of_zeroes++; if (count_of_zeroes == elementSize) //we have a null! ... done! break; //otherwise, increment new element count, and move on newElemCount++; }//while //At this point, our newElemCount holds a count of new elements to be added //and the new size of bits is: aafUInt32 newsize = (newElemCount+1/*don't forget EOS*/) * elementSize; //Add this "newsize" to the original originalDataSize to get the new Total buffer size aafUInt32 TotalSize = originalDataSize + newsize; // Make sure that the new size doesn't exceed maximum // size allowed for simple properties. if (TotalSize > OMPROPERTYSIZE_MAX) return AAFRESULT_BAD_SIZE; //Save the orginal buffer, before we re-allocate aafMemPtr_t tmp_buffer = new aafUInt8[originalDataSize+1]; memcpy(tmp_buffer, pOriginalData, originalDataSize); //Allocate the grand total # of bits (orginal + the new stuff) ... aafMemPtr_t pBits = 0; hr = pvd->AllocateBits (TotalSize, &pBits); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (pBits); //copy over the first part memcpy (pBits, tmp_buffer, originalDataSize); pBits += originalDataSize; //copy over the second part memcpy (pBits, pElements, newsize); //delete our tmp_buffer delete [] tmp_buffer; return AAFRESULT_SUCCESS; }