The CORBA standard defines the IDL to C++ mapping. Table 1 lists the rules for each data type, starting with the IDL basic types and then describing each complex type.
| IDL | C++ Typedefs |
|---|---|
short |
CORBA::Short |
long |
CORBA::Long |
unsigned short |
CORBA::UShort |
unsigned long |
CORBA::ULong |
float |
CORBA::Float |
double |
CORBA::Double |
char |
CORBA::Char |
boolean |
CORBA::Boolean |
octet |
CORBA::Octet |
Table 2 describes how C++ Typedefs map to C++ types.
| CORBA C++ Typedefs | C++ Types |
|---|---|
CORBA::Short |
short |
CORBA::Long |
long |
CORBA::UShort |
unsigned short |
CORBA::ULong |
unsigned long |
CORBA::Float |
float |
CORBA::Double |
double |
CORBA::Char |
char |
CORBA::Boolean |
unsigned char |
CORBA::Octet |
unsigned char |
The C++ namespace CORBA contains some built-in application-independent definitions used by C++ clients and servers. (If the chosen C++ compiler does not support namespaces, a C++ class, CORBA, is used instead.) Putting these definitions in a C++ namespace (or class) means that their names do not clash with names used in any other library or application.
An enum in IDL is mapped to the equivalent C++ enum. Hence the IDL definition
enum symbolRep {CPQ};
maps to
enum symbolRep {CPQ};
Basic types passed as a parameter to an operation or appears as the return type require the corresponding C++ formal parameter types as shown. The rules are very simple: out and inout parameters are passed by reference so that the called function can change them, and in parameters and return values are passed by value.
| IDL type | in | out | inout | return |
|---|---|---|---|---|
short |
CORBA::Short |
CORBA::Short& |
CORBA::Short& |
CORBA::Short |
long |
CORBA::Long |
CORBA::Long& |
CORBA::Long& |
CORBA::Long |
unsigned short |
CORBA::UShort |
CORBA::UShort& |
CORBA::UShort& |
CORBA::UShort |
unsigned long |
CORBA::ULong |
CORBA::ULong& |
CORBA::ULong& |
CORBA::ULong |
float |
CORBA::Float |
CORBA::Float& |
CORBA::Float& |
CORBA::Float |
double |
CORBA::Double |
CORBA::Double& |
CORBA::Double& |
CORBA::Double |
char |
CORBA::Char |
CORBA::Char& |
CORBA::Char& |
CORBA::Char |
boolean |
CORBA::Boolean |
CORBA::Boolean& |
CORBA::Boolean& |
CORBA::Boolean |
Enum E |
E |
E& |
E& |
E |
octet |
CORBA::Octet |
CORBA::Octet& |
CORBA::Octet& |
CORBA::Octet |
See Passing Object References as Parameters for information on how to pass references to objects as parameters.
Because the basic types in IDL do not map to pointer types in C++, the memory management issues are straightforward when basic types are passed as in, out, or inout parameters or as return values in C++. Examples are shown in the following sections. For more information, refer to Memory Management for Object References.
Consider the interface:
interface W { void op(in long l);}
A C++ client of this interface simply passes a CORBA::Long value, for example:
W_var C = ...; CORBA::Long l = 23456; C->op(l);
The implementation of operation C::op( ) can be coded as follows:
void C_i::op(CORBA::Long l)
throw (CORBA::SystemException){
cout << 1;
}
Given the following interface:
interface W { float op (out char x);
A C++ client of this interface can use it as follows:
W_var C = ...; CORBA::Char x; CORBA::Float f; f = C->op(x);
The implementation of operation W::op ( ) can be coded as follows:
CORBA::Float W_i::op(CORBA::Char& x)
throw (CORBA::SystemException){
...;
return 1.234;
}
An example interface:
interface W { void op (inout Boolean b1);
A C++ client of this interface passes a value that may be updated by the target object:
W_var C
CORBA::Boolean b1=1; // Pass 'true' to op1
C->op(b1);
If (b1) { }
The implementation of operation w::op( ) may be coded as follows:
void W_i::op(CORBA::Boolean& b1)
throw (CORBA::SystemException){
if (b1) cout << "b1 is true" >>endl;
b = 0; return;
}