Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 28, 2008, 11:50:53 PM (16 years ago)
Author:
landauf
Message:

a first test-version of my super-macro
tested with a testfunction in Projectile, just shoot to test
no idea if this works on other compilers (namely MSVC)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/orxonox/objects/Projectile.h

    r1596 r1676  
    3434#include "WorldEntity.h"
    3535#include "tools/Timer.h"
     36#undef SUPER_INTRUSIVE
     37#include "core/Super.h"
    3638
    3739namespace orxonox
     
    4547            void destroyObject();
    4648            virtual void tick(float dt);
     49            virtual void testfunction();
    4750
    4851            static float getSpeed()
     
    6467            Timer<Projectile> destroyTimer_;
    6568    };
     69
     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;
     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            SuperFunctionCaller_testfunction* superFunctionCaller = 0;
     100            // Search for an existing caller within all direct children
     101            for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)
     102                if (((ClassIdentifier<T>*)(*it))->superFunctionCaller_testfunction_)
     103                    superFunctionCaller = ((ClassIdentifier<T>*)(*it))->superFunctionCaller_testfunction_;
     104            // Check if we've found an existing caller - if not, create a new one
     105            if (!superFunctionCaller)
     106                superFunctionCaller = new SuperFunctionClassCaller_testfunction<T>;
     107            // Iterate through all children and assign the caller
     108            for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)
     109            {
     110                if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_testfunction_)
     111                {
     112                    std::cout << "adding functionpointer to " << ((ClassIdentifier<T>*)(*it))->getName() << std::endl;
     113                    ((ClassIdentifier<T>*)(*it))->superFunctionCaller_testfunction_ = superFunctionCaller;
     114                }
     115            }
     116        }
     117    };
    66118}
    67119
Note: See TracChangeset for help on using the changeset viewer.