Esempio n. 1
0
bool FileFormatInstance::WriteProperty( const IsoString& property, const Variant& value )
{
   try
   {
      if ( (*API->FileFormat->BeginPropertyEmbedding)( handle ) == api_false )
         return false;

      bool ok = true;

      if ( value.IsValid() )
      {
         api_property_value apiValue;
         APIPropertyValueFromVariant( apiValue, value );
         api_property_value safeCopy = apiValue;
         ok = (*API->FileFormat->SetImageProperty)( handle, property.c_str(), &safeCopy ) != api_false;

         if ( safeCopy.data.blockValue != apiValue.data.blockValue ||
              safeCopy.dimX != apiValue.dimX || safeCopy.dimY != apiValue.dimY ||
              safeCopy.dimZ != apiValue.dimZ || safeCopy.dimT != apiValue.dimT || safeCopy.type != apiValue.type )
         {
            APIHackingAttempt( "WriteProperty" );
         }
      }

      (*API->FileFormat->EndPropertyEmbedding)( handle );

      return ok;
   }
   catch ( ... )
   {
      (*API->FileFormat->EndPropertyEmbedding)( handle );
      throw;
   }
}
void FileFormatImplementation::SetImageProperty( const IsoString& id, const Variant& value )
{
   IsoString tid = id.Trimmed();
   if ( !tid.IsEmpty() && value.IsValid() )
   {
      FileFormatPropertyArray::iterator i = m_data->properties.Search( tid );
      if ( i != m_data->properties.End() )
         i->value = value;
      else
         m_data->properties.Append( FileFormatProperty( tid, value ) );
   }
}
Esempio n. 3
0
bool ProcessInstance::SetParameterValue( const Variant& value,
                                         const ProcessParameter& parameter, size_type rowIndex )
{
   if ( !value.IsValid() )
      return false;

   uint32 apiType = (*API->Process->GetParameterType)( parameter.Handle() ) & PTYPE_TYPE_MASK;
   if ( apiType == 0 )
      throw APIFunctionError( "GetParameterType" );

   if ( apiType == PTYPE_TABLE )
      throw Error( "ProcessInstance::SetParameterValue(): Invoked for a table parameter" );

   if ( apiType == PTYPE_STRING )
   {
      String s = value.ToString();
      return (*API->Process->SetParameterValue)( handle, parameter.Handle(), rowIndex, s.c_str(), s.Length() ) != api_false;
   }

   if ( apiType == PTYPE_BLOCK )
   {
      ByteArray a = value.ToByteArray();
      return (*API->Process->SetParameterValue)( handle, parameter.Handle(), rowIndex, a.Begin(), a.Length() ) != api_false;
   }

   union
   {
      uint32   u32;
      int32    i32;
      uint64   u64;
      int64    i64;
      float    f;
      double   d;
      api_bool b;
      api_enum e;
   }
   apiValue;

   switch ( apiType )
   {
   case PTYPE_UINT8:
   case PTYPE_UINT16:
   case PTYPE_UINT32:
      apiValue.u32 = value.ToUInt();
      break;
   case PTYPE_INT8:
   case PTYPE_INT16:
   case PTYPE_INT32:
      apiValue.i32 = value.ToInt();
      break;
   case PTYPE_UINT64:
      apiValue.u64 = value.ToUInt64();
      break;
   case PTYPE_INT64:
      apiValue.i64 = value.ToInt64();
      break;
   case PTYPE_FLOAT:
      apiValue.f = value.ToFloat();
      break;
   case PTYPE_DOUBLE:
      apiValue.d = value.ToDouble();
      break;
   case PTYPE_BOOL:
      apiValue.b = api_bool( value.ToBoolean() );
      break;
   case PTYPE_ENUM:
      apiValue.e = api_enum( value.ToInt() );
      break;
   default:
      throw Error( "ProcessParameter::SetParameterValue(): Internal error: Unknown parameter type" );
   }

   return (*API->Process->SetParameterValue)( handle, parameter.Handle(), rowIndex, &apiValue, 1 ) != api_false;
}