Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/doc/Super


Ignore:
Timestamp:
Oct 1, 2008, 2:52:45 AM (11 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Super

    v1 v1  
     1= Super =
     2[[TracNav(TracNav/TOC_Development)]]
     3
     4== Description ==
     5Super.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
     6super.functionname() in Java or other languages.
     7
     8This works only with virtual functions that return nothing (void) and belong to classes that have an Identifier. Arguments however are supported.
     9
     10
     11== Add a new super-function ==
     12To add a new super-function, you have process 4 steps:
     13
     14 1. '''Add a new SUPER macro''':[[br]]
     15    This allows you to call the super-function in your code.[[br]]
     16    Location: core/Super.h, marked with --> HERE <-- comments (1/3)[[br]][[br]]
     17 1. '''Call the SUPER_FUNCTION_GLOBAL_DECLARATION_PART1/2 macros.'''[[br]]
     18    This defines some global classes and templates, needed to create and call the super-functions.[[br]]
     19    Location: core/Super.h, marked with --> HERE <-- comments (2/3)[[br]][[br]]
     20 1. '''Call the SUPER_INTRUSIVE_DECLARATION macro.'''[[br]]
     21    This will be included into the declaration of !ClassIdentifier<T>.[[br]]
     22    Location: core/Super.h, marked with --> HERE <-- comments (3/3)[[br]][[br]]
     23 1. '''Call the SUPER_FUNCTION macro.'''[[br]]
     24    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.[[br]]
     25    Dont forget to include core/Super.h in the header-file.[[br]]
     26    Location: The header-file of the baseclass (core/Baseclass.h), below the class declaration[[br]]
     27
     28== Call a super-function ==
     29Example: mySuperFunction(int value) was declared as a super-function by following the previous steps. This is how you use SUPER:
     30
     31*.h File:
     32{{{
     33class BaseClass
     34{
     35    virtual void mySuperFunction(int value);
     36};
     37
     38class DerivedClass : public BaseClass
     39{
     40    virtual void mySuperFunction(int value);
     41};
     42}}}
     43
     44*.cc File:
     45{{{
     46void BaseClass::mySuperFunction(int value)
     47{
     48   ...
     49}
     50
     51void DerivedClass::mySuperFunction(int value)
     52{
     53    SUPER(DerivedClass, mySuperFunction, value);
     54
     55    // This is equivalent to:
     56    // BaseClass::mySuperFunction(value);
     57}
     58}}}
     59
     60The 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.