AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::CreateValueFromCArray ( aafMemPtr_t pInitData, aafUInt32 initDataSize, ImplAAFPropertyValue ** ppPropVal) { if (! pInitData) return AAFRESULT_NULL_PARAM; if (! ppPropVal) return AAFRESULT_NULL_PARAM; ImplAAFTypeDefSP pElementType; AAFRESULT result = GetType(&pElementType); if (AAFRESULT_FAILED(result)) return result; if (dynamic_cast<ImplAAFTypeDefObjectRef*>((ImplAAFTypeDef*) pElementType)) { // 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; } 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... aafUInt32 refCount; refCount = tmp->ReleaseReference (); // ...make sure it really does ASSERTU (1 == refCount); AAFRESULT hr; hr = pvd->Initialize(this); if (! AAFRESULT_SUCCEEDED (hr)) return hr; hr = SetCArray (pvd, pInitData, initDataSize); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (ppPropVal); *ppPropVal = pvd; ASSERTU (*ppPropVal); (*ppPropVal)->AcquireReference (); 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 ImplAAFTypeDefString::CreateValueFromCString ( aafMemPtr_t pInitData, aafUInt32 initDataSize, ImplAAFPropertyValue ** ppPropVal) { if (! pInitData) return AAFRESULT_NULL_PARAM; if (! ppPropVal) return AAFRESULT_NULL_PARAM; if (! IsRegistered ()) return AAFRESULT_NOT_REGISTERED; if (initDataSize > OMPROPERTYSIZE_MAX) return AAFRESULT_BAD_SIZE; 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... aafUInt32 refCount; refCount = tmp->ReleaseReference (); // ...make sure it really does ASSERTU (1 == refCount); AAFRESULT hr; hr = pvd->Initialize(this); if (! AAFRESULT_SUCCEEDED (hr)) return hr; hr = SetCString (pvd, pInitData, initDataSize); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (ppPropVal); *ppPropVal = pvd; ASSERTU (*ppPropVal); (*ppPropVal)->AcquireReference (); return AAFRESULT_SUCCESS; }
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 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 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 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 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 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; }