C++ provides the hierarchical class mechanism, where
derived classes inherit (some) of the
functions and variables of their
base class. This feature is heavily used
within SystemC—for example all module classes are derived
classes of the SystemC base class,
sc_module
.
The SystemC models in each section of this application note are built using derived classes of the models from previous sections.
Those functions and variables which other classes will use are
declared as public
. For SystemC modules this
usually means the constructor and any SystemC ports or
sockets. Occasionally there are some utility functions which are
also made public (see for example
Or1ksimExt::isLittleEndian
in Section 6.3)[2].
Variables and functions in classes that are not for use by other
classes, but are required in derived classes are declared as
protected
(i.e. visible to derived classes).
The remaining functions and variables, which are for use only by the
current class, are declared private
(visible only
to this class). This avoids any unplanned reuse by derived classes.
Some of the functions will be reimplemented in later derived
classes. Such functions are also declared virtual
.
In summary public
functions and variables may be
used by any other class, protected
functions and
variables may be used only by this class and
any derived classes and private
functions and
variables may be used only by this class. virtual
functions may be reimplemented in derived
classes.
[2]
Object oriented purists prefer to expose only class functions as
the public
interface, so hiding all state
implementation from external view. There is considerable merit
in this, but the common SystemC convention is to expose actual
ports or sockets, rather than accessor functions for those
objects. This application note follows this practice.