2005/5/10

     
 

ScriptVar

artefaktur

| DMI Basics | Features Profile | DMI Client Interface | ScriptVar | DMI Server | Using DMI in C++ | DMI with CfgScript | DMI Server Objects | Subclassing | Delegates |


To provide a flexibility data type for dynamic invocation ScriptVar is used as wrapper for all ACDK types.


Content of this chapter:

   acdk::lang::dmi::ScriptVar
     ScriptVar Values
     Values and References
     ScriptVar Flags
     Initializing
   Using any-type in DMI



Anys and Variants An important aspect in generic call interfaces is that the type of the arguments must be:

  • Homogeneous. The generic call interface has only to deal with one container type.
  • Self descriptive. The concrete type (and size) of the contained type must be known.

COM+ and CORBA both provide such a container:
  • COM+: VARIANT
  • CORBA: any

// pseudo code
class AnyVal
{
  // The possible types
  enum Type
  {
    Int,
    Long,
    Float,
    Object
    // etc.
  };
  Type type;
  
  // contained values.
  union TypeUnion
  {
    int ival;
    long lval;
    float fval;
    Object oval;
    // etc... 
  };
  TypeUnion val;
};

 acdk::lang::dmi::ScriptVar


For detailed reference see  acdk::lang::dmi::ScriptVar.


 ScriptVar Values

Such a container for any type is the class  acdk::lang::dmi::ScriptVar.
A ScriptVar can contain values from following types:

 Values and References


To support the IN(), OUT() and INOUT() parameter types in the DMI, a ScriptVar can contain a value or a reference to a value.

For basic types this is a value or a pointer to the value.
For Object types this is is a RObject or a pointer to a RObject.

!

The lifetime of the contained reference values are not managed by the ScriptVar, but must keep alive by the calling context.
In normal use ScriptVar should only used as stack variable. The contained reference value should also keep as stack variable with a outer scope:

  int ival = 42;
  {
    ScriptVar sv(&ival);
    callSomeThing(sv);
  }

 ScriptVar Flags


The flags indicates some calling convention informations, like the IN, OUT, INOUT, BYVAL flags.

 Initializing

For the major DMI interfaces ScriptVar is the major data type.

For the standard types there is a direct constructor to convert the contained type value into a ScriptVar.

  ScriptVar svint(int(42));
  ScriptVar svshort(short(42));
  ScriptVar svobject(new Integer(42));

!

If you initialize a ScriptVar with a string literal, you may not receive the result you expected:

 ScriptVar svstring("This is a String");
The type is not ObjectType (containing a String instance) but CharRefType.
Use instead:

ScriptVar svstring(new String("This is a String"));
// or
ScriptVar svstring(RCS("This is a String"));

 Using any-type in DMI

An C++ method with a ScriptVar as argument is not itself DMI-able (see  Valid DMI-able Types).
Use the compatible class  acdk::lang::dmi::DmiObject instead.