Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

27.4 Macros that Create Insertion and Extraction Operators For You

Although the orb library RWreqistream and RWreqostream classes insulate developers from having to read and write directly to the CORBA::Request, it is still necessary to write the actual insertion and extraction operators for the CORBA::Request.

27.4.1 The Insertion and Extraction Operators

The insertion operator, operator<<(), marshals the opaque object's state into a CORBA::Request for transmission to a remote process. The extraction operator, operator>>(), unmarshals an opaque object which is received from a remote process in a CORBA::Request.

For our example Book class, these operators look like this:

27.4.2 RWDEFINE_OPAQUE and RWDEFINE_OPAQUE_COLLECTABLE

As you can imagine, writing these operators for every class you want to pass as an opaque type would be tedious. To counter this, the orb library provides two macros that create the CORBA::Request insertion and extraction operations for you:

Since many Rogue Wave classes already define virtual stream operations, or inherit from RWCollectable and implement the saveGuts() and restoreGuts() operations, they can be passed easily as opaque types using RWDEFINE_OPAQUE and RWDEFINE_OPAQUE_COLLECTABLE.

These definitions must be provided for both the client and the server. You can either call the macro in the same source file as the opaque C++ class, or you can create an include file that just contains the macro call. Then include the file in both the client and server executables.

27.4.3 Example of RWDEFINE_OPAQUE

Given the Library interface, assume that Book inherits from RWCollectable and implements the saveGuts and restoreGuts methods:

Also assume that the Borrower class implements (as friend functions) the insertion and extraction operators for virtual streams. For example:

Given these assumptions, two simple C++ files could be written to implement the operations, required by the ORB, for those types to be passed as opaque objects. For Book, you could write a file called bookio.cpp, as follows:

For Borrower, you could write a similar file, called borrowio.cpp:

These files would then be compiled and linked into both the client and the server portions of the program.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.