[1505] | 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 | /** |
---|
[2171] | 30 | @file |
---|
[7401] | 31 | @ingroup Object Factory |
---|
[1505] | 32 | @brief Definition and implementation of the ClassFactory class |
---|
| 33 | |
---|
[7401] | 34 | The ClassFactory is able to create new objects of a specific class which creates objects. |
---|
[1505] | 35 | */ |
---|
| 36 | |
---|
| 37 | #ifndef _ClassFactory_H__ |
---|
| 38 | #define _ClassFactory_H__ |
---|
| 39 | |
---|
[9557] | 40 | #include "core/CorePrereqs.h" |
---|
[1505] | 41 | |
---|
| 42 | #include <string> |
---|
| 43 | |
---|
[8858] | 44 | #include "util/Output.h" |
---|
[1505] | 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
[5929] | 48 | // ########################### |
---|
| 49 | // ### Factory ### |
---|
| 50 | // ########################### |
---|
[9667] | 51 | /// Base-class of all factories. |
---|
[5929] | 52 | class _CoreExport Factory |
---|
| 53 | { |
---|
| 54 | public: |
---|
[11071] | 55 | Factory() = default; |
---|
| 56 | virtual ~Factory() = default; |
---|
[9667] | 57 | virtual Identifiable* fabricate(Context* context) = 0; |
---|
[5929] | 58 | }; |
---|
| 59 | |
---|
[1505] | 60 | // ############################### |
---|
| 61 | // ### ClassFactory ### |
---|
| 62 | // ############################### |
---|
[9667] | 63 | /// The ClassFactory is the base-class of all class-spezific factories |
---|
[1505] | 64 | template <class T> |
---|
[5929] | 65 | class ClassFactory : public Factory |
---|
[1505] | 66 | { |
---|
[9667] | 67 | }; |
---|
| 68 | |
---|
| 69 | // ############################### |
---|
| 70 | // ### ClassFactoryNoArgs ### |
---|
| 71 | // ############################### |
---|
| 72 | /// The ClassFactoryNoArgs is able to create new objects of a specific class that require no constructor arguments. |
---|
| 73 | template <class T> |
---|
| 74 | class ClassFactoryNoArgs : public ClassFactory<T> |
---|
| 75 | { |
---|
[1505] | 76 | public: |
---|
[5929] | 77 | /** |
---|
[9667] | 78 | @brief Creates and returns a new object of class T. |
---|
| 79 | @return The new object |
---|
[5929] | 80 | */ |
---|
[9667] | 81 | inline Identifiable* fabricate(Context* context) |
---|
[5929] | 82 | { |
---|
[9667] | 83 | return static_cast<Identifiable*>(new T()); |
---|
[5929] | 84 | } |
---|
[9667] | 85 | }; |
---|
[1505] | 86 | |
---|
[9667] | 87 | // ############################### |
---|
| 88 | // ### ClassFactoryWithContext ### |
---|
| 89 | // ############################### |
---|
| 90 | /// The ClassFactoryWithContext is able to create new objects of a specific class that require a context as constructor argument |
---|
| 91 | template <class T> |
---|
| 92 | class ClassFactoryWithContext : public ClassFactory<T> |
---|
| 93 | { |
---|
| 94 | public: |
---|
[5929] | 95 | /** |
---|
| 96 | @brief Creates and returns a new object of class T. |
---|
| 97 | @return The new object |
---|
| 98 | */ |
---|
[9667] | 99 | inline Identifiable* fabricate(Context* context) |
---|
[5929] | 100 | { |
---|
[9667] | 101 | return static_cast<Identifiable*>(new T(context)); |
---|
[5929] | 102 | } |
---|
[1505] | 103 | }; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | #endif /* _ClassFactory_H__ */ |
---|