13.1.8.1 Union Member Accessor and Modifier Member Function Mapping

For each member in the union, accessor and modifier member functions are generated.

In the following code, taken from the previous example, two member functions are generated for the ID member function:

void idInfo (ID);
ID idInfo () const;

In this example, the first function (the modifier) sets the discriminator to the default value and sets the value of the union to the specified ID value. The second function, the accessor, returns the value of the union.

Depending upon the data type of the union member, additional modifier functions are generated. The member functions generated for each data type are as follows:

  • Basic data types—short, long, unsigned short, unsigned long, float, double, char, boolean, and octet

    The following example generates two member functions for a basic data type with member name basictype:
    void basictype (TYPE);     // modifier
    TYPE basictype () const;   // accessor

    For the mapping from an OMG IDL data type to the C++ data type TYPE , see the following table.

  • Object and pseudo-object

    For object and Typecode types with member name objtype, member functions are generated as follows:

    void objtype (TYPE); // modifier
    TYPE objtype () const; // accessor

    For the mapping from an OMG IDL data type to the C++ data type TYPE, see the following table.

    The modifier member function does not assume ownership of the specified object reference argument. Instead, the modifier duplicates the object reference or pseudo-object reference. You are responsible for releasing the reference when it is no longer required.

  • Enum

    For an enum TYPE with member name enumtype, member functions are generated as follows:

    void enumtype (TYPE);      // modifier
    TYPE enumtype () const;   // accessor
  • String

    For strings, one accessor and three modifier functions are generated, as follows:

    void stringInfo (char *);                        // modifier 1
    void stringInfo (const char *);                 // modifier 2
    void stringInfo (const CORBA::String_var &);   // modifier 3
    const char * stringInfo () const;             // accessor

    The first modifier assumes ownership of the char * parameter passed to it and the union is responsible for calling the CORBA::string_free member function on this string when the union value changes or when the union is destroyed.

    The second and third modifiers make a copy of the specified string passed in the parameter or contained in the string var.

    The accessor function returns a pointer to internal memory of the union; do not attempt to free this memory, and do not access this memory after the union value has been changed or the union has been destroyed.

  • Struct, union, sequence, and any

    For these data types, modifier and accessor functions are generated with references to the type, as follows:

    void reftype (TYPE &);            // modifier
    const TYPE & reftype () const;    // accessor
    TYPE & reftype ();                // accessor

    The modifier function does not assume ownership of the input type parameter; instead, the function makes a copy of the data type.

  • Array

    For an array, the modifier member function accepts an array pointer while the accessor returns a pointer to an array slice, as follows:

    void arraytype (TYPE);              // modifier
    TYPE_slice * arraytype () const;   // accessor

    The modifier function does not assume ownership of the input type parameter; instead, the function makes a copy of the array.