Given the output of a Classdesc class definition file (.cd
file), the purpose of a translator is to auto-generate an equivalent
Objective-C object template and all the necessary Objective-C to C++
interfacing functions. To construct a translator, we need the following
files: the output file from the Classdesc (eg. myCounter.cd
file), translator main program file (Figure 11), a user C++
model (eg. myCounter.h
and myCounter.cc
files), and the
Classdesc base-action definition file (writeobjc_base.h
).
During the compilation of an Objective-C translator, the class name
is passed to the translator by a preprocessor macro, set on the
compiler command line (eg: -DCNAME=myCounter
) to enable the
translator to include appropriate .h
and .cd
files. When the
compilation completed, a translator called write_objc
is created. When
this translator is executed, it will create an equivalent Objective-C
object template and all the necessary interfacing functions.
During the execution of the translator, it creates an instance of the
user model (or object) and recursively calls the writeobjc action on
all its member variables and functions for Objective-C
translation. When the translator finishes its execution, three
interface files are created: the Objective-C object definition file
(eg. myCounter.mh
), the Objective-C object implementation file
(eg. myCounter.m
) and the Objective-C calls to C++ methods
interface file (myCounterExportCpp.cc
file). Since
writeobjc
is recursive, it is only necessary to perform this
process once, on a top level C++ class.