AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::ValidateInputParams ( ImplAAFPropertyValue ** ppElementValues, aafUInt32 numElements) { //first validate params + basic stuff ... if (!ppElementValues) return AAFRESULT_NULL_PARAM; //verify that all the individual elem types are the same as each other, HRESULT hr; //get Base TD ImplAAFTypeDefSP spTargetTD; hr = GetType(&spTargetTD); //gets base elem type if (AAFRESULT_FAILED (hr)) return hr; if (! spTargetTD->IsRegistered ()) return AAFRESULT_NOT_REGISTERED; //Get size aafUInt32 targetElemSize = spTargetTD->NativeSize(); for (aafUInt32 i=0; i<numElements; i++) { //get source type ImplAAFTypeDefSP spSourceTD; hr = ppElementValues[i]->GetType (&spSourceTD); if (AAFRESULT_FAILED (hr)) return hr; //verify that spTargetTD == spSourceTD if (spSourceTD != spTargetTD ) return AAFRESULT_BAD_TYPE; //verify FIXED/VARIABLE Arrayable if (! IsArrayable(spSourceTD) ) return AAFRESULT_BAD_TYPE; //verify that the target elem size is equal to that of source aafUInt32 sourceSize = spSourceTD->NativeSize(); if (sourceSize != targetElemSize ) return AAFRESULT_BAD_SIZE; }//for each elem return AAFRESULT_SUCCESS; }//ValidateInputParams()
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::SetCArray ( ImplAAFPropertyValue * pPropVal, aafMemPtr_t pData, aafUInt32 dataSize) { if (! pPropVal) return AAFRESULT_NULL_PARAM; if (! pData) 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( pPropVal->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; AAFRESULT hr; ImplAAFTypeDefSP pBaseType; hr = GetType (&pBaseType); ASSERTU (pBaseType->IsFixedSize ()); pBaseType->AttemptBuiltinRegistration (); ASSERTU (pBaseType->IsRegistered ()); ImplAAFRefArrayValue* pRefArray = dynamic_cast<ImplAAFRefArrayValue*>(pPropVal); if (NULL != pRefArray) { // This interface is not type-safe for accessing objects! There is also no // mechanism in place to convert between a buffer pointer and an array // of interface pointers; this convertion would not be necessary for // arrays of non-objects. return AAFRESULT_BAD_TYPE; } // Size of individual elements aafUInt32 elemSize = pBaseType->NativeSize (); // number of elements in input data. If this is not an integral // number, this will round down and the test below will fail. aafUInt32 elemCount = dataSize / elemSize; // The size of the new property, calculated from number of elements // and the size of each element. aafUInt32 propSize = elemSize * elemCount; // If the given dataSize was not an integral multiple of the size of // each element, then we'll signal an error. if (propSize != dataSize) return AAFRESULT_BAD_SIZE; // In case of fixed-size arrays, we'll also have to see if the data // size matches what we're expecting. if (IsFixedSize ()) { aafUInt32 nativeSize = NativeSize (); if (nativeSize != dataSize) return AAFRESULT_BAD_SIZE; } ImplAAFPropValData * pvd = 0; ASSERTU (pPropVal); pvd = dynamic_cast<ImplAAFPropValData*> (pPropVal); ASSERTU (pvd); aafMemPtr_t pBits = 0; hr = pvd->AllocateBits (propSize, &pBits); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (pBits); memcpy (pBits, pData, propSize); return AAFRESULT_SUCCESS; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::SetElementValue ( ImplAAFPropertyValue * pPropVal, aafUInt32 index, ImplAAFPropertyValue * pMemberPropVal) { //Ensure our input pointers are valid if (!pPropVal || !pMemberPropVal) 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( pPropVal->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; ImplAAFRefArrayValue* pRefArray = dynamic_cast<ImplAAFRefArrayValue*>(pPropVal); if (NULL != pRefArray) { return pRefArray->SetElementAt(pMemberPropVal, index); } //Ensure index is within range if (index >= pvtCount(pPropVal)) //if index is > 0..n-1 return AAFRESULT_BADINDEX; //AAFRESULT_BAD_PARAM; //all parameters validated; proceed .... AAFRESULT hr; //get source size ImplAAFTypeDefSP spSourceTD; hr = pMemberPropVal->GetType (&spSourceTD); if (AAFRESULT_FAILED (hr)) return hr; if (! spSourceTD->IsRegistered ()) return AAFRESULT_NOT_REGISTERED; aafUInt32 sourceSize = spSourceTD->NativeSize(); //get Base TD and size ImplAAFTypeDefSP spTargetTD; hr = GetType (&spTargetTD); //gets base elem type if (AAFRESULT_FAILED (hr)) return hr; aafUInt32 targetElemSize = spTargetTD->NativeSize(); //verify that spTargetTD == spSourceTD if (spTargetTD != spSourceTD) return AAFRESULT_BAD_TYPE; //verify that the target elem size is equal to that of source if (targetElemSize != sourceSize) return AAFRESULT_BAD_SIZE; //// On to data ... //get Source Data ImplAAFPropValData * pvd_Source = dynamic_cast<ImplAAFPropValData*> (pMemberPropVal); ASSERTU (pvd_Source); aafUInt32 source_bitsSize; hr = pvd_Source->GetBitsSize (&source_bitsSize); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (source_bitsSize); ASSERTU ( targetElemSize == source_bitsSize); aafMemPtr_t pSourceData = 0; hr = pvd_Source->GetBits (&pSourceData); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (pSourceData); //get Target Data ImplAAFPropValData * pvd_Target = dynamic_cast<ImplAAFPropValData*> (pPropVal); ASSERTU (pvd_Target); aafUInt32 target_bitsSize; hr = pvd_Target->GetBitsSize (&target_bitsSize); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU ( target_bitsSize >= ((index+1) * targetElemSize) ); aafMemPtr_t pTargetData = 0; hr = pvd_Target->GetBits (&pTargetData); //gets the 0th index location if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (pTargetData); //make target point to the right element pTargetData += (index * targetElemSize); //finally, copy over the appropriate bits memcpy (pTargetData, pSourceData, sourceSize); return AAFRESULT_SUCCESS; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::GetCArray ( ImplAAFPropertyValue * pPropVal, aafMemPtr_t pData, aafUInt32 dataSize) { if (! pPropVal) return AAFRESULT_NULL_PARAM; if (! pData) 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( pPropVal->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; ImplAAFTypeDefSP pBaseType; HRESULT hr = GetType (&pBaseType); ASSERTU (pBaseType->IsFixedSize ()); pBaseType->AttemptBuiltinRegistration (); ASSERTU (pBaseType->IsRegistered ()); ImplAAFRefArrayValue* pRefArray = dynamic_cast<ImplAAFRefArrayValue*>(pPropVal); if (NULL != pRefArray) { // This interface is not type-safe for accessing objects! There is also no // mechanism in place to convert between a buffer pointer and an array // of interface pointers; this convertion would not be necessary for // arrays of non-objects. return AAFRESULT_BAD_TYPE; } aafUInt32 elemSize = pBaseType->NativeSize (); aafUInt32 elemCount = pvtCount (pPropVal); aafUInt32 propSize = elemSize * elemCount; if (dataSize < propSize) return AAFRESULT_BAD_SIZE; ImplAAFPropValData * pvd = 0; ASSERTU (pPropVal); pvd = dynamic_cast<ImplAAFPropValData*> (pPropVal); ASSERTU (pvd); aafUInt32 bitsSize; hr = pvd->GetBitsSize (&bitsSize); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (bitsSize >= propSize); aafMemPtr_t pBits = 0; hr = pvd->GetBits (&pBits); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (pBits); memcpy (pData, pBits, propSize); 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; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefString::SetCString ( ImplAAFPropertyValue * pPropVal, aafMemPtr_t pData, aafUInt32 dataSize) { if (! pPropVal) return AAFRESULT_NULL_PARAM; if (! pData) return AAFRESULT_NULL_PARAM; if (! IsRegistered ()) return AAFRESULT_NOT_REGISTERED; if (dataSize > OMPROPERTYSIZE_MAX) return AAFRESULT_BAD_SIZE; // Get the property value's embedded type and // check if it's the same as the base type. ImplAAFTypeDefSP pIncomingType; if( AAFRESULT_FAILED( pPropVal->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; AAFRESULT hr; ImplAAFTypeDefSP pBaseType; hr = GetType (&pBaseType); ASSERTU (pBaseType->IsFixedSize ()); pBaseType->AttemptBuiltinRegistration (); ASSERTU (pBaseType->IsRegistered ()); // Size of individual elements aafUInt32 elemSize = pBaseType->NativeSize (); // number of elements in input data. If this is not an integral // number, this will round down and the test below will fail. aafUInt32 elemCount = dataSize / elemSize; // The size of the new property, calculated from number of elements // and the size of each element. aafUInt32 propSize = elemSize * elemCount; // If the given dataSize was not an integral multiple of the size of // each element, then we'll signal an error. if (propSize != dataSize) return AAFRESULT_BAD_SIZE; ImplAAFPropValData * pvd = 0; ASSERTU (pPropVal); pvd = dynamic_cast<ImplAAFPropValData*> (pPropVal); ASSERTU (pvd); aafMemPtr_t pBits = 0; hr = pvd->AllocateBits (propSize, &pBits); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (pBits); memcpy (pBits, pData, propSize); return AAFRESULT_SUCCESS; }