Chapter 15 CORBA C++ Overview


Supported datatypes

Jaguar follows the OMG standard for translating CORBA IDL to C++, more specifically, refer to C++ Language Mapping Specification (formal/99-07-41). You can download this document from the OMG Web site .

The standard supports all the C++ features in the Annotated C++ Reference Manual by Ellis and Stroustrup as implemented by the ANSI/ISO C++ standardization committees. In addition, the namespace construct is supported. Templates are not required but can be used.

IDL modules are mapped to C++ namespaces and IDL interfaces are mapped to C++ classes. All OMG IDL constructs scoped to an interface are accessed through C++-scoped-names. For example, the IDL interface CtsComponents::ThreadManager maps to the C++ class CtsComponents::ThreadManager. If your C++ compiler supports namespaces, you can use the namespace directive and refer to the interface name by itself, as in:

using namespace CtsComponents;
...
ThreadManager threadMan;

Mapping for predefined Jaguar Manager datatypes

Table 15-1 lists the datatypes in Jaguar Manager, the equivalent CORBA IDL types, and the C++ datatypes used in stub methods. You can also define additional types in IDL; when you generate stubs and skeletons, these are translated to C++ types using the standard CORBA IDL to C++ type mappings. For example, The BCD and MJD CORBA IDL modules define types to represent binary data, fixed-point numeric data, dates, and times. For details, see the generated Interface Repository documentation for these IDL modules.

Table 15-1: Jaguar Manager, CORBA IDL, and C++ datatype mappings

Jaguar Manager

CORBA IDL type

Argument mode

IDL C++ type

integer<16>

short

in
inout
out
return

CORBA::Short
CORBA::Short&
CORBA::Short_out
CORBA::Short

integer<32>

long

in
inout
out
return

CORBA::Long
CORBA::Long&
CORBA::Long_out
CORBA::Long

integer<64>

long long

in
inout
out
return

CORBA::LongLong
CORBA::LongLong&
CORBA::LongLong_out
CORBA::LongLong

Note   Define JAG_LONGLONG Because there is no standard C++ type for an signed 64-bit integer, you must define the JAG_LONGLONG macro as your compiler's type for a signed 64-bit integer.

float

float

in
inout
out
return

CORBA::Float
CORBA::Float&
CORBA::Float_out
CORBA::Float

double

double

in
inout
out
return

CORBA::Double
CORBA::Double&
CORBA::Double_out
CORBA::Double

boolean

boolean

in
inout
out
return

CORBA::Boolean
CORBA::Boolean&
CORBA::Boolean_out
CORBA::Boolean

string

string

in
inout
out
return

char*
char*&
CORBA::String_out
char*

binary

BCD::Binary

in
inout
out
return

BCD::Binary&
BCD::Binary&
BCD::Binary_out
BCD::Binary*

decimal

BCD::Decimal

in
inout
out
return

BCD::Decimal&
BCD::Decimal&
BCD::Decimal_out
BCD::Decimal*

money

BCD::Money

in
inout
out
return

BCD::Money&
BCD::Money&
BCD::Money_out
BCD::Money*

date

MJD::Date

in
inout
out
return

MJD::Date&
MJD::Date&
MJD::Date_out
MJD::Date

time

MJD::Time

in
inout
out
return

MJD::Time&
MJD::Time&
MJD::Time_out
MJD::Time

timestamp

MJD::Timestamp

in
inout
out
return

MJD::Timestamp&
MJD::Timestamp&
MJD::Timestamp_out
MJD::Timestamp

ResultSet

TabularResults::
ResultSet

return

TabularResults::ResultSet*

ResultSets

TabularResults::
ResultSets

return

TabularResults::ResultSets*

Using mapped IDL types

All Jaguar component interfaces are defined in standard CORBA IDL, and C++ stubs and skeletons use the standard CORBA IDL-to-C++ type mappings.

For local variables that map to constructed C++ types and do not represent an IDL interface, use the C++ datatype that is appended with _var. _var variables are automatically freed when they are out of scope. If you do not use the _var type, references must be freed with the C++ delete operator. In Table 15-1, string, binary, decimal, money, date, time, timestamp, ResultSet, and ResultSets have _var types. Other types listed in Table 15-1 map to fixed-length C++ types. For fixed-length types, use the base C++ type.

IDL interfaces map to C++ classes that extend the CORBA::Object class. These object reference types have a _var form for references with automatic memory management, and a _ptr form for references that must remain valid after the reference variable goes out of scope. _ptr references must be freed by calling CORBA::release.

You must pass values in a _var type as follows:

MyType_var v;
....
v.in() // Passes v as an in // parameter.
v.inout() // Passes v as an inout // parameter.
v.out() // Passes v as an out // parameter.
return v._retn() // Passes v as a return value.

Note   Do not use the C++ _out types for local variables; these types are reserved for method signatures.

For out and inout parameters of IDL type string, use CORBA::string_alloc or CORBA::string_dup to allocate memory for them. For example:

ItemName = CORBA::string_dup("Dummy Item Name");
ItemData = CORBA::string_dup("Dummy Item Data");

In C++, if you declare string variables as type CORBA::String_var, memory allocated by CORBA::string_dup or CORBA::string_alloc is freed automatically. Otherwise, declare as char * and free the memory explicitly by calling CORBA::string_free.

You can pass a null value as a parameter type only with the object reference type Module::Interface::_nil().

Overloaded methods

Overloading methods is supported for C++ components. When you overload a method, you use the same name for several methods that specify different parameters. When you call an overloaded method, the method with the corresponding parameters is executed. See "Operation declarations" for more information.

 


Copyright © 2000 Sybase, Inc. All rights reserved.