Orxonox  0.0.5 Codename: Arcturus
CoreIncludes.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 
77 #ifndef _CoreIncludes_H__
78 #define _CoreIncludes_H__
79 
80 #include "CorePrereqs.h"
81 
82 #include "util/Output.h"
84 #include "object/ClassFactory.h"
85 #include "object/ObjectList.h"
87 
88 // resolve macro conflict on windows
89 #if defined(ORXONOX_PLATFORM_WINDOWS)
90 # define WIN32_LEAN_AND_MEAN
91 # include <windows.h>
92 # undef RegisterClass
93 #endif
94 
95 
100 #define RegisterClass(ClassName) \
101  RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), true)
102 
107 #define RegisterClassNoArgs(ClassName) \
108  RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryNoArgs<ClassName>(), true)
109 
114 #define RegisterUnloadableClass(ClassName) \
115  RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), false)
116 
121 #define RegisterAbstractClass(ClassName) \
122  RegisterClassWithFactory(ClassName, static_cast<ClassFactory<ClassName>*>(nullptr), false)
123 
130 #define RegisterClassWithFactory(ClassName, FactoryInstance, bLoadable) \
131  orxonox::SI_I& _##ClassName##Identifier = (*new orxonox::SI_I(orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)))
132 
137 #define RegisterObject(ClassName) \
138  if (ClassIdentifier<ClassName>::getIdentifier()->initializeObject(this)) \
139  return; \
140  else \
141  ((void)0)
142 
147 #define Class(ClassName) \
148  orxonox::ClassIdentifier<ClassName>::getIdentifier()
149 
150 
151 namespace orxonox
152 {
156  template <class T>
157  inline Identifier* registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true)
158  {
159  return registerClass<T>(name, static_cast<Factory*>(factory), bLoadable);
160  }
161 
168  template <class T>
169  inline Identifier* registerClass(const std::string& name, Factory* factory, bool bLoadable = true)
170  {
171  return new ClassIdentifier<T>(name, factory, bLoadable);
172  }
173 
178  inline Identifier* ClassByString(const std::string& name)
179  {
181  }
182 
188  {
190  }
191 
196  inline Identifier* ClassByID(uint32_t id)
197  {
199  }
200 
207  template <class T>
208  inline Identifier* ClassByObjectType(const T* p)
209  {
211  }
212 
213 
214 
215 
221  {
222  template <class T>
224  {
225  virtual Identifier* getParent() const override { return Class(T); }
226  };
227 
228  public:
230  : StaticallyInitializedInstance(StaticInitialization::IDENTIFIER)
231  , identifier_(identifier)
232  {}
233  ~StaticallyInitializedIdentifier() { identifier_->destroy(); }
234 
235  virtual void load() override
236  {
237  IdentifierManager::getInstance().addIdentifier(this->identifier_);
238  }
239 
240  virtual void unload() override
241  {
243  }
244 
246  { return *this->identifier_; }
247 
248  template <class T>
250  { this->identifier_->inheritsFrom(new InheritsFromClass<T>()); return *this; }
251 
253  { this->identifier_->setVirtualBase(true); return *this; }
254 
255  private:
257  };
258 
260 }
261 
262 #endif /* _CoreIncludes_H__ */
StaticallyInitializedIdentifier SI_I
Definition: CoreIncludes.h:259
StaticallyInitializedIdentifier & virtualBase()
Definition: CoreIncludes.h:252
The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables t...
Definition: Identifier.h:262
Identifier * ClassByString(const std::string &name)
Returns the Identifier with a given name.
Definition: CoreIncludes.h:178
void addIdentifier(Identifier *identifier)
Registers the identifier in all maps of the IdentifierManager.
Definition: IdentifierManager.cc:57
~StaticallyInitializedIdentifier()
Definition: CoreIncludes.h:233
void removeIdentifier(Identifier *identifier)
Unregisters the identifier from all maps of the IdentifierManager.
Definition: IdentifierManager.cc:71
Identifier * identifier_
Definition: CoreIncludes.h:256
Shared library macros, enums, constants and forward declarations for the core library ...
::std::string string
Definition: gtest-port.h:756
virtual void load() override
Definition: CoreIncludes.h:235
Identifier * ClassByLowercaseString(const std::string &name)
Returns the Identifier with a given lowercase name.
Definition: CoreIncludes.h:187
helper class to manually define inheritance
Definition: Identifier.h:112
virtual Identifier * getParent() const override
Definition: CoreIncludes.h:225
static constexpr Type IDENTIFIER
Definition: CorePrereqs.h:94
static ClassIdentifier< T > * getIdentifier()
Returns the only instance of this class.
Definition: Identifier.h:329
StaticallyInitializedIdentifier(Identifier *identifier)
Definition: CoreIncludes.h:229
Identifier * ClassByID(uint32_t id)
Returns the Identifier with a given network ID.
Definition: CoreIncludes.h:196
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
Definition: StaticallyInitializedInstance.h:36
#define _CoreExport
Definition: CorePrereqs.h:61
Identifier * getIdentifierByID(uint32_t id)
Returns the Identifier with a given network ID.
Definition: IdentifierManager.cc:246
The Identifier is used to identify the class of an object and to store information about the class...
Definition: Identifier.h:109
Identifier * ClassByObjectType(const T *p)
Returns the Identifier with a given &#39;this&#39; pointer.
Definition: CoreIncludes.h:208
Defines the helper function orxout() and includes all necessary headers to use the output system...
Definition: InputPrereqs.h:78
StaticallyInitializedIdentifier & inheritsFrom()
Definition: CoreIncludes.h:249
Definition of the ObjectList class, a wrapper of ObjectListBase.
Identifier * registerClass(const std::string &name, ClassFactory< T > *factory, bool bLoadable=true)
Overload of registerClass() which determines T implicitly by the template argument of the ClassFactor...
Definition: CoreIncludes.h:157
Identifier * getIdentifierByString(const std::string &name)
Returns the Identifier with a given name.
Definition: IdentifierManager.cc:218
The static initializer stores the parent classes of this identifier.
Definition: CoreIncludes.h:220
Identifier & getIdentifier()
Definition: CoreIncludes.h:245
Identifier * getIdentifierByLowercaseString(const std::string &name)
Returns the Identifier with a given name in lowercase.
Definition: IdentifierManager.cc:232
static IdentifierManager & getInstance()
Returns a reference to the singleton instance.
Definition: Singleton.h:118
Base-class of all factories.
Definition: ClassFactory.h:52
virtual void unload() override
Definition: CoreIncludes.h:240
Definition and implementation of the ClassFactory class.
#define Class(ClassName)
Returns the Identifier of the given class.
Definition: CoreIncludes.h:147