AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefRename::GetBaseValue ( ImplAAFPropertyValue * pInPropVal, ImplAAFPropertyValue ** ppOutPropVal) { if (! pInPropVal) return AAFRESULT_NULL_PARAM; if (! ppOutPropVal) return AAFRESULT_NULL_PARAM; // Get the property value's embedded type and // check if it's the same as the base type. ImplAAFTypeDefSP pInPropType; if( AAFRESULT_FAILED( pInPropVal->GetType( &pInPropType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pInPropType); if( (ImplAAFTypeDef *)pInPropType != this ) return AAFRESULT_BAD_TYPE; aafUInt32 inBitsSize; ImplAAFPropValDataSP pOutPVData; ImplAAFPropValDataSP pvd; ImplAAFTypeDefSP ptd; AAFRESULT hr; hr = GetBaseType (&ptd); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (ptd); // aafUInt32 elementSize = ptd->PropValSize(); ASSERTU (pInPropVal); pvd = dynamic_cast<ImplAAFPropValData*> (pInPropVal); ASSERTU (pvd); hr = pvd->GetBitsSize (&inBitsSize); if (! AAFRESULT_SUCCEEDED (hr)) return hr; pOutPVData = (ImplAAFPropValData *)CreateImpl(CLSID_AAFPropValData); if (! pOutPVData) return AAFRESULT_NOMEMORY; // Bobt: Hack bugfix! SmartPointer operator= will automatically // AddRef; CreateImpl *also* will addref, so we've got one too // many. Put us back to normal. pOutPVData->ReleaseReference (); ASSERTU (ptd); hr = pOutPVData->Initialize (ptd); if (AAFRESULT_FAILED(hr)) return hr; hr = pOutPVData->AllocateFromPropVal (pvd, 0, inBitsSize, NULL); if (AAFRESULT_FAILED(hr)) return hr; ASSERTU (ppOutPropVal); *ppOutPropVal = pOutPVData; (*ppOutPropVal)->AcquireReference (); ASSERTU (*ppOutPropVal); return AAFRESULT_SUCCESS; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefCharacter::GetCharacter ( ImplAAFPropertyValue * pCharacterValue, aafCharacter * pCharacter) { TRACE("ImplAAFTypeDefCharacter::GetCharacter"); if (! pCharacterValue) return AAFRESULT_NULL_PARAM; if (! pCharacter) return AAFRESULT_NULL_PARAM; //get a pointer to the Val Data ImplAAFPropValDataSP pvd; pvd = dynamic_cast<ImplAAFPropValData*>(pCharacterValue); if (!pvd) return AAFRESULT_BAD_TYPE; // get the property value's embedded type ImplAAFTypeDefSP pPropType; check_hr ( pvd->GetType (&pPropType) ); //Make sure the TD of the pv passed in, matches that of the ImplAAFTypeDefCharacter if ((ImplAAFTypeDef *)pPropType != this) // call operator ImplAAFTypeDef * return AAFRESULT_BAD_TYPE; //check to make sure that the size in the val data matches that of the native size aafUInt32 cbChar = 0; check_hr ( pvd->GetBitsSize(&cbChar) ); if (cbChar != NativeSize()) { return AAFRESULT_BAD_SIZE; } //Now set the character from that contained in the prop val data aafMemPtr_t pBits = NULL; check_hr ( pvd->GetBits (&pBits) ); ASSERT("Valid bits", pBits != 0); memcpy (pCharacter, pBits, cbChar); return AAFRESULT_SUCCESS; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefString::GetElements ( ImplAAFPropertyValue * pInPropVal, aafMemPtr_t pBuffer, aafUInt32 bufferSize) { AAFRESULT hr; if (! pInPropVal) return AAFRESULT_NULL_PARAM; if (! pBuffer) return AAFRESULT_NULL_PARAM; if (! IsRegistered ()) return AAFRESULT_NOT_REGISTERED; // 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; ImplAAFPropValDataSP pvd; pvd = dynamic_cast<ImplAAFPropValData*>(pInPropVal); if (!pvd) return AAFRESULT_BAD_TYPE; aafUInt32 propBitsSize; hr = pvd->GetBitsSize(&propBitsSize); if (AAFRESULT_FAILED(hr)) return hr; if (bufferSize < propBitsSize) return AAFRESULT_SMALLBUF; aafMemPtr_t pBits = NULL; hr = pvd->GetBits (&pBits); if (AAFRESULT_FAILED(hr)) return hr; ASSERTU (pBits); ASSERTU (pBuffer); ASSERTU (propBitsSize <= bufferSize); memcpy (pBuffer, pBits, propBitsSize); return AAFRESULT_SUCCESS; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefRename::CreateValue ( ImplAAFPropertyValue * pInPropVal, ImplAAFPropertyValue ** ppOutPropVal) { if (! pInPropVal) return AAFRESULT_NULL_PARAM; if (! ppOutPropVal) return AAFRESULT_NULL_PARAM; aafUInt32 inBitsSize; ImplAAFPropValDataSP pOutPVData; ImplAAFPropValDataSP pvd; AAFRESULT hr; ASSERTU (pInPropVal); pvd = dynamic_cast<ImplAAFPropValData*> (pInPropVal); ASSERTU (pvd); hr = pvd->GetBitsSize (&inBitsSize); if (! AAFRESULT_SUCCEEDED (hr)) return hr; pOutPVData = (ImplAAFPropValData *)CreateImpl(CLSID_AAFPropValData); if (! pOutPVData) return AAFRESULT_NOMEMORY; // SmartPointer operator= will automatically AddRef; CreateImpl *also* will // addref, so we've got one too many. Put us back to normal. pOutPVData->ReleaseReference (); hr = pOutPVData->Initialize (this); if (AAFRESULT_FAILED(hr)) return hr; hr = pOutPVData->AllocateFromPropVal (pvd, 0, inBitsSize, NULL); if (AAFRESULT_FAILED(hr)) return hr; ASSERTU (ppOutPropVal); *ppOutPropVal = pOutPVData; (*ppOutPropVal)->AcquireReference (); ASSERTU (*ppOutPropVal); return AAFRESULT_SUCCESS; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefString::GetCount ( ImplAAFPropertyValue * pPropVal, aafUInt32 * pCount) { ImplAAFTypeDefSP pIncomingType; ImplAAFTypeDefSP ptd; AAFRESULT hr; if (! pPropVal) return AAFRESULT_NULL_PARAM; if (! pCount) return AAFRESULT_NULL_PARAM; // Get the property value's embedded type and // check if it's the same as the base type. if( AAFRESULT_FAILED( pPropVal->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; hr = GetType (&ptd); if (AAFRESULT_FAILED(hr)) return hr; ASSERTU (ptd); ASSERTU (ptd->IsFixedSize()); aafUInt32 elemSize = ptd->ActualSize(); aafUInt32 propSize; ASSERTU (pPropVal); ImplAAFPropValDataSP pvd; pvd = dynamic_cast<ImplAAFPropValData *>(pPropVal); ASSERTU (pvd); hr = pvd->GetBitsSize (&propSize); if (AAFRESULT_FAILED(hr)) return hr; ASSERTU (pCount); *pCount = propSize / elemSize; return AAFRESULT_SUCCESS; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::GetElementValue ( ImplAAFPropertyValue * pInPropVal, aafUInt32 index, ImplAAFPropertyValue ** ppOutPropVal) { if (! pInPropVal) return AAFRESULT_NULL_PARAM; if (! ppOutPropVal) return AAFRESULT_NULL_PARAM; // 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; ImplAAFRefArrayValue* pRefArray = dynamic_cast<ImplAAFRefArrayValue*>(pInPropVal); if (NULL != pRefArray) { return pRefArray->GetElementAt(index, ppOutPropVal); } if (index >= pvtCount (pInPropVal)) return AAFRESULT_BADINDEX; aafUInt32 inBitsSize; ImplAAFPropValDataSP pOutPVData; ImplAAFPropValDataSP pvd; ImplAAFTypeDefSP ptd; AAFRESULT hr; hr = GetType (&ptd); if (AAFRESULT_FAILED (hr)) return hr; // aafUInt32 elementSize = ptd->PropValSize(); aafUInt32 elementSize = ptd->ActualSize(); // okay for data not to be registered? ASSERTU (pInPropVal); pvd = dynamic_cast<ImplAAFPropValData*> (pInPropVal); hr = pvd->GetBitsSize (&inBitsSize); if (! AAFRESULT_SUCCEEDED (hr)) return hr; ASSERTU ((index+1) * elementSize <= inBitsSize); pOutPVData = (ImplAAFPropValData *)CreateImpl(CLSID_AAFPropValData); if (! pOutPVData) return AAFRESULT_NOMEMORY; // Bobt: Hack bugfix! SmartPointer operator= will automatically // AddRef; CreateImpl *also* will addref, so we've got one too // many. Put us back to normal. pOutPVData->ReleaseReference (); hr = pOutPVData->Initialize (ptd); if (AAFRESULT_FAILED(hr)) return hr; hr = pOutPVData->AllocateFromPropVal (pvd, index * elementSize, elementSize, NULL); if (AAFRESULT_FAILED(hr)) return hr; ASSERTU (ppOutPropVal); *ppOutPropVal = pOutPVData; ASSERTU (*ppOutPropVal); (*ppOutPropVal)->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; }