Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1676


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)

Location:
code/branches/core3/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/core/ConfigFileManager.cc

    r1658 r1676  
    327327        file.close();
    328328
    329         COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl;
     329        COUT(0) << "Loaded config file \"" << this->filename_ << "\"." << std::endl;
    330330
    331331        // Save the file in case something changed (like stripped whitespaces)
  • code/branches/core3/src/core/Factory.cc

    r1586 r1676  
    9898        }
    9999        (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
     100/*
     101        for (it = Identifier::getIdentifierMapIntern().begin(); it != Identifier::getIdentifierMapIntern().end(); ++it)
     102            (*it).second->createSuperFunctionCaller();
     103*/
    100104        COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl;
    101105    }
  • code/branches/core3/src/core/Identifier.cc

    r1610 r1676  
    145145                // Tell the parent we're one of it's direct children
    146146                (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
     147
     148                // Create the super-function dependencies
     149                (*it)->createSuperFunctionCaller();
    147150            }
    148151        }
  • code/branches/core3/src/core/Identifier.h

    r1610 r1676  
    6262#include "MetaObjectList.h"
    6363#include "Iterator.h"
     64#undef SUPER_INTRUSIVE
     65#include "Super.h"
    6466#include "util/Debug.h"
    6567#include "util/String.h"
     
    224226            static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
    225227
     228            virtual void createSuperFunctionCaller() const = 0;
     229
    226230            /** @brief Returns the map that stores all Identifiers. @return The map */
    227231            static std::map<std::string, Identifier*>& getIdentifierMapIntern();
     
    229233            static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern();
    230234
    231             bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    232             ObjectListBase* objects_;                                      //!< The list of all objects of this class
    233 
    234         private:
    235235            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    236236            inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
     
    238238            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
    239239
     240            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     241            ObjectListBase* objects_;                                      //!< The list of all objects of this class
     242
     243        private:
    240244            /**
    241245                @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
     
    295299    class ClassIdentifier : public Identifier
    296300    {
     301        #define SUPER_INTRUSIVE_DECLARATION
     302        #include "Super.h"
     303
    297304        public:
    298305            static ClassIdentifier<T> *getIdentifier();
     
    311318
    312319        private:
    313             ClassIdentifier() {}
     320            ClassIdentifier()
     321            {
     322                #define SUPER_INTRUSIVE_CONSTRUCTOR
     323                #include "Super.h"
     324            }
    314325            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    315326            ~ClassIdentifier() {}                                       // don't delete
  • code/branches/core3/src/orxonox/objects/BillboardProjectile.cc

    r1559 r1676  
    4848            this->scale(0.5);
    4949        }
     50
     51        std::cout << "a:\n";
     52        SUPER(BillboardProjectile, testfunction);
     53        std::cout << "b:\n";
    5054    }
    5155
     
    6670        this->billboard_.setVisible(this->isVisible());
    6771    }
     72
     73    void BillboardProjectile::testfunction() { SUPER(BillboardProjectile, testfunction); std::cout << "2 -> " << std::endl; }
    6874}
  • code/branches/core3/src/orxonox/objects/BillboardProjectile.h

    r1558 r1676  
    4646            virtual void setColour(const ColourValue& colour);
    4747            virtual void changedVisibility();
     48            virtual void testfunction();
    4849
    4950        private:
  • code/branches/core3/src/orxonox/objects/ParticleProjectile.cc

    r1610 r1676  
    3333#include "core/CoreIncludes.h"
    3434#include "core/ConfigValueIncludes.h"
     35//#include "util/FastDelegate.h"
     36//using namespace fastdelegate;
     37
    3538namespace orxonox
    3639{
    3740    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    };
    3870
    3971    ParticleProjectile::ParticleProjectile(SpaceShip* owner) : BillboardProjectile(owner)
     
    5486
    5587        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;
     95
     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*/
     136        std::cout << "c:\n";
     137        SUPER(ParticleProjectile, testfunction);
     138        std::cout << "d:\n";
     139
     140        std::cout << "e:\n";
     141        this->testfunction();
     142        std::cout << "f:\n";
     143
     144//        (*((ClassIdentifier<SuperDummy>*)this->getIdentifier())->superFunctionCaller_testfunction_)(this);
    56145    }
    57146
     
    72161        this->particles_->setEnabled(this->isVisible());
    73162    }
     163
     164    void ParticleProjectile::testfunction() { SUPER(ParticleProjectile, testfunction); std::cout << "3 -> " << std::endl; }
    74165}
  • code/branches/core3/src/orxonox/objects/ParticleProjectile.h

    r1597 r1676  
    4444            virtual ~ParticleProjectile();
    4545            virtual void changedVisibility();
     46            virtual void testfunction();
    4647            void setConfigValues();
    4748
  • code/branches/core3/src/orxonox/objects/Projectile.cc

    r1610 r1676  
    121121        delete this;
    122122    }
     123
     124    void Projectile::testfunction() { std::cout << "1 -> " << std::endl; }
    123125}
  • 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.