Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 7, 2008, 5:01:44 PM (17 years ago)
Author:
nicolasc
Message:

merged FICN back into trunk
awaiting release.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

    • Property svn:ignore set to
      dependencies
  • 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
    135#ifndef _ClassFactory_H__
    236#define _ClassFactory_H__
    337
     38#include <string>
     39
     40#include "CorePrereqs.h"
     41
     42#include "Factory.h"
    443#include "Identifier.h"
     44#include "Debug.h"
    545
    646namespace orxonox
     
    949    // ###      ClassFactory       ###
    1050    // ###############################
     51    //! The ClassFactory is able to create new objects of a specific class.
    1152    template <class T>
    1253    class ClassFactory : public BaseFactory
    1354    {
    1455        public:
    15             static bool create();
     56            static bool create(const std::string& name);
    1657            BaseObject* fabricate();
    1758
    1859        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
    2263
    2364            static T* createNewObject();
    2465    };
    2566
     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    */
    2671    template <class T>
    27     bool ClassFactory<T>::create()
     72    bool ClassFactory<T>::create(const std::string& name)
    2873    {
     74        COUT(4) << "*** Create entry for " << name << " in Factory." << std::endl;
    2975        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());
    3877
    3978        return true;
    4079    }
    4180
     81    /**
     82        @brief Creates and returns a new object of class T.
     83        @return The new object
     84    */
    4285    template <class T>
    4386    BaseObject* ClassFactory<T>::fabricate()
     
    4689    }
    4790
     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    */
    4895    template <class T>
    4996    T* ClassFactory<T>::createNewObject()
     
    53100}
    54101
    55 #endif
     102#endif /* _ClassFactory_H__ */
Note: See TracChangeset for help on using the changeset viewer.