Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1684 for code


Ignore:
Timestamp:
Aug 31, 2008, 4:32:31 AM (16 years ago)
Author:
landauf
Message:
  • packed all super-function-related code into a bunch of macros and commented the code.
  • added tick, XMLPort, changedActivity and changedVisibility as super-functions
Location:
code/branches/core3/src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/core/BaseObject.h

    r1592 r1684  
    3939#include "CorePrereqs.h"
    4040
     41#include "Super.h"
     42#include "OrxonoxClass.h"
    4143#include "util/XMLIncludes.h"
    42 #include "OrxonoxClass.h"
    4344
    4445namespace orxonox
     
    6566
    6667            /** @brief Sets the state of the objects activity. @param bActive True = active */
    67             inline void setActivity(bool bActive) { this->bActive_ = bActive; this->changedActivity(); }
     68            inline void setActive(bool bActive) { this->bActive_ = bActive; this->changedActivity(); }
    6869            /** @brief Returns the state of the objects activity. @return The state of the activity */
    6970            inline bool isActive() const { return this->bActive_; }
     
    7273
    7374            /** @brief Sets the state of the objects visibility. @param bVisible True = visible */
    74             inline void setVisibility(bool bVisible) { this->bVisible_ = bVisible; this->changedVisibility(); }
     75            inline void setVisible(bool bVisible) { this->bVisible_ = bVisible; this->changedVisibility(); }
    7576            /** @brief Returns the state of the objects visibility. @return The state of the visibility */
    7677            inline bool isVisible() const { return this->bVisible_; }
     
    101102            Namespace* namespace_;
    102103    };
     104
     105    SUPER_FUNCTION(1, BaseObject, XMLPort, false);
     106    SUPER_FUNCTION(3, BaseObject, changedActivity, false);
     107    SUPER_FUNCTION(4, BaseObject, changedVisibility, false);
    103108}
    104109
  • code/branches/core3/src/core/Identifier.h

    r1683 r1684  
    304304    class ClassIdentifier : public Identifier
    305305    {
    306         #define SUPER_INTRUSIVE_DECLARATION
     306        #define SUPER_INTRUSIVE_DECLARATION_INCLUDE
    307307        #include "Super.h"
    308308
     
    320320            ClassIdentifier()
    321321            {
    322                 #define SUPER_INTRUSIVE_CONSTRUCTOR
     322                #define SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE
    323323                #include "Super.h"
    324324            }
    325325            ~ClassIdentifier()
    326326            {
    327                 #define SUPER_INTRUSIVE_DESTRUCTOR
     327                #define SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE
    328328                #include "Super.h"
    329329            }
  • code/branches/core3/src/core/Namespace.cc

    r1505 r1684  
    6060    void Namespace::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6161    {
    62         BaseObject::XMLPort(xmlelement, mode);
     62//        BaseObject::XMLPort(xmlelement, mode);
     63        SUPER(Namespace, XMLPort, xmlelement, mode);
    6364
    6465        std::string name = this->getName();
  • code/branches/core3/src/core/Super.h

    r1683 r1684  
    2727 */
    2828
     29/**
     30    @file Super.h
     31    @brief Definition of all super-function related macros.
     32
     33    This file defines all macros needed to add a new "super-function".
     34    If you add a super-function, you can call SUPER(myclass, functionname) inside your
     35    code and the function of the parentclass gets called. This is comparable with
     36    super.functionname() in Java or other languages.
     37
     38    This works only with virtual functions that return nothing (void) and belong to
     39    classes that have an Identifier. Arguments however are supported.
     40
     41    To add a new super-function, you have process 6 steps:
     42
     43    1) Add a new SUPER macro
     44       This allows you to call the super-function in your code.
     45       Location: This file (Super.h), marked with --> HERE <-- comments (1/5)
     46
     47    2) Call the SUPER_FUNCTION_GLOBAL_DECLARATION_PART1/2 macros.
     48       This defines some global classes and templates, needed to create and call the super-functions.
     49       Location: This file (Super.h), marked with --> HERE <-- comments (2/5)
     50
     51    3) Call the SUPER_INTRUSIVE_DECLARATION macro.
     52       This will be included into the declaration of ClassIdentifier<T>.
     53       Location: This file (Super.h), marked with --> HERE <-- comments (3/5)
     54
     55    4) Call the SUPER_INTRUSIVE_CONSTRUCTOR macro.
     56       This will be included into the constructor of ClassIdentifier<T>.
     57       Location: This file (Super.h), marked with --> HERE <-- comments (4/5)
     58
     59    5) Call the SUPER_INTRUSIVE_DESTRUCTOR macro.
     60       This will be included into the destructor of ClassIdentifier<T>.
     61       Location: This file (Super.h), marked with --> HERE <-- comments (5/5)
     62
     63    6) Call the SUPER_FUNCTION macro.
     64       This defines a partially specialized template that will decide if a class is "super" to another class.
     65       If the check returns true, a SuperFunctionCaller gets created, which will be used by the SUPER macro.
     66       You have to add this into the header-file of the baseclass of the super-function (the class that first
     67       implements the function), below the class declaration. You can't call it directly in this file, because
     68       otherwise you had to include the headerfile right here, which would cause some ugly backdependencies,
     69       include loops and slower compilation.
     70       Dont forget to include Super.h in the header-file.
     71       Location: The header-file of the baseclass (Baseclass.h), below the class declaration
     72*/
     73
    2974#ifndef _Super_H__
    3075#define _Super_H__
     
    3277#include <iostream>
    3378
    34 //////////////////
    35 // Common macro //
    36 //////////////////
    37 #define SUPER(classname, functionname, ...) \
    38     SUPER_##functionname(classname, functionname, __VA_ARGS__)
    39 
    40 /////////////////////////////
    41 // Function-specific macro //
    42 /////////////////////////////
    43 #define SUPER_testfunction(classname, functionname, ...) \
    44     (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this)
     79#include "CorePrereqs.h"
     80
     81#include "util/Debug.h"
     82#include "util/XMLIncludes.h"
     83
     84///////////////////////
     85// Macro definitions //
     86///////////////////////
     87
     88//// Common macros ////
     89
     90    /**
     91        @brief Declares a new super-function by creating a specialized template. Add this below the class declaration of the baseclass.
     92        @param functionnumber Each super-function needs a unique number, starting with zero, increasing by one
     93        @param baseclass The baseclass of the super-function (~the root)
     94        @param functionname The name of the super-function
     95        @param purevirtualbase "true" if the function is pure virtual in the baseclass, "false" if the function is implemented (without "")
     96    */
     97    #define SUPER_FUNCTION(functionnumber, baseclass, functionname, purevirtualbase) \
     98        template <class T, int templatehack2> \
     99        struct SuperFunctionCondition<functionnumber, T, 0, templatehack2> \
     100        { \
     101            static void check() \
     102            { \
     103                SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply((T*)0); \
     104                SuperFunctionCondition<functionnumber + 1, T, 0, templatehack2>::check(); \
     105            } \
     106            \
     107            static void apply(void* temp) {} \
     108            static void apply(baseclass* temp) \
     109            { \
     110                ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier(); \
     111                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) \
     112                { \
     113                    if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
     114                    { \
     115                        COUT(0) << "Added SuperFunctionCaller for " << #functionname << ": " << ClassIdentifier<T>::getIdentifier()->getName() << " <- " << ((ClassIdentifier<T>*)(*it))->getName() << std::endl; \
     116                        ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>; \
     117                    } \
     118                } \
     119            } \
     120        }; \
     121        \
     122        SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND##purevirtualbase(functionnumber, baseclass)
     123
     124    #define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND0(functionnumber, baseclass) SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDfalse(functionnumber, baseclass)
     125    #define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND1(functionnumber, baseclass) SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDtrue(functionnumber, baseclass)
     126    #define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDfalse(functionnumber, baseclass)
     127    #define SUPER_FUNCTION_PUREVIRTUAL_WORKAROUNDtrue(functionnumber, baseclass) \
     128        template <int templatehack2> \
     129        struct SuperFunctionCondition<functionnumber, baseclass, 0, templatehack2> \
     130        { \
     131            static void check() \
     132            { \
     133                SuperFunctionCondition<functionnumber + 1, baseclass, 0, templatehack2>::check(); \
     134            } \
     135        };
     136
     137
     138    /*
     139    //// Comments about the macro ////
     140
     141        // Partially specialized template (templatehack is now specialized too).
     142        //
     143        // This ensures the compiler takes THIS template if the header-file of the super-function
     144        // is included. In any other case, the compiler just uses the fallback template which is
     145        // defined in this file.
     146        template <class T, templatehack2>
     147        struct SuperFunctionCondition<functionnumber, T, 0, templatehack2>
     148        {
     149            static void check()
     150            {
     151                // This call to the apply-function is the whole check. By calling the function with
     152                // a T* pointer, the right function get's called.
     153                SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply((T*)0);
     154
     155                // Go go the check for of next super-function (functionnumber + 1)
     156                SuperFunctionCondition<functionnumber + 1, T, 0, templatehack2>::check();
     157            }
     158
     159            // This function gets called if T is not a child of the baseclass.
     160            // The function does nothing.
     161            static void apply(void* temp) {}
     162
     163            // This function gets called if T is a child of the baseclass and can therefore be converted.
     164            // The function adds a SuperFunctionCaller to the Identifier of all subclasses of T.
     165            static void apply(baseclass* temp)
     166            {
     167                ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
     168
     169                // Iterate through all children
     170                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)
     171                {
     172                    // Check if there's not already a caller
     173                    if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)
     174                    {
     175                        // Add the SuperFunctionCaller
     176                        COUT(5) << "adding functionpointer to " << ((ClassIdentifier<T>*)(*it))->getName() << std::endl;
     177                        ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>;
     178                    }
     179                }
     180            }
     181        };
     182        SUPER_FUNCTION_PUREVIRTUAL_WORKAROUND##purevirtualbase
     183
     184
     185        // The following piece of code is only added if purevirtualbase = true
     186
     187        // Explicit specialization of the Condition template for the baseclass to avoid
     188        // errors if the function is pure virtual in the baseclass.
     189        template <int templatehack2> \
     190        struct SuperFunctionCondition<functionnumber, baseclass, 0, templatehack2> \
     191        { \
     192            // The check function just behaves like the fallback - it advances to the check for the next super-function (functionnumber + 1)
     193            static void check() \
     194            { \
     195                SuperFunctionCondition<functionnumber + 1, baseclass, 0, templatehack2>::check(); \
     196            } \
     197        };
     198    */
     199
     200    // SUPER-macro: Calls Parent::functionname() where Parent is the direct parent of classname
     201    #define SUPER(classname, functionname, ...) \
     202        SUPER_##functionname(classname, functionname, __VA_ARGS__)
     203
     204    // helper macro: for functions without arguments
     205    #define SUPER_NOARGS(classname, functionname) \
     206        (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this)
     207
     208    // helper macro: for functions with arguments
     209    #define SUPER_ARGS(classname, functionname, ...) \
     210        (*ClassIdentifier<classname>::getIdentifier()->superFunctionCaller_##functionname##_)(this, __VA_ARGS__)
     211
     212
     213//// Function-specific macros ////
     214
     215    /*
     216        Add a macro for each super-function
     217
     218        Example (no arguments):
     219        #define SUPER_myfunction(classname, functionname, ...) \
     220            SUPER_NOARGS(classname, functionname)
     221
     222        Example (with arguments):
     223        #define SUPER_myfunction(classname, functionname, ...) \
     224            SUPER_ARGS(classname, functionname, __VA_ARGS__)
     225    */
     226
     227    // (1/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     228    #define SUPER_testfunction(classname, functionname, ...) \
     229        SUPER_NOARGS(classname, functionname)
     230
     231    #define SUPER_XMLPort(classname, functionname, ...) \
     232        SUPER_ARGS(classname, functionname, __VA_ARGS__)
     233
     234    #define SUPER_tick(classname, functionname, ...) \
     235        SUPER_ARGS(classname, functionname, __VA_ARGS__)
     236
     237    #define SUPER_changedActivity(classname, functionname, ...) \
     238        SUPER_NOARGS(classname, functionname)
     239
     240    #define SUPER_changedVisibility(classname, functionname, ...) \
     241        SUPER_NOARGS(classname, functionname)
     242    // (1/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     243
    45244
    46245namespace orxonox
    47246{
    48     /////////////////
    49     // Common code //
    50     /////////////////
    51     class SuperDummy {};
    52 
    53     // Base template
    54     template <int functionnumber, int templatehack, class T>
    55     struct SuperFunctionCondition
    56     {
    57         static void check() {}
    58     };
    59 
    60     ////////////////////////////
    61     // Function-specific code //
    62     ////////////////////////////
    63     // Partially specialized template (templatehack not yet specialized, this will be done by the real condition in the header file of the super-function)
    64     template <int templatehack, class T>
    65     struct SuperFunctionCondition<0, templatehack, T>
    66     {
    67         // Calls the condition of the next super-function
    68         static void check()
    69         {
    70             std::cout << "ignore superfunction \"testfunction\" in " << ClassIdentifier<T>::getIdentifier()->getName() << std::endl;
    71             SuperFunctionCondition<0 + 1, templatehack, T>::check();
     247    /////////////////////////////////////////////////////////////////////////////////////////////////////
     248    // This code gets included by Identifier.h and every other header file that needs a super-function //
     249    /////////////////////////////////////////////////////////////////////////////////////////////////////
     250
     251    //// Common code ////
     252
     253        // Dummy - only needed to cast Identifier* to ClassIdentifier<SuperDummy>* (the real class doesn't matter)
     254        class SuperDummy {};
     255
     256        // Base template
     257        template <int functionnumber, class T, int templatehack1, int templatehack2>
     258        struct SuperFunctionCondition
     259        {
     260            static void check() {}
     261        };
     262
     263
     264    //// Function-specific code ////
     265
     266        /**
     267            @brief Creates the needed objects and templates to call a super-function.
     268            @param functionnumber Each super-function needs a unique number, starting with zero, increasing by one
     269            @param functionname The name of the super-function
     270            @param hasarguments "false" if the function doesn't take any arguments, "true" if it does (without "")
     271            @param ... Variadic: If the function takes arguments, add them here with type and name. Example: int myvalue, float myothervalue
     272        */
     273        #define SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(functionnumber, functionname, hasarguments, ...) \
     274            template <class T, int templatehack1, int templatehack2> \
     275            struct SuperFunctionCondition<functionnumber, T, templatehack1, templatehack2> \
     276            { \
     277                static void check() \
     278                { \
     279                    SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check(); \
     280                } \
     281            }; \
     282            \
     283            class _CoreExport SuperFunctionCaller_##functionname \
     284            { \
     285                public: \
     286                    virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \
     287                    virtual ~SuperFunctionCaller_##functionname () {} \
     288            }; \
     289            \
     290            template <class T> \
     291            class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname \
     292            { \
     293                public: \
     294                    inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \
     295                    { \
     296                        (dynamic_cast<T*>(object))->T:: functionname
     297
     298        /*
     299            JUST ADD THE FUNCTION ARGUMENTS BETWEEN BOTH MACROS, ENCLOSED BY BRACKETS
     300            EXAMPLE:
     301
     302              SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(0, myfunction, true, int myvalue, float myothervalue) <-- !!! DONT ADD A SEMICOLON HERE !!!
     303                (myvalue, myothervalue)
     304              SUPER_FUNCTION_GLOBAL_DECLARATION_PART2
     305        */
     306
     307        #define SUPER_FUNCTION_GLOBAL_DECLARATION_PART2 \
     308                                                        ; \
     309                    } \
     310            };
     311
     312        #define SUPER_CALL_ARGUMENTSfalse(...) OrxonoxClass* object
     313        #define SUPER_CALL_ARGUMENTS0(...)     OrxonoxClass* object
     314        #define SUPER_CALL_ARGUMENTStrue(...) OrxonoxClass* object, __VA_ARGS__
     315        #define SUPER_CALL_ARGUMENTS1(...)    OrxonoxClass* object, __VA_ARGS__
     316
     317
     318    /*
     319    //// COMMENTS ABOUT THE MACRO ////
     320
     321        // Partially specialized template (templatehack not yet specialized, this
     322        // will be done by the real condition in the header-file of the super-function)
     323        // Only used as fallback
     324        template <class T, int templatehack1, int templatehack2>
     325        struct SuperFunctionCondition<functionnumber, T, templatehack1, templatehack2>
     326        {
     327            // If this function gets called, the header-file of the super function is not
     328            // included, so this fallback template (templatehack not specialized) is used
     329            static void check()
     330            {
     331                // Calls the condition-check of the next super-function (functionnumber + 1)
     332                SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check();
     333            }
     334        };
     335
     336        // Baseclass of the super-function caller. The real call will be done by a
     337        // templatized subclass through the virtual () operator.
     338        class _CoreExport SuperFunctionCaller_##functionname
     339        {
     340            public:
     341                virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0;
     342                virtual ~SuperFunctionCaller_##functionname () {}
     343        };
     344
     345        // The real super-function caller: Calls T::functionname()
     346        // T should be the parent, but this will be done by the spezialized condition template
     347        template <class T>
     348        class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname
     349        {
     350            public:
     351                // @brief Calls the function.
     352                // @param object The object to call the function on
     353                // @param ... The arguments of the function
     354                inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) )
     355                {
     356                    (dynamic_cast<T*>(object))->T:: functionname ( Call the function with it's arguments );
     357                }
    72358        }
    73     };
    74 
    75     class SuperFunctionCaller_testfunction
    76     {
    77         public:
    78             virtual void operator()(void* object) = 0;
    79             virtual ~SuperFunctionCaller_testfunction() {}
    80     };
    81 
    82     template <class T>
    83     class SuperFunctionClassCaller_testfunction : public SuperFunctionCaller_testfunction
    84     {
    85         public:
    86             inline void operator()(void* object)
    87             {
    88                 ((T*)object)->T::testfunction();
    89             }
    90     };
     359    */
     360
     361    //// Execute the code for each super-function ////
     362        // (2/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     363        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(0, testfunction, false)
     364            ()
     365        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     366
     367        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(1, XMLPort, true, Element& xmlelement, XMLPort::Mode mode)
     368            (xmlelement, mode)
     369        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     370
     371        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(2, tick, true, float dt)
     372            (dt)
     373        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     374
     375        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(3, changedActivity, false)
     376            ()
     377        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     378
     379        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(4, changedVisibility, false)
     380            ()
     381        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     382        // (2/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     383
    91384}
    92385
    93386#else /* _Super_H__ */
    94   #ifdef SUPER_INTRUSIVE_DECLARATION
    95 
    96 /////////////////
    97 // Common code //
    98 /////////////////
    99 private:
    100     template <int functionnumber, int templatehack, class TT>
    101     friend struct SuperFunctionCondition;
    102 
    103     // Creates the function pointers by calling the first SuperFunctionCondition check
    104     virtual void createSuperFunctionCaller() const
    105     {
    106         SuperFunctionCondition<0, 0, T>::check();
    107     }
    108 
    109 ////////////////////////////
     387  #ifdef SUPER_INTRUSIVE_DECLARATION_INCLUDE
     388
     389//////////////////////////////////////////////////////////////////////////
     390// This code gets included within the declaration of ClassIdentifier<T> //
     391//////////////////////////////////////////////////////////////////////////
     392
     393//// Common code ////
     394
     395    private:
     396        template <int functionnumber, class TT, int templatehack1, int templatehack2>
     397        friend struct SuperFunctionCondition;
     398
     399        // Creates the super-function-callers by calling the first SuperFunctionCondition check
     400        // This get's called within the initialization of an Identifier
     401        virtual void createSuperFunctionCaller() const
     402        {
     403            SuperFunctionCondition<0, T, 0, 0>::check();
     404        }
     405
     406
     407//// Function-specific code ////
     408
     409    public:
     410        /**
     411            @brief Adds a pointer to the SuperFunctionCaller as a member of ClassIdentifier.
     412            @param functionname The name of the super-function
     413        */
     414        #ifndef SUPER_INTRUSIVE_DECLARATION
     415          #define SUPER_INTRUSIVE_DECLARATION(functionname) \
     416            SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_
     417        #endif
     418
     419
     420//// Execute the code for each super-function ////
     421    // (3/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     422    SUPER_INTRUSIVE_DECLARATION(testfunction);
     423    SUPER_INTRUSIVE_DECLARATION(XMLPort);
     424    SUPER_INTRUSIVE_DECLARATION(tick);
     425    SUPER_INTRUSIVE_DECLARATION(changedActivity);
     426    SUPER_INTRUSIVE_DECLARATION(changedVisibility);
     427    // (3/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     428
     429
     430    #undef SUPER_INTRUSIVE_DECLARATION_INCLUDE
     431  #endif /* SUPER_INTRUSIVE_DECLARATION_INCLUDE */
     432
     433  #ifdef SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE
     434
     435//////////////////////////////////////////////////////////////////////////
     436// This code gets included inside the constructor of ClassIdentifier<T> //
     437//////////////////////////////////////////////////////////////////////////
     438
    110439// Function-specific code //
    111 ////////////////////////////
    112 public:
    113     // The function caller
    114     SuperFunctionCaller_testfunction* superFunctionCaller_testfunction_;
    115 
    116     #undef SUPER_INTRUSIVE_DECLARATION
    117   #endif /* SUPER_INTRUSIVE_DECLARATION */
    118 
    119   #ifdef SUPER_INTRUSIVE_CONSTRUCTOR
    120 
    121 ////////////////////////////
     440
     441    /**
     442        @brief Initializes the SuperFunctionCaller pointer with zero.
     443        @param functionname The name of the super-function
     444    */
     445    #ifndef SUPER_INTRUSIVE_CONSTRUCTOR
     446      #define SUPER_INTRUSIVE_CONSTRUCTOR(functionname) \
     447        this->superFunctionCaller_##functionname##_ = 0
     448    #endif
     449
     450
     451//// Execute the code for each super-function ////
     452    // (4/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     453    SUPER_INTRUSIVE_CONSTRUCTOR(testfunction);
     454    SUPER_INTRUSIVE_CONSTRUCTOR(XMLPort);
     455    SUPER_INTRUSIVE_CONSTRUCTOR(tick);
     456    SUPER_INTRUSIVE_CONSTRUCTOR(changedActivity);
     457    SUPER_INTRUSIVE_CONSTRUCTOR(changedVisibility);
     458    // (4/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     459
     460    #undef SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE
     461  #endif /* SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE */
     462
     463  #ifdef SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE
     464
     465/////////////////////////////////////////////////////////////////////////
     466// This code gets included inside the destructor of ClassIdentifier<T> //
     467/////////////////////////////////////////////////////////////////////////
     468
    122469// Function-specific code //
    123 ////////////////////////////
    124 this->superFunctionCaller_testfunction_ = 0;
    125 
    126     #undef SUPER_INTRUSIVE_CONSTRUCTOR
    127   #endif /* SUPER_INTRUSIVE_CONSTRUCTOR */
    128 
    129   #ifdef SUPER_INTRUSIVE_DESTRUCTOR
    130 
    131 ////////////////////////////
    132 // Function-specific code //
    133 ////////////////////////////
    134 
    135 if (this->superFunctionCaller_testfunction_)
    136     delete this->superFunctionCaller_testfunction_;
    137 
    138     #undef SUPER_INTRUSIVE_DESTRUCTOR
    139   #endif /* SUPER_INTRUSIVE_DESTRUCTOR */
     470
     471    /**
     472        @brief Deletes the SuperFunctionCaller.
     473        @param functionname The name of the super-function
     474    */
     475    #ifndef SUPER_INTRUSIVE_DESTRUCTOR
     476      #define SUPER_INTRUSIVE_DESTRUCTOR(functionname) \
     477        if (this->superFunctionCaller_##functionname##_) \
     478          delete this->superFunctionCaller_##functionname##_
     479    #endif
     480
     481
     482//// Execute the code for each super-function ////
     483    // (5/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     484    SUPER_INTRUSIVE_DESTRUCTOR(testfunction);
     485    SUPER_INTRUSIVE_DESTRUCTOR(XMLPort);
     486    SUPER_INTRUSIVE_DESTRUCTOR(tick);
     487    SUPER_INTRUSIVE_DESTRUCTOR(changedActivity);
     488    SUPER_INTRUSIVE_DESTRUCTOR(changedVisibility);
     489    // (5/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     490
     491    #undef SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE
     492  #endif /* SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE */
    140493#endif /* _Super_H__ */
  • code/branches/core3/src/orxonox/objects/Ambient.cc

    r1594 r1684  
    8989    void Ambient::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    9090    {
    91         BaseObject::XMLPort(xmlelement, mode);
     91//        BaseObject::XMLPort(xmlelement, mode);
     92        SUPER(Ambient, XMLPort, xmlelement, mode);
    9293
    9394        XMLPortParam(Ambient, "colourvalue", setAmbientLight, getAmbienetLight, xmlelement, mode);
  • code/branches/core3/src/orxonox/objects/BillboardProjectile.cc

    r1676 r1684  
    6767    void BillboardProjectile::changedVisibility()
    6868    {
    69         Projectile::changedVisibility();
     69//        Projectile::changedVisibility();
     70        SUPER(BillboardProjectile, changedVisibility);
    7071        this->billboard_.setVisible(this->isVisible());
    7172    }
  • code/branches/core3/src/orxonox/objects/BillboardProjectile.h

    r1676 r1684  
    3838namespace orxonox
    3939{
    40     class _OrxonoxExport BillboardProjectile : public Projectile
     40    class TESTTESTTEST1
     41    {
     42        public:
     43            TESTTESTTEST1() { this->setMyValue(10); }
     44
     45        private:
     46            void setMyValue(int value) { this->value1_ = value; }
     47
     48            int value1_;
     49            int value2_;
     50            Identifier* identifier_;
     51    };
     52
     53    class TESTTESTTEST2
     54    {
     55        public:
     56            TESTTESTTEST2() { this->setMyValue(10); }
     57
     58        private:
     59            void setMyValue(int value) { this->value1_ = value; }
     60
     61            int value1_;
     62            int value2_;
     63            double value3_;
     64            char value4_;
     65            bool value5_;
     66            Identifier* identifier1_;
     67            Identifier* identifier2_;
     68    };
     69
     70    class TESTTESTTEST3 : virtual public TESTTESTTEST1
     71    {
     72        public:
     73            TESTTESTTEST3() { this->setMyOtherValue(10); }
     74
     75        private:
     76            void setMyOtherValue(int value) { this->value3_ = value; }
     77
     78            int value3_;
     79            TESTTESTTEST2* test_;
     80    };
     81
     82    class _OrxonoxExport BillboardProjectile : public Projectile, public TESTTESTTEST3, public TESTTESTTEST2, virtual public TESTTESTTEST1
    4183    {
    4284        public:
  • code/branches/core3/src/orxonox/objects/Model.cc

    r1592 r1684  
    6666    void Model::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6767    {
    68         WorldEntity::XMLPort(xmlelement, mode);
     68//        WorldEntity::XMLPort(xmlelement, mode);
     69        SUPER(Model, XMLPort, xmlelement, mode);
    6970
    7071        XMLPortParam(Model, "mesh", setMesh, getMesh, xmlelement, mode);
     
    7273        Model::create();
    7374    }
     75/*
     76    void Model::tick(float dt)
     77    {
     78        float i = dt * rnd(-100, 100);
     79        float j = dt * rnd(-100, 100);
     80        float k = dt * rnd(-100, 100);
    7481
     82//        WorldEntity::tick(dt);
     83        SUPER(Model, tick, dt);
     84
     85        this->setPosition(this->getPosition().x + i, this->getPosition().y + j, this->getPosition().z + k);
     86    }
     87*/
    7588    bool Model::create(){
    7689      if(!WorldEntity::create())
     
    94107    void Model::changedVisibility()
    95108    {
    96         WorldEntity::changedVisibility();
     109//        WorldEntity::changedVisibility();
     110        SUPER(Model, changedVisibility);
    97111        this->mesh_.setVisible(this->isVisible());
    98112    }
  • code/branches/core3/src/orxonox/objects/Model.h

    r1592 r1684  
    4444            virtual ~Model();
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46//            virtual void tick(float dt);
    4647            virtual void changedVisibility();
    4748            inline void setMesh(const std::string& meshname)
  • code/branches/core3/src/orxonox/objects/ParticleProjectile.cc

    r1676 r1684  
    3333#include "core/CoreIncludes.h"
    3434#include "core/ConfigValueIncludes.h"
    35 //#include "util/FastDelegate.h"
    36 //using namespace fastdelegate;
    3735
    3836namespace orxonox
    3937{
    4038    CreateFactory(ParticleProjectile);
    41 
    42     struct FunctionPointerViewer
    43     {
    44         void* ptr1_;
    45         void* ptr2_;
    46 
    47         void view()
    48         {
    49             std::cout << ptr1_ << "." << ptr2_ << std::endl;
    50         }
    51     };
    52 
    53     union FunctionPointerViewer1
    54     {
    55         FunctionPointerViewer viewer_;
    56         void (Projectile::*function_) ();
    57     };
    58 
    59     union FunctionPointerViewer2
    60     {
    61         FunctionPointerViewer viewer_;
    62         void (BillboardProjectile::*function_) ();
    63     };
    64 
    65     union FunctionPointerViewer3
    66     {
    67         FunctionPointerViewer viewer_;
    68         void (ParticleProjectile::*function_) ();
    69     };
    7039
    7140    ParticleProjectile::ParticleProjectile(SpaceShip* owner) : BillboardProjectile(owner)
     
    8655
    8756        this->setConfigValues();
    88 /*
    89         FunctionPointerViewer1 fpw1;
    90         fpw1.function_ = &Projectile::testfunction;
    91         FunctionPointerViewer2 fpw2;
    92         fpw2.function_ = &BillboardProjectile::testfunction;
    93         FunctionPointerViewer3 fpw3;
    94         fpw3.function_ = &ParticleProjectile::testfunction;
    9557
    96         std::cout << sizeof(void (Projectile::*) ()) << std::endl;
    97         fpw1.viewer_.view();
    98         fpw2.viewer_.view();
    99         fpw3.viewer_.view();
    100 
    101         {
    102             std::cout << "1:" << std::endl;
    103             FastDelegate0<> delegate1(this, &ParticleProjectile::testfunction);
    104             delegate1();
    105             FastDelegate0<> delegate2((BillboardProjectile*)this, &BillboardProjectile::testfunction);
    106             delegate2();
    107             FastDelegate0<> delegate3(this, &Projectile::testfunction);
    108             delegate3();
    109         }
    110         {
    111             std::cout << "2:" << std::endl;
    112             BillboardProjectile temp;
    113 //            FastDelegate0<> delegate1(&temp, &ParticleProjectile::testfunction);
    114 //            delegate1();
    115             FastDelegate0<> delegate2(&temp, &BillboardProjectile::testfunction);
    116             delegate2();
    117             FastDelegate0<> delegate3(&temp, &Projectile::testfunction);
    118             delegate3();
    119         }
    120         std::cout << "done" << std::endl;
    121 
    122         std::cout << "0:" << std::endl;
    123         this->Projectile::testfunction();
    124         this->BillboardProjectile::testfunction();
    125         this->ParticleProjectile::testfunction();
    126         this->testfunction();
    127 
    128         std::cout << "1:" << std::endl;
    129         (this->*fpw1.function_)();
    130         std::cout << "2:" << std::endl;
    131         (this->*fpw2.function_)();
    132         std::cout << "3:" << std::endl;
    133         (this->*fpw3.function_)();
    134         std::cout << "done" << std::endl;
    135 */
    13658        std::cout << "c:\n";
    13759        SUPER(ParticleProjectile, testfunction);
     
    14163        this->testfunction();
    14264        std::cout << "f:\n";
    143 
    144 //        (*((ClassIdentifier<SuperDummy>*)this->getIdentifier())->superFunctionCaller_testfunction_)(this);
    14565    }
    14666
     
    15878    void ParticleProjectile::changedVisibility()
    15979    {
    160         BillboardProjectile::changedVisibility();
     80//        BillboardProjectile::changedVisibility();
     81        SUPER(ParticleProjectile, changedVisibility);
    16182        this->particles_->setEnabled(this->isVisible());
    16283    }
  • code/branches/core3/src/orxonox/objects/ParticleProjectile.h

    r1676 r1684  
    3838namespace orxonox
    3939{
    40     class _OrxonoxExport ParticleProjectile : public BillboardProjectile
     40    class TESTTESTTEST13
     41    {
     42        public:
     43            TESTTESTTEST13() { this->setMyValue(10); }
     44
     45        private:
     46            void setMyValue(int value) { this->value1_ = value; }
     47
     48            int value1_;
     49            int value2_;
     50            Identifier* identifier_;
     51    };
     52
     53    class TESTTESTTEST23
     54    {
     55        public:
     56            TESTTESTTEST23() { this->setMyValue(10); }
     57
     58        private:
     59            void setMyValue(int value) { this->value1_ = value; }
     60
     61            int value1_;
     62            int value2_;
     63            double value3_;
     64            char value4_;
     65            bool value5_;
     66            Identifier* identifier1_;
     67            Identifier* identifier2_;
     68    };
     69
     70    class TESTTESTTEST33 : virtual public TESTTESTTEST13
     71    {
     72        public:
     73            TESTTESTTEST33() { this->setMyOtherValue(10); }
     74
     75        private:
     76            void setMyOtherValue(int value) { this->value3_ = value; }
     77
     78            int value3_;
     79            TESTTESTTEST23* test_;
     80    };
     81
     82    class _OrxonoxExport ParticleProjectile : public TESTTESTTEST33, public BillboardProjectile, virtual public TESTTESTTEST13
    4183    {
    4284        public:
  • code/branches/core3/src/orxonox/objects/Projectile.cc

    r1676 r1684  
    8686    void Projectile::tick(float dt)
    8787    {
    88         WorldEntity::tick(dt);
     88//        WorldEntity::tick(dt);
     89        SUPER(Projectile, tick, dt);
    8990
    9091        if (!this->isActive())
  • code/branches/core3/src/orxonox/objects/Projectile.h

    r1683 r1684  
    3232#include "OrxonoxPrereqs.h"
    3333
     34#include "core/Super.h"
    3435#include "WorldEntity.h"
    3536#include "tools/Timer.h"
    36 #undef SUPER_INTRUSIVE
    37 #include "core/Super.h"
    3837
    3938namespace orxonox
    4039{
    41     class _OrxonoxExport Projectile : public WorldEntity
     40    class TESTTESTTEST12
     41    {
     42        public:
     43            TESTTESTTEST12() { this->setMyValue(10); }
     44
     45        private:
     46            void setMyValue(int value) { this->value1_ = value; }
     47
     48            int value1_;
     49            int value2_;
     50            Identifier* identifier_;
     51    };
     52
     53    class TESTTESTTEST22
     54    {
     55        public:
     56            TESTTESTTEST22() { this->setMyValue(10); }
     57
     58        private:
     59            void setMyValue(int value) { this->value1_ = value; }
     60
     61            int value1_;
     62            int value2_;
     63            double value3_;
     64            char value4_;
     65            bool value5_;
     66            Identifier* identifier1_;
     67            Identifier* identifier2_;
     68    };
     69
     70    class TESTTESTTEST32 : virtual public TESTTESTTEST12
     71    {
     72        public:
     73            TESTTESTTEST32() { this->setMyOtherValue(10); }
     74
     75        private:
     76            void setMyOtherValue(int value) { this->value3_ = value; }
     77
     78            int value3_;
     79            TESTTESTTEST22* test_;
     80    };
     81
     82    class _OrxonoxExport Projectile : public TESTTESTTEST22, public TESTTESTTEST32, virtual public TESTTESTTEST12, public WorldEntity
    4283    {
    4384        public:
     
    68109    };
    69110
    70     // Partially specialized template (templatehack is now specialized too)
    71     template <class T>
    72     struct SuperFunctionCondition<0, 0, T>
    73     {
    74         // Checks if class U isA baseclass and sets the functionpointer if the check returned true
    75         static void check()
    76         {
    77             std::cout << "check superfunction \"testfunction\" in " << ClassIdentifier<T>::getIdentifier()->getName() << std::endl;
    78 
    79             T* temp = 0;
    80             SuperFunctionCondition<0, 0, T>::apply(temp);
    81 
    82             std::cout << "done" << std::endl;
    83 
    84             // Calls the condition of the next super-function
    85             SuperFunctionCondition<0 + 1, 0, T>::check();
    86         }
    87 
    88         static void apply(void* temp)
    89         {
    90             std::cout << ClassIdentifier<T>::getIdentifier()->getName() << " is not a Projectile" << std::endl;
    91             // nop
    92         }
    93 
    94         static void apply(Projectile* temp)
    95         {
    96             std::cout << ClassIdentifier<T>::getIdentifier()->getName() << " is a Projectile" << std::endl;
    97             ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
    98 
    99             // Iterate through all children and assign the caller
    100             for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)
    101             {
    102                 if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_testfunction_)
    103                 {
    104                     std::cout << "adding functionpointer to " << ((ClassIdentifier<T>*)(*it))->getName() << std::endl;
    105                     ((ClassIdentifier<T>*)(*it))->superFunctionCaller_testfunction_ = new SuperFunctionClassCaller_testfunction<T>;
    106                 }
    107             }
    108         }
    109     };
     111    SUPER_FUNCTION(0, Projectile, testfunction, false);
    110112}
    111113
  • code/branches/core3/src/orxonox/objects/RotatingProjectile.cc

    r1610 r1684  
    8888
    8989        Projectile::tick(dt);
     90//        SUPER(RotatingProjectile, tick, dt);
    9091    }
    9192
    9293    void RotatingProjectile::changedVisibility()
    9394    {
    94         BillboardProjectile::changedVisibility();
     95//        BillboardProjectile::changedVisibility();
     96        SUPER(RotatingProjectile, changedVisibility);
    9597        this->rotatingBillboard1_.setVisible(this->isVisible());
    9698        this->rotatingBillboard2_.setVisible(this->isVisible());
  • code/branches/core3/src/orxonox/objects/Skybox.cc

    r1592 r1684  
    6767    void Skybox::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6868    {
    69         BaseObject::XMLPort(xmlelement, mode);
     69//        BaseObject::XMLPort(xmlelement, mode);
     70        SUPER(Skybox, XMLPort, xmlelement, mode);
    7071
    7172        XMLPortParam(Skybox, "src", setSkyboxSrc, getSkyboxSrc, xmlelement, mode);
     
    8687    void Skybox::changedVisibility()
    8788    {
    88         BaseObject::changedVisibility();
     89//        BaseObject::changedVisibility();
     90        SUPER(Skybox, changedVisibility);
    8991        GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(this->isVisible(), this->skyboxSrc_);
    9092    }
  • code/branches/core3/src/orxonox/objects/SpaceShip.cc

    r1594 r1684  
    259259    void SpaceShip::changedVisibility()
    260260    {
    261         Model::changedVisibility();
     261//        Model::changedVisibility();
     262        SUPER(SpaceShip, changedVisibility);
    262263
    263264        this->tt1_->setEnabled(this->isVisible());
     
    271272    void SpaceShip::changedActivity()
    272273    {
    273         Model::changedActivity();
     274//        Model::changedActivity();
     275        SUPER(SpaceShip, changedActivity);
    274276
    275277        this->tt1_->setEnabled(this->isVisible());
     
    345347    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    346348    {
    347         Model::XMLPort(xmlelement, mode);
     349//        Model::XMLPort(xmlelement, mode);
     350        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    348351
    349352        XMLPortParam(SpaceShip, "camera", setCamera, getCamera, xmlelement, mode);
     
    482485
    483486
    484         WorldEntity::tick(dt);
     487//        WorldEntity::tick(dt);
     488        SUPER(SpaceShip, tick, dt);
    485489
    486490        this->roll(this->mouseXRotation_ * dt);
  • code/branches/core3/src/orxonox/objects/SpaceShipAI.cc

    r1594 r1684  
    7878    void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7979    {
    80         SpaceShip::XMLPort(xmlelement, mode);
     80//        SpaceShip::XMLPort(xmlelement, mode);
     81        SUPER(SpaceShipAI, XMLPort, xmlelement, mode);
    8182
    8283        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action)));
     
    229230            this->doFire();
    230231
    231         SpaceShip::tick(dt);
     232//        SpaceShip::tick(dt);
     233        SUPER(SpaceShipAI, tick, dt);
    232234    }
    233235
  • code/branches/core3/src/orxonox/objects/SpaceShipAI.h

    r1552 r1684  
    4747
    4848            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     49            virtual void tick(float dt);
    4950            static void createEnemy(int num);
    5051            static void killEnemies(int num);
     
    5455
    5556        private:
    56             virtual void tick(float dt);
    5757            virtual ColourValue getProjectileColour() const;
    5858
  • code/branches/core3/src/orxonox/objects/Tickable.h

    r1535 r1684  
    4545
    4646#include "core/OrxonoxClass.h"
     47#include "core/Super.h"
    4748
    4849namespace orxonox
     
    6162            Tickable();
    6263    };
     64
     65    SUPER_FUNCTION(2, Tickable, tick, true);
    6366
    6467    //! The Tickable interface provides a tick(dt) function, that gets called every frame.
  • code/branches/core3/src/orxonox/objects/WorldEntity.cc

    r1611 r1684  
    110110    void WorldEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    111111    {
    112         BaseObject::XMLPort(xmlelement, mode);
     112//        BaseObject::XMLPort(xmlelement, mode);
     113        SUPER(WorldEntity, XMLPort, xmlelement, mode);
    113114
    114115        XMLPortParamExternTemplate(WorldEntity, Ogre::Node, this->node_, "position", setPosition, getPosition, xmlelement, mode, Ogre::Node, const Vector3&);
Note: See TracChangeset for help on using the changeset viewer.