Messages in C++

Description

The C++ API is a rich class hierarchy that corresponds to the set of EXS and SwitchKit messages that can be sent to the CSP. The class hierarchy lends structure and organization to these messages, as shown in the C++ Class Hierarchy diagram. Macros corresponding to the C macros are provided for the C++ message classes. These macros allow easy branching, based on the type of message received.

SKC_BaseObject

This class is the base of the class hierarchy tree. As delivered in the API, it does not derive from any other class. SKC_BaseObject implements a basic mechanism for determining if a given object is derived from a particular class. The desc() virtual function returns a static object pointer that is different for each class. By calling isKindOf(), the SKC_ClassDesc of a given class is compared against the desc() of the given object and all of its base classes. If isKindOf() returns true, then the type cast to the given type is safe.

Example

SKC_BaseObject *obj = getObject();

if (obj->isKindOf(&SKC_ToolkitMessage:desc())) {

SKC_ToolkitMessage *tkitMsg = (SKC_ToolkitMessage *) obj;

processToolkitMessage(tkitMsg);

}

Class Definition Macros

Every class defined in the SwitchKit C++ API contains an invocation of a macro both in its class declaration (the .h file) and in its class definition (the C file). As distributed, these macros complete the implementation of the class derivation testing mechanism.

The macro invoked in the header file is SK_DECLARE_CLASS(cls, base). The first argument is the name of the class that the macro invocation appears in, and the second argument is its base class. SK_DEFINE_CLASS(cls) is invoked in the implementation file of the class—once for each class defined by the API with an argument of that class name.

For example, if you want to add a trivial print() function so that all of the classes know how to print themselves, SK_DECLARE_CLASS could be appended with the following:

#define SK_DECLARE_CLASS(cls,base) \

virtual void print() {cout << "Object of type" << #cls; } \

...

In the above example, it is assumed that #cls is interpreted by the processor to substitute in the value of the cls argument, enclosed in quotes.