Chapter 15 CORBA C++ Overview
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;
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.
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.
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().
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. |