Appendix B Creating Wrapped Classes

B.1 Wrap Script Model

There are essentially three parts to publishing a class: publishing its name, publishing its members, and publishing its methods.[18] This information is necessary for AM2 to create a subclass, instantiate a class, and operate on a C++ class. You provide the information by writing a wrap file that describes the class to be wrapped. Once it is written, you run the wrap script, sometimes referred to as the wrapper, and generate the wrapped class.

For instance, to wrap a C++ class called IntStack as a wrapped class called DSIntStack, you write a file called DSIntStackRO.wrp and run the wrap script. The wrapper generates the class named DSIntStackRO, writing the files DSintStackRO.h to declare it and DSintStackRO.cc to implement it. The command line interface to the wrap script determines where to place the generated files. It is described in Section B.3.1, "Command Line Interface" page 286.

We call the C++ class that we want to wrap the foundation class. In our example, the class IntStack is the foundation class. We encourage programmers to think of the wrapper class as a translation layer only, turning ADL messages and member assignments into calls to an instance of the foundation class. In the example, when you create an instance of DSintStackRO, the DSintStackRO constructor creates a corresponding IntStack instance. ADL messages such as Push and Pop translate into calls on that instance of IntStack. By making it easy for a wrapped object to use an instance of the foundation class, the wrapper encourages programmers to put very little into the wrapped class.


[18] The wrap script also has an inheritance mechanism that provides an inheritance relationship between wrapped classes and simplifies the specification and maintenance of the wrap code itself. We postpone the description of this mechanism until after we cover the basics.
AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker