Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/core/ClassFactory.h @ 632

Last change on this file since 632 was 258, checked in by landauf, 17 years ago

merged object-hierarchy back to trunk

File size: 1.3 KB
Line 
1#ifndef _ClassFactory_H__
2#define _ClassFactory_H__
3
4#include "Identifier.h"
5
6namespace orxonox
7{
8    // ###############################
9    // ###      ClassFactory       ###
10    // ###############################
11    template <class T>
12    class ClassFactory : public BaseFactory
13    {
14        public:
15            static bool create();
16            BaseObject* fabricate();
17
18        private:
19            ClassFactory() {}
20            ClassFactory(const ClassFactory& factory) {}
21            ~ClassFactory() {}
22
23            static T* createNewObject();
24    };
25
26    template <class T>
27    bool ClassFactory<T>::create()
28    {
29        ClassIdentifier<T>::getIdentifier()->addFactory(new ClassFactory<T>);
30
31        ClassIdentifier<T>::getIdentifier()->startCreatingHierarchy();
32#if HIERARCHY_VERBOSE
33        std::cout << "*** Create Factory -> Create Class\n";
34#endif
35        BaseObject* temp = ClassIdentifier<T>::getIdentifier()->fabricate();
36        delete temp;
37        ClassIdentifier<T>::getIdentifier()->stopCreatingHierarchy();
38
39        return true;
40    }
41
42    template <class T>
43    BaseObject* ClassFactory<T>::fabricate()
44    {
45        return ClassFactory<T>::createNewObject();
46    }
47
48    template <class T>
49    T* ClassFactory<T>::createNewObject()
50    {
51        return new T;
52    }
53}
54
55#endif
Note: See TracBrowser for help on using the repository browser.