Changeset 790 for code/trunk/src/orxonox/core/ClassFactory.h
- Timestamp:
- Feb 7, 2008, 5:01:44 PM (17 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
Property
svn:ignore
set to
dependencies
-
Property
svn:ignore
set to
-
code/trunk/src/orxonox/core/ClassFactory.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file ClassFactory.h 30 @brief Definition and implementation of the ClassFactory class 31 32 The ClassFactory is able to create new objects of a specific class. 33 */ 34 1 35 #ifndef _ClassFactory_H__ 2 36 #define _ClassFactory_H__ 3 37 38 #include <string> 39 40 #include "CorePrereqs.h" 41 42 #include "Factory.h" 4 43 #include "Identifier.h" 44 #include "Debug.h" 5 45 6 46 namespace orxonox … … 9 49 // ### ClassFactory ### 10 50 // ############################### 51 //! The ClassFactory is able to create new objects of a specific class. 11 52 template <class T> 12 53 class ClassFactory : public BaseFactory 13 54 { 14 55 public: 15 static bool create( );56 static bool create(const std::string& name); 16 57 BaseObject* fabricate(); 17 58 18 59 private: 19 ClassFactory() {} 20 ClassFactory(const ClassFactory& factory) {} 21 ~ClassFactory() {}60 ClassFactory() {} // Don't create 61 ClassFactory(const ClassFactory& factory) {} // Don't copy 62 virtual ~ClassFactory() {} // Don't delete 22 63 23 64 static T* createNewObject(); 24 65 }; 25 66 67 /** 68 @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory. 69 @return Always true (this is needed because the compiler only allows assignments before main()) 70 */ 26 71 template <class T> 27 bool ClassFactory<T>::create( )72 bool ClassFactory<T>::create(const std::string& name) 28 73 { 74 COUT(4) << "*** Create entry for " << name << " in Factory." << std::endl; 29 75 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(); 76 Factory::add(name, ClassIdentifier<T>::getIdentifier()); 38 77 39 78 return true; 40 79 } 41 80 81 /** 82 @brief Creates and returns a new object of class T. 83 @return The new object 84 */ 42 85 template <class T> 43 86 BaseObject* ClassFactory<T>::fabricate() … … 46 89 } 47 90 91 /** 92 @brief Creates and returns a new object of class T; this is a wrapper for the new operator. 93 @return The new object 94 */ 48 95 template <class T> 49 96 T* ClassFactory<T>::createNewObject() … … 53 100 } 54 101 55 #endif 102 #endif /* _ClassFactory_H__ */
Note: See TracChangeset
for help on using the changeset viewer.