Basic Steps for Implementing SOM Classes
Implementing and using SOM classes in C or C++ involves the following steps,
which are explicitly illustrated in the examples of this tutorial:
- Define the interface to objects of the new class
(that is, the interface declaration), by creating a .idl file.
- Run the SOM Compiler on the .idl file (by issuing
the sc command on AIX or OS/2, or by issuing the somc command
on Windows) to produce the following binding files:
- Template implementation file
a .c file for C programmers, or
a .C file (on AIX) or a .cpp file (on OS/2 or Windows) for
C++ programmers;
- Header file to be included in the implementation
file
a .ih file for C programmers, or
a .xih file for C++ programmers; and
- Header file to be included in client programs that
use the class
a .h file for C clients, or
a .xh file for C++ clients.
To specify whether
the SOM Compiler should produce C or C++ bindings, set the value of the
SMEMIT environment variable or use the "-s" option of the sc or
somc command, as described in Section 4.3, "The SOM Compiler." By
default, the SOM Compiler produces C bindings.
3.
Customize
the implementation, by adding code to the template implementation file.
4.
Create a client program
that uses the class.
5.
Compile
and link the client code with the class implementation, using a C or C++
compiler.
6.
Execute the
client program.
The following examples illustrate appropriate syntax for defining interface
declarations in a .idl file, including designating the methods that the
class's instances will perform. In addition, example template implementation
files contain typical code that the SOM Compiler produces. Explanations
accompanying each example discuss topics that are significant to the particular
example; full explanations of the SOM IDL syntax are contained in Chapter
4, "SOM IDL and the SOM Compiler." Customization of each implementation
file (step 3) is illustrated in C and C++.
Note:
- The Tutorial assumes you will work through the
examples in order. If you do not do so, the code that the SOM Compiler generates
from your revised .idl file may vary slightly from what you see in the Tutorial.
- When the SOMobjects Toolkit is installed, a choice
is made between "somcorba" and "somstars" for the style of C bindings the
SOM Compiler will generate. The Tutorial examples use the "somcorba" style,
where an interface name used as a type indicates a pointer to an object,
as required by strict CORBA bindings. Consequently, as the examples show,
a "*" does not explicitly appear for types that are pointers to objects.
If your system was installed for "somstars" C bindings, you can set the
environment variable SMADDSTAR=1 or use the SOM Compiler option "-maddstar"
to request bindings that use explicit pointer stars. For more information,
see "Declaring object variables" in Chapter 3, "Using SOM Classes in Client
Programs" and "Object types" in Chapter 4, "SOM IDL and the SOM Compiler."
[Back: Development of the Tutorial examples]
[Next: Example 1-Implementing a Simple Class with One Method]