The topic describes IDL mapping for interfaces, modules, and constants, and describes scoped names.
An IDL interface maps to a C++ class. For example:
interface W { attribute long l; readonly attribute char c; void op1( ); }
maps to
class W : public virtual CORBA::Object { CORBA::Long l( ) throw (CORBA::SystemException); void l(CORBA::Long) throw (CORBA::SystemException); CORBA::Char c; virtual void ap1( ) throw (CORBA::SystemException); }
Each operation maps to a member function; each normal attribute maps to two member functions to read and modify the attribute value and each readonly attribute maps to one member function to read the attribute value.
The IDL compiler also adds a number of member and static functions. Class W inherits from the system-provided class CORBA::object
, which acts as the uppermost root class for all CORBA objects. A reference of type of CORBA::Object_ptr
or CORBA::Object_var
can reference any CORBA object.
The same mapping is used for both normal and oneway operations. However, the IDL compiler ensures that each oneway operation has no return value, no out
or inout
parameters, and no raises clause. On the client side, the generated C++ stub does not wait for a reply from the target object.
When an IDL type definition is made within an interface definition, the corresponding C++ type appears within the generated C++ class and its name is therefore scoped by the name of that class. Consider the IDL definition:
interface W { enum e {a,b,c); struct nested1 {...} }
This is translated into the following C++:
class W : public virtual CORBA::Object { enum e {able}; struct nested1; }
This gives the scoped names W::e
and W::nested1
, and these must be used instead of the simple names e
and nested1
.
IDL modules are Mapped to C++ namespaces. Consider:
module M { typedef float money; interface I { ... } };
This is translated into:
namespace M { typedef CORBA::Float money; class I :public virtual CORBA::Object { } }
Therefore, the scoped name of the interface is M::I
.
Tandem's D42 C++ compiler does not support namespaces, in which case namespace M
is replaced with class M
.
Constants that are defined globally in an IDL file are translated directly into their C++ equivalents. Therefore, the following code
const long MaxLen = 4;
maps to the following C++ definition
const CORBA::Long MaxLen = 4;
Constants defined in IDL interfaces must map to both a declaration (within the generated C++ class) and a definition at the C++ file level. Hence, the following code
interface I { const long MaxLen = 4; ... }
maps to
class I : public virtual CORBA::Object { static const CORBA::Long MaxLen; ... }
and the following definition at the C++ file level:
const CORBA::Long I::MaxLen = 4;