[1677] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef _Super_H__ |
---|
| 30 | #define _Super_H__ |
---|
| 31 | |
---|
| 32 | #include <iostream> |
---|
| 33 | |
---|
| 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) |
---|
| 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
| 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(); |
---|
| 72 | } |
---|
| 73 | }; |
---|
| 74 | |
---|
| 75 | class SuperFunctionCaller_testfunction |
---|
| 76 | { |
---|
| 77 | public: |
---|
| 78 | virtual void operator()(void* object) = 0; |
---|
| 79 | }; |
---|
| 80 | |
---|
| 81 | template <class T> |
---|
| 82 | class SuperFunctionClassCaller_testfunction : public SuperFunctionCaller_testfunction |
---|
| 83 | { |
---|
| 84 | public: |
---|
| 85 | inline virtual void operator()(void* object) |
---|
| 86 | { |
---|
| 87 | ((T*)object)->T::testfunction(); |
---|
| 88 | } |
---|
| 89 | }; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | #else /* _Super_H__ */ |
---|
| 93 | #ifdef SUPER_INTRUSIVE_DECLARATION |
---|
| 94 | |
---|
| 95 | ///////////////// |
---|
| 96 | // Common code // |
---|
| 97 | ///////////////// |
---|
| 98 | private: |
---|
| 99 | template <int functionnumber, int templatehack, class TT> |
---|
| 100 | friend struct SuperFunctionCondition; |
---|
| 101 | |
---|
| 102 | // Creates the function pointers by calling the first SuperFunctionCondition check |
---|
| 103 | virtual void createSuperFunctionCaller() const |
---|
| 104 | { |
---|
| 105 | SuperFunctionCondition<0, 0, T>::check(); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | //////////////////////////// |
---|
| 110 | // 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 | //////////////////////////// |
---|
| 122 | // Function-specific code // |
---|
| 123 | //////////////////////////// |
---|
| 124 | this->superFunctionCaller_testfunction_ = 0; |
---|
| 125 | |
---|
| 126 | #undef SUPER_INTRUSIVE_CONSTRUCTOR |
---|
| 127 | #endif /* SUPER_INTRUSIVE_CONSTRUCTOR */ |
---|
| 128 | #endif /* _Super_H__ */ |
---|