void ImplAAFTypeDefString::internalize(const OMByte* externalBytes, OMUInt32 externalBytesSize, OMByte* internalBytes, OMUInt32 internalBytesSize, OMByteOrder byteOrder) const { ImplAAFTypeDefSP ptd = BaseType(); ASSERTU (ptd); ASSERTU (ptd->IsFixedSize ()); aafUInt32 extElemSize = ptd->PropValSize (); aafUInt32 intElemSize = ptd->ActualSize (); // aafUInt32 intElemSize = ptd->internalSize (0, 0); // aafUInt32 extElemSize = ptd->externalSize (0, 0); aafUInt32 numElems = externalBytesSize / extElemSize; aafInt32 intNumBytesLeft = internalBytesSize; aafInt32 extNumBytesLeft = externalBytesSize; aafUInt32 elem = 0; for (elem = 0; elem < numElems; elem++) { ptd->type()->internalize (externalBytes, extElemSize, internalBytes, intElemSize, byteOrder); internalBytes += intElemSize; externalBytes += extElemSize; intNumBytesLeft -= intElemSize; extNumBytesLeft -= extElemSize; ASSERTU (intNumBytesLeft >= 0); ASSERTU (extNumBytesLeft >= 0); } }
OMUInt32 ImplAAFTypeDefString::internalSize(const OMByte* /*externalBytes*/, OMUInt32 externalBytesSize) const { ImplAAFTypeDefSP ptd = BaseType(); ASSERTU (ptd); ASSERTU (ptd->IsFixedSize ()); aafUInt32 extElemSize = ptd->PropValSize (); aafUInt32 intElemSize = ptd->ActualSize (); // aafUInt32 extElemSize = ptd->externalSize (0, 0); // aafUInt32 intElemSize = ptd->internalSize (0, 0); ASSERTU (intElemSize); aafUInt32 numElems = externalBytesSize / extElemSize; return numElems * intElemSize; }
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::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::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; }