Exemplo n.º 1
0
// Allocate and initialize the correct subclass of ImplAAFPropertyValue 
// for the given OMProperty.
AAFRESULT STDMETHODCALLTYPE
  ImplAAFTypeDef::CreatePropertyValue(
    OMProperty *property,
    ImplAAFPropertyValue ** ppPropertyValue ) const
{
  AAFRESULT result = AAFRESULT_SUCCESS;
  ASSERTU (property && ppPropertyValue);
  if (NULL == property || NULL == ppPropertyValue)
    return AAFRESULT_NULL_PARAM;
  *ppPropertyValue = NULL; // initialize out parameter
  ASSERTU (property->definition());
  if (NULL == property->definition())
    return AAFRESULT_INVALID_PARAM;
  const OMType *type = property->definition()->type();
  ASSERTU (type);
  ImplAAFTypeDef *ptd = const_cast<ImplAAFTypeDef *>
                          (dynamic_cast<const ImplAAFTypeDef *>(type));
  ASSERTU (ptd);
  if (NULL == ptd)
    return AAFRESULT_INVALID_PARAM;
 
  ImplAAFPropValData *pvd = NULL;
  pvd = (ImplAAFPropValData*) CreateImpl (CLSID_AAFPropValData);
  if (!pvd) 
    return AAFRESULT_NOMEMORY;

  result = pvd->Initialize (ptd);
  if (AAFRESULT_SUCCEEDED(result))
  {
    // set the storage in the prop value
    OMUInt32 bitsSize;
    ASSERTU (property);
    bitsSize = property->bitsSize ();
    aafMemPtr_t pBits = NULL;
    // Bobt hack! This should be removed once we have proper
    // integration with OM property def support.
    if (! property->isOptional() || property->isPresent ())
    {
      result = pvd->AllocateBits (bitsSize, &pBits);
      if (AAFRESULT_SUCCEEDED (result))
      {
	if (bitsSize)
        {
          ASSERTU (pBits);
          property->getBits (pBits, bitsSize);
        }
      }
    }
  }

  if (AAFRESULT_SUCCEEDED(result))
  {
    *ppPropertyValue = pvd; // ref count is already 1.
    pvd = NULL;
  }
  else
  {
    pvd->ReleaseReference(); // delete the new object.
  }

  return (result) ;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}