Planet
navi homeaboutscreenshotsdownloaddevelopmentforum

Super

TracNav(TracNav/TOC_Development)?

Description

Super.h defines all macros needed to add a new "super-function". If you add a super-function, you can call SUPER(myclass, functionname, arguments) inside your code and the function of the parentclass gets called. This is comparable with super.functionname() in Java or other languages.

This works only with virtual functions that return nothing (void) and belong to classes that have an Identifier. Arguments however are supported.

Add a new super-function

To add a new super-function, you have process 4 steps:

  1. Add a new SUPER macro:
    This allows you to call the super-function in your code.
    Location: core/Super.h, marked with —> HERE ←- comments (1/3)

  2. Call the SUPER_FUNCTION_GLOBAL_DECLARATION_PART1/2 macros.
    This defines some global classes and templates, needed to create and call the super-functions.
    Location: core/Super.h, marked with —> HERE ←- comments (2/3)

  3. Call the SUPER_INTRUSIVE_DECLARATION macro.
    This will be included into the declaration of ClassIdentifier<T>.
    Location: core/Super.h, marked with —> HERE ←- comments (3/3)

  4. Call the SUPER_FUNCTION macro.
    This defines a partially specialized template that will decide if a class is "super" to another class. If the check returns true, a SuperFunctionCaller? gets created, which will be used by the SUPER macro. You have to add this into the header-file of the baseclass of the super-function (the class that first implements the function), below the class declaration. You can't call it directly in this file, because otherwise you had to include the headerfile right here, which would cause some ugly backdependencies, include loops and slower compilation.
    Dont forget to include core/Super.h in the header-file.
    Location: The header-file of the baseclass (core/Baseclass.h), below the class declaration

Call a super-function

Example: mySuperFunction(int value) was declared as a super-function by following the previous steps. This is how you use SUPER:

*.h File:

class BaseClass
{
    virtual void mySuperFunction(int value);
};

class DerivedClass : public BaseClass
{
    virtual void mySuperFunction(int value);
};

*.cc File:

void BaseClass::mySuperFunction(int value)
{
   ...
}

void DerivedClass::mySuperFunction(int value)
{
    SUPER(DerivedClass, mySuperFunction, value);

    // This is equivalent to:
    // BaseClass::mySuperFunction(value);
}

The advantage is that you don't have to write "BaseClass?" to call the super-function but "DerivedClass?". This means you don't have to rely on the class hierarchy.

Last modified 8 years ago Last modified on Oct 1, 2008, 2:52:45 AM