Orxonox  0.0.5 Codename: Arcturus
Classes | Namespaces | Macros | Variables
Super.h File Reference

Definition of all super-function related macros, used to call functions of the base class. More...

#include "core/CorePrereqs.h"
#include "util/Output.h"

Go to the source code of this file.

Classes

struct  orxonox::SuperFunctionCondition< functionnumber, T, templatehack1, templatehack2 >
 Creates the SuperFunctionCaller if T is a child of the super-functions baseclass. More...
 
struct  orxonox::SuperFunctionDestruction< functionnumber, T >
 Deletes the SuperFunctionCaller. More...
 
struct  orxonox::SuperFunctionInitialization< functionnumber, T >
 Initializes the SuperFunctionCaller-pointer with zero. More...
 

Namespaces

 orxonox
 Die Wagnis Klasse hat die folgenden Aufgaben:
 

Macros

#define SUPER(classname, functionname, ...)   SUPER_##functionname(classname, functionname, __VA_ARGS__)
 SUPER-macro: Calls Parent::functionname(...) where Parent is the direct parent of classname. More...
 
#define SUPER_ARGS(classname, functionname, ...)   (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this, __VA_ARGS__)
 
#define SUPER_CALL_ARGUMENTS0(...)   Identifiable* object
 
#define SUPER_CALL_ARGUMENTS1(...)   Identifiable* object, __VA_ARGS__
 
#define SUPER_CALL_ARGUMENTSfalse(...)   Identifiable* object
 
#define SUPER_CALL_ARGUMENTStrue(...)   Identifiable* object, __VA_ARGS__
 
#define SUPER_changedActivity(classname, functionname, ...)   SUPER_NOARGS(classname, functionname)
 
#define SUPER_changedCarrier(classname, functionname, ...)   SUPER_NOARGS(classname, functionname)
 
#define SUPER_changedName(classname, functionname, ...)   SUPER_NOARGS(classname, functionname)
 
#define SUPER_changedOverlayGroup(classname, functionname, ...)   SUPER_NOARGS(classname, functionname)
 
#define SUPER_changedOwner(classname, functionname, ...)   SUPER_NOARGS(classname, functionname)
 
#define SUPER_changedPickedUp(classname, functionname, ...)   SUPER_NOARGS(classname, functionname)
 
#define SUPER_changedScale(classname, functionname, ...)   SUPER_NOARGS(classname, functionname)
 
#define SUPER_changedUsed(classname, functionname, ...)   SUPER_NOARGS(classname, functionname)
 
#define SUPER_changedVisibility(classname, functionname, ...)   SUPER_NOARGS(classname, functionname)
 
#define SUPER_FUNCTION(functionnumber, baseclass, functionname, purevirtualbase)
 Declares a new super-function by creating a specialized template. More...
 
#define SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(functionnumber, functionname, hasarguments, ...)
 Creates the needed objects and templates to call a super-function. More...
 
#define SUPER_FUNCTION_GLOBAL_DECLARATION_PART2
 
#define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND0(functionnumber, baseclass)   SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDfalse(functionnumber, baseclass)
 
#define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND1(functionnumber, baseclass)   SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDtrue(functionnumber, baseclass)
 
#define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDfalse(functionnumber, baseclass)
 
#define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDtrue(functionnumber, baseclass)
 
#define SUPER_NOARGS(classname, functionname)   (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this)
 
#define SUPER_tick(classname, functionname, ...)   SUPER_ARGS(classname, functionname, __VA_ARGS__)
 
#define SUPER_XMLEventPort(classname, functionname, ...)   SUPER_ARGS(classname, functionname, __VA_ARGS__)
 
#define SUPER_XMLPort(classname, functionname, ...)   SUPER_ARGS(classname, functionname, __VA_ARGS__)
 

Variables

mode orxonox::SUPER_FUNCTION_GLOBAL_DECLARATION_PART2
 
 orxonox::xmlelement
 

Detailed Description

Definition of all super-function related macros, used to call functions of the base class.

This file 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 parent-class gets called. This is comparable to super.functionname(arguments) 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, there's no limitation for their number and type, except that the type has to be known in Super.h.

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

  1. Add a new SUPER macro
    This allows you to call the super-function in your code.
    Location: This file (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: This file (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: This file (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 back-dependencies, include loops and slower compilation.
    Dont forget to include Super.h in the header-file.
    Location: The header-file of the baseclass (Baseclass.h), below the class declaration

Macro Definition Documentation

#define SUPER (   classname,
  functionname,
  ... 
)    SUPER_##functionname(classname, functionname, __VA_ARGS__)

SUPER-macro: Calls Parent::functionname(...) where Parent is the direct parent of classname.

#define SUPER_ARGS (   classname,
  functionname,
  ... 
)    (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this, __VA_ARGS__)
#define SUPER_CALL_ARGUMENTS0 (   ...)    Identifiable* object
#define SUPER_CALL_ARGUMENTS1 (   ...)    Identifiable* object, __VA_ARGS__
#define SUPER_CALL_ARGUMENTSfalse (   ...)    Identifiable* object
#define SUPER_CALL_ARGUMENTStrue (   ...)    Identifiable* object, __VA_ARGS__
#define SUPER_changedActivity (   classname,
  functionname,
  ... 
)    SUPER_NOARGS(classname, functionname)
#define SUPER_changedCarrier (   classname,
  functionname,
  ... 
)    SUPER_NOARGS(classname, functionname)
#define SUPER_changedName (   classname,
  functionname,
  ... 
)    SUPER_NOARGS(classname, functionname)
#define SUPER_changedOverlayGroup (   classname,
  functionname,
  ... 
)    SUPER_NOARGS(classname, functionname)
#define SUPER_changedOwner (   classname,
  functionname,
  ... 
)    SUPER_NOARGS(classname, functionname)
#define SUPER_changedPickedUp (   classname,
  functionname,
  ... 
)    SUPER_NOARGS(classname, functionname)
#define SUPER_changedScale (   classname,
  functionname,
  ... 
)    SUPER_NOARGS(classname, functionname)
#define SUPER_changedUsed (   classname,
  functionname,
  ... 
)    SUPER_NOARGS(classname, functionname)
#define SUPER_changedVisibility (   classname,
  functionname,
  ... 
)    SUPER_NOARGS(classname, functionname)
#define SUPER_FUNCTION (   functionnumber,
  baseclass,
  functionname,
  purevirtualbase 
)

Declares a new super-function by creating a specialized template.

Add this below the class declaration of the baseclass.

Parameters
functionnumberEach super-function needs a unique number, starting with zero, increasing by one
baseclassThe baseclass of the super-function (~the root)
functionnameThe name of the super-function
purevirtualbase"true" if the function is pure virtual in the baseclass, "false" if the function is implemented (without "")
#define SUPER_FUNCTION_GLOBAL_DECLARATION_PART1 (   functionnumber,
  functionname,
  hasarguments,
  ... 
)

Creates the needed objects and templates to call a super-function.

Parameters
functionnumberEach super-function needs a unique number, starting with zero, increasing by one
functionnameThe name of the super-function
hasarguments"false" if the function doesn't take any arguments, "true" if it does (without "")
...Variadic: If the function takes arguments, add them here with type and name. Example: int myvalue, float myothervalue
#define SUPER_FUNCTION_GLOBAL_DECLARATION_PART2
Value:
; \
} \
\
Identifier* getParentIdentifier() const \
{ \
return ClassIdentifier<T>::getIdentifier(); \
} \
};
#define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND0 (   functionnumber,
  baseclass 
)    SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDfalse(functionnumber, baseclass)
#define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND1 (   functionnumber,
  baseclass 
)    SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDtrue(functionnumber, baseclass)
#define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDfalse (   functionnumber,
  baseclass 
)
#define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDtrue (   functionnumber,
  baseclass 
)
Value:
template <int templatehack2> \
struct SuperFunctionCondition<functionnumber, baseclass, 0, templatehack2> \
{ \
static void superCheck() \
{ \
SuperFunctionCondition<functionnumber + 1, baseclass, 0, templatehack2>::superCheck(); \
} \
};
#define SUPER_NOARGS (   classname,
  functionname 
)    (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this)
#define SUPER_tick (   classname,
  functionname,
  ... 
)    SUPER_ARGS(classname, functionname, __VA_ARGS__)
#define SUPER_XMLEventPort (   classname,
  functionname,
  ... 
)    SUPER_ARGS(classname, functionname, __VA_ARGS__)
#define SUPER_XMLPort (   classname,
  functionname,
  ... 
)    SUPER_ARGS(classname, functionname, __VA_ARGS__)