Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/object/ClassFactory.h @ 10408

Last change on this file since 10408 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
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/**
30    @file
31    @ingroup Object Factory
32    @brief Definition and implementation of the ClassFactory class
33
34    The ClassFactory is able to create new objects of a specific class which creates objects.
35*/
36
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
46namespace orxonox
47{
48    // ###########################
49    // ###       Factory       ###
50    // ###########################
51    /// Base-class of all factories.
52    class _CoreExport Factory
53    {
54        public:
55            virtual ~Factory() {}
56            virtual Identifiable* fabricate(Context* context) = 0;
57    };
58
59    // ###############################
60    // ###      ClassFactory       ###
61    // ###############################
62    /// The ClassFactory is the base-class of all class-spezific factories
63    template <class T>
64    class ClassFactory : public Factory
65    {
66    };
67
68    // ###############################
69    // ###   ClassFactoryNoArgs    ###
70    // ###############################
71    /// The ClassFactoryNoArgs is able to create new objects of a specific class that require no constructor arguments.
72    template <class T>
73    class ClassFactoryNoArgs : public ClassFactory<T>
74    {
75        public:
76            /**
77                @brief Creates and returns a new object of class T.
78                @return The new object
79            */
80            inline Identifiable* fabricate(Context* context)
81            {
82                return static_cast<Identifiable*>(new T());
83            }
84    };
85
86    // ###############################
87    // ### ClassFactoryWithContext ###
88    // ###############################
89    /// The ClassFactoryWithContext is able to create new objects of a specific class that require a context as constructor argument
90    template <class T>
91    class ClassFactoryWithContext : public ClassFactory<T>
92    {
93        public:
94            /**
95                @brief Creates and returns a new object of class T.
96                @return The new object
97            */
98            inline Identifiable* fabricate(Context* context)
99            {
100                return static_cast<Identifiable*>(new T(context));
101            }
102    };
103}
104
105#endif /* _ClassFactory_H__ */
Note: See TracBrowser for help on using the repository browser.