Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1687 for code


Ignore:
Timestamp:
Aug 31, 2008, 5:37:56 PM (16 years ago)
Author:
landauf
Message:

simplified the declaration of a new super-function by replacing 2 intrusive macros with some templates

Location:
code/branches/core3/src/core
Files:
2 edited

Legend:

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

    r1685 r1687  
    319319            ClassIdentifier()
    320320            {
    321                 #define SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE
    322                 #include "Super.h"
     321                SuperFunctionInitialization<0, T>::initialize(this);
    323322            }
    324323            ~ClassIdentifier()
    325324            {
    326                 #define SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE
    327                 #include "Super.h"
     325                SuperFunctionDestruction<0, T>::destroy(this);
    328326            }
    329327
  • code/branches/core3/src/core/Super.h

    r1685 r1687  
    3939    classes that have an Identifier. Arguments however are supported.
    4040
    41     To add a new super-function, you have process 6 steps:
     41    To add a new super-function, you have process 4 steps:
    4242
    4343    1) Add a new SUPER macro
    4444       This allows you to call the super-function in your code.
    45        Location: This file (Super.h), marked with --> HERE <-- comments (1/5)
     45       Location: This file (Super.h), marked with --> HERE <-- comments (1/3)
    4646
    4747    2) Call the SUPER_FUNCTION_GLOBAL_DECLARATION_PART1/2 macros.
    4848       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)
     49       Location: This file (Super.h), marked with --> HERE <-- comments (2/3)
    5050
    5151    3) Call the SUPER_INTRUSIVE_DECLARATION macro.
    5252       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.
     53       Location: This file (Super.h), marked with --> HERE <-- comments (3/3)
     54
     55    4) Call the SUPER_FUNCTION macro.
    6456       This defines a partially specialized template that will decide if a class is "super" to another class.
    6557       If the check returns true, a SuperFunctionCaller gets created, which will be used by the SUPER macro.
     
    225217    */
    226218
    227     // (1/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     219    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    228220    #define SUPER_testfunction(classname, functionname, ...) \
    229221        SUPER_NOARGS(classname, functionname)
     
    240232    #define SUPER_changedVisibility(classname, functionname, ...) \
    241233        SUPER_NOARGS(classname, functionname)
    242     // (1/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     234    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    243235
    244236
     
    251243    //// Common code ////
    252244
    253         // Base template
     245        // Base templates
     246        /**
     247            @brief Creates the SuperFunctionCaller if T is a child of the super-functions baseclass.
     248        */
    254249        template <int functionnumber, class T, int templatehack1, int templatehack2>
    255250        struct SuperFunctionCondition
    256251        {
    257252            static void check() {}
     253        };
     254
     255        /**
     256            @brief Initializes the SuperFunctionCaller-pointer with zero.
     257        */
     258        template <int functionnumber, class T>
     259        struct SuperFunctionInitialization
     260        {
     261            static void initialize(ClassIdentifier<T>* identifier) {}
     262        };
     263
     264        /**
     265            @brief Deletes the SuperFunctionCaller.
     266        */
     267        template <int functionnumber, class T>
     268        struct SuperFunctionDestruction
     269        {
     270            static void destroy(ClassIdentifier<T>* identifier) {}
    258271        };
    259272
     
    275288                { \
    276289                    SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check(); \
     290                } \
     291            }; \
     292            \
     293            template <class T> \
     294            struct SuperFunctionInitialization<functionnumber, T> \
     295            { \
     296                static void initialize(ClassIdentifier<T>* identifier) \
     297                { \
     298                    identifier->superFunctionCaller_##functionname##_ = 0; \
     299                    SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); \
     300                } \
     301            }; \
     302            \
     303            template <class T> \
     304            struct SuperFunctionDestruction<functionnumber, T> \
     305            { \
     306                static void destroy(ClassIdentifier<T>* identifier) \
     307                { \
     308                    if (identifier->superFunctionCaller_##functionname##_) \
     309                        delete identifier->superFunctionCaller_##functionname##_; \
     310                    SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier); \
    277311                } \
    278312            }; \
     
    328362                // Calls the condition-check of the next super-function (functionnumber + 1)
    329363                SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check();
     364            }
     365        };
     366
     367        // Initializes the SuperFunctionCaller-pointer with zero.
     368        template <class T>
     369        struct SuperFunctionInitialization<functionnumber, T>
     370        {
     371            static void initialize(ClassIdentifier<T>* identifier)
     372            {
     373                identifier->superFunctionCaller_##functionname##_ = 0;
     374
     375                // Calls the initialization of the next super-function (functionnumber + 1)
     376                SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier);
     377            }
     378        };
     379
     380        // Deletes the SuperFunctionCaller.
     381        template <class T>
     382        struct SuperFunctionDestruction<functionnumber, T>
     383        {
     384            static void destroy(ClassIdentifier<T>* identifier)
     385            {
     386                if (identifier->superFunctionCaller_##functionname##_)
     387                    delete identifier->superFunctionCaller_##functionname##_;
     388
     389                // Calls the destruction of the next super-function (functionnumber + 1)
     390                SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier);
    330391            }
    331392        };
     
    356417    */
    357418
     419
    358420    //// Execute the code for each super-function ////
    359         // (2/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     421
     422        // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    360423        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(0, testfunction, false)
    361424            ()
     
    377440            ()
    378441        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    379         // (2/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     442        // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    380443
    381444}
     
    391454
    392455    private:
     456
    393457        template <int functionnumber, class TT, int templatehack1, int templatehack2>
    394458        friend struct SuperFunctionCondition;
     
    416480
    417481//// Execute the code for each super-function ////
    418     // (3/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     482
     483    // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    419484    SUPER_INTRUSIVE_DECLARATION(testfunction);
    420485    SUPER_INTRUSIVE_DECLARATION(XMLPort);
     
    422487    SUPER_INTRUSIVE_DECLARATION(changedActivity);
    423488    SUPER_INTRUSIVE_DECLARATION(changedVisibility);
    424     // (3/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
     489    // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    425490
    426491
    427492    #undef SUPER_INTRUSIVE_DECLARATION_INCLUDE
    428493  #endif /* SUPER_INTRUSIVE_DECLARATION_INCLUDE */
    429 
    430   #ifdef SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE
    431 
    432 //////////////////////////////////////////////////////////////////////////
    433 // This code gets included inside the constructor of ClassIdentifier<T> //
    434 //////////////////////////////////////////////////////////////////////////
    435 
    436 // Function-specific code //
    437 
    438     /**
    439         @brief Initializes the SuperFunctionCaller pointer with zero.
    440         @param functionname The name of the super-function
    441     */
    442     #ifndef SUPER_INTRUSIVE_CONSTRUCTOR
    443       #define SUPER_INTRUSIVE_CONSTRUCTOR(functionname) \
    444         this->superFunctionCaller_##functionname##_ = 0
    445     #endif
    446 
    447 
    448 //// Execute the code for each super-function ////
    449     // (4/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    450     SUPER_INTRUSIVE_CONSTRUCTOR(testfunction);
    451     SUPER_INTRUSIVE_CONSTRUCTOR(XMLPort);
    452     SUPER_INTRUSIVE_CONSTRUCTOR(tick);
    453     SUPER_INTRUSIVE_CONSTRUCTOR(changedActivity);
    454     SUPER_INTRUSIVE_CONSTRUCTOR(changedVisibility);
    455     // (4/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    456 
    457     #undef SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE
    458   #endif /* SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE */
    459 
    460   #ifdef SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE
    461 
    462 /////////////////////////////////////////////////////////////////////////
    463 // This code gets included inside the destructor of ClassIdentifier<T> //
    464 /////////////////////////////////////////////////////////////////////////
    465 
    466 // Function-specific code //
    467 
    468     /**
    469         @brief Deletes the SuperFunctionCaller.
    470         @param functionname The name of the super-function
    471     */
    472     #ifndef SUPER_INTRUSIVE_DESTRUCTOR
    473       #define SUPER_INTRUSIVE_DESTRUCTOR(functionname) \
    474         if (this->superFunctionCaller_##functionname##_) \
    475           delete this->superFunctionCaller_##functionname##_
    476     #endif
    477 
    478 
    479 //// Execute the code for each super-function ////
    480     // (5/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    481     SUPER_INTRUSIVE_DESTRUCTOR(testfunction);
    482     SUPER_INTRUSIVE_DESTRUCTOR(XMLPort);
    483     SUPER_INTRUSIVE_DESTRUCTOR(tick);
    484     SUPER_INTRUSIVE_DESTRUCTOR(changedActivity);
    485     SUPER_INTRUSIVE_DESTRUCTOR(changedVisibility);
    486     // (5/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    487 
    488     #undef SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE
    489   #endif /* SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE */
    490494#endif /* _Super_H__ */
Note: See TracChangeset for help on using the changeset viewer.