Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/loading/factory.h @ 9757

Last change on this file since 9757 was 9757, checked in by bensch, 18 years ago

new_class_id: hups… this was bad naming… confusing too.

File size: 2.6 KB
RevLine 
[4597]1/*
[4250]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Christian Meyer
13   co-programmer: Benjamin Grauer
14*/
15
[4597]16/*!
[4885]17 * @file factory.h
18 * @brief A loadable object handler
[3940]19*/
20
[4250]21
[9709]22#ifndef __FACTORY_H
23#define __FACTORY_H
[3940]24
25class BaseObject;
26
[5944]27#include "parser/tinyxml/tinyxml.h"
[4597]28#include "base_object.h"
[6341]29#include <list>
[3940]30
[4597]31/**
[4885]32 * Creates a factory to a Loadable Class.
33 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
[7221]34 */
[9709]35#define CREATE_FACTORY(CLASS_NAME) \
[9757]36    tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(CLASS_NAME::staticClassID())
[4487]37
38//! The Factory is a loadable object handler
[9684]39class Factory : public BaseObject
40{
[9715]41  ObjectListDeclaration(Factory);
[9684]42public:
[5156]43  virtual ~Factory ();
[3940]44
[5982]45  static void deleteFactories();
[4739]46
[7221]47  static  BaseObject* fabricate(const std::string& className);
[9715]48  static  BaseObject* fabricate(const ClassID& classID);
[9709]49  static  BaseObject* fabricate(const TiXmlElement* root);
[4597]50
[5984]51
[9684]52  bool operator==(int classID) const;
[7221]53  bool operator==(const std::string& className) const;
[9715]54  bool operator==(const ClassID& classID) const { return _classID == classID; };
[5982]55
[9684]56protected:
[9715]57  Factory (const ClassID& id);
[9684]58  virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
[4932]59
[9709]60private:
61  Factory (const Factory&) {};
62
[9684]63protected:
[9715]64  const ClassID              _classID;              //!< The Class-Identifyer of the Factory.
[9686]65  static std::list<Factory*>*   _factoryList;          //!< List of Registered Factories
[3940]66};
67
[4487]68/**
[7221]69 *  @brief a factory that is able to load any kind of Object
[5750]70 * (this is a Functor)
71 */
[4004]72template<class T> class tFactory : public Factory
73{
[9684]74public:
75  /**
76   * @brief creates a new type Factory to enable the loading of T
77   * @param factoryName the Name of the Factory to load.
78   * @param classID the ID of the Class to be created.
79   */
[9715]80  tFactory (const ClassID& classID)
[9709]81      : Factory(classID)
[5984]82  {  }
[4597]83
[9684]84private:
[9709]85  tFactory (const tFactory&) {};
[9684]86  /**
87   * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
88   * @param root the TiXmlElement T should load parameters from.
89   * @return the newly fabricated T.
90   */
91  virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const
92  {
93    return new T(root);
94  }
[4004]95};
96
[3940]97#endif /* _FACTORY_H */
98
Note: See TracBrowser for help on using the repository browser.