Ejemplo n.º 1
0
AAFRESULT STDMETHODCALLTYPE
    ImplAAFTypeDefCharacter::SetCharacter (
      ImplAAFPropertyValue * pCharacterValue,
      aafCharacter  character)
{
  TRACE("ImplAAFTypeDefCharacter::SetCharacter");
  
	if (! pCharacterValue)
		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;
	}
	
	//ok all set with initial conditions
	//now set the value to the incoming character
	
	aafMemPtr_t pBits = NULL;
	check_hr ( pvd->GetBits (&pBits)  );
	ASSERT("Valid bits", pBits != 0);
	
	memcpy (pBits, &character, cbChar);
	
	return AAFRESULT_SUCCESS;
	
}
Ejemplo n.º 2
0
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;
}