Orxonox  0.0.5 Codename: Arcturus
ClassFactory.h
Go to the documentation of this file.
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 
37 #ifndef _ClassFactory_H__
38 #define _ClassFactory_H__
39 
40 #include "core/CorePrereqs.h"
41 
42 #include <string>
43 
44 #include "util/Output.h"
45 
46 namespace orxonox
47 {
48  // ###########################
49  // ### Factory ###
50  // ###########################
53  {
54  public:
55  Factory() = default;
56  virtual ~Factory() = default;
57  virtual Identifiable* fabricate(Context* context) = 0;
58  };
59 
60  // ###############################
61  // ### ClassFactory ###
62  // ###############################
64  template <class T>
65  class ClassFactory : public Factory
66  {
67  };
68 
69  // ###############################
70  // ### ClassFactoryNoArgs ###
71  // ###############################
73  template <class T>
74  class ClassFactoryNoArgs : public ClassFactory<T>
75  {
76  public:
81  inline Identifiable* fabricate(Context* context)
82  {
83  return static_cast<Identifiable*>(new T());
84  }
85  };
86 
87  // ###############################
88  // ### ClassFactoryWithContext ###
89  // ###############################
91  template <class T>
92  class ClassFactoryWithContext : public ClassFactory<T>
93  {
94  public:
99  inline Identifiable* fabricate(Context* context)
100  {
101  return static_cast<Identifiable*>(new T(context));
102  }
103  };
104 }
105 
106 #endif /* _ClassFactory_H__ */
Identifiable * fabricate(Context *context)
Creates and returns a new object of class T.
Definition: ClassFactory.h:81
Shared library macros, enums, constants and forward declarations for the core library ...
The ClassFactoryNoArgs is able to create new objects of a specific class that require no constructor ...
Definition: ClassFactory.h:74
Identifiable is needed to create the class-hierarchy at startup and to store the Identifier.
Definition: Identifiable.h:50
The ClassFactoryWithContext is able to create new objects of a specific class that require a context ...
Definition: CorePrereqs.h:151
Identifiable * fabricate(Context *context)
Creates and returns a new object of class T.
Definition: ClassFactory.h:99
The ClassFactory is the base-class of all class-spezific factories.
Definition: CorePrereqs.h:149
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
#define _CoreExport
Definition: CorePrereqs.h:61
Defines the helper function orxout() and includes all necessary headers to use the output system...
Definition: InputPrereqs.h:78
Definition: Context.h:45
Base-class of all factories.
Definition: ClassFactory.h:52