13.1.24 Attributes

A read-only attribute in OMG IDL is mapped to a C++ function that returns the attribute value. A read-write attribute maps to two overloaded C++ functions, one to return the attribute value and one to set the attribute value. The name of the overloaded member function is the name of the attribute.

Attributes are generated in the same way that operations are generated. They are defined in both the virtual and the stub classes. For example, consider the following OMG IDL definition:

// OMG IDL
module INVENT
    {
    interface Order
        {
        . . .
        attribute itemStruct itemInfo;
        };
};

This definition maps to C++ as follows:

// C++
class INVENT
    {
    . . .
    class Item : public virtual CORBA::Object
        {
        . . .
         virtual itemStruct * itemInfo ( ) = 0;
        virtual void itemInfo (
            const itemStruct & itemInfo) = 0;
        };
    };
class Stub_Item : public Item
    {
    . . .
        itemStruct * itemInfo ();
        void itemInfo (
          const itemStruct & itemInfo);
    };

The generated client application stub then contains the following generated code for the stub class:

// ROUTINE NAME:      INVENT::Stub_Item::itemInfo
//
// FUNCTIONAL DESCRIPTION:
//
//   Client application stub routine for attribute
//   INVENT::Stub_Item::itemInfo. (Interface : Item)
INVENT::itemStruct * INVENT::Stub_Item::itemInfo ( )
{
. . .
}
//
// ROUTINE NAME:      INVENT::Stub_Item::itemInfo
//
// FUNCTIONAL DESCRIPTION:
//
//  Client application stub routine for attribute
//  INVENT::Stub_Item::itemInfo. (Interface : Item)
void INVENT::Stub_Item::itemInfo (
  const INVENT::itemStruct & itemInfo)
{
}