Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/util/loading/factory.h @ 6175

Last change on this file since 6175 was 5985, checked in by manuel, 19 years ago

merge: factory has now create from class name string function (svn merge -r 5955:HEAD ../trunk/ powerups/)

File size: 2.4 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
[3940]22#ifndef _FACTORY_H
23#define _FACTORY_H
24
25class BaseObject;
26
[5955]27#include "parser/tinyxml/tinyxml.h"
[4597]28#include "base_object.h"
[4171]29#include "debug.h"
[5985]30#include <vector>
[3940]31
[4597]32/**
[4885]33 * Creates a factory to a Loadable Class.
34 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
[4004]35*/
[5750]36#define CREATE_FACTORY(CLASS_NAME, CLASS_ID) \
37    tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
[4487]38
39//! The Factory is a loadable object handler
[4597]40class Factory : public BaseObject {
[3940]41
42 public:
[5985]43  Factory (const char* factoryName, ClassID classID);
[5156]44  virtual ~Factory ();
[3940]45
[5985]46  static void deleteFactories();
[4739]47
[5985]48  static  BaseObject* fabricate(const char* className);
49  static  BaseObject* fabricate(ClassID classID);
50  static  BaseObject* fabricate(const TiXmlElement* root = NULL);
[4597]51
[5985]52  bool operator==(ClassID classID) const { return (this->classID == classID); };
53  bool operator==(const char* className) const;
54
[4932]55  protected:
[5985]56    virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
[4932]57
[5750]58  protected:
[5985]59    ClassID                       classID;              //!< The Class-Identifyer of the Factory.
60    const char*                   className;            //!< The name of the Class.
61    static std::list<Factory*>*   factoryList;          //!< List of Registered Factories
[3940]62};
63
[4487]64/**
[4836]65 *  a factory that is able to load any kind of Object
[5750]66 * (this is a Functor)
67 */
[4004]68template<class T> class tFactory : public Factory
69{
[5985]70 public:
71  tFactory (const char* factoryName, ClassID classID)
72   : Factory(factoryName, classID)
73  {
74  }
[4597]75
[4004]76  private:
[5985]77   /**
78    * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
79    * @param root the TiXmlElement T should load parameters from.
80    * @return the newly fabricated T.
81    */
82    virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const
83    {
84      return new T(root);
85    }
[4004]86};
87
[3940]88#endif /* _FACTORY_H */
89
Note: See TracBrowser for help on using the repository browser.