Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11481 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 3.2 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            Factory() = default;
56            virtual ~Factory() = default;
57            virtual Identifiable* fabricate(Context* context) = 0;
58    };
59
60    // ###############################
61    // ###      ClassFactory       ###
62    // ###############################
63    /// The ClassFactory is the base-class of all class-spezific factories
64    template <class T>
65    class ClassFactory : public Factory
66    {
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    {
76        public:
77            /**
78                @brief Creates and returns a new object of class T.
79                @return The new object
80            */
81            inline Identifiable* fabricate(Context* context)
82            {
83                return static_cast<Identifiable*>(new T());
84            }
85    };
86
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:
95            /**
96                @brief Creates and returns a new object of class T.
97                @return The new object
98            */
99            inline Identifiable* fabricate(Context* context)
100            {
101                return static_cast<Identifiable*>(new T(context));
102            }
103    };
104}
105
106#endif /* _ClassFactory_H__ */
Note: See TracBrowser for help on using the repository browser.