Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/loading/factory.h @ 7227

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

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

File size: 2.8 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
[5944]27#include "parser/tinyxml/tinyxml.h"
[4597]28#include "base_object.h"
[5982]29#include <vector>
[6341]30#include <list>
[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)
[7221]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
[7167]39// #define CREATE_DYNAMIC_FACTORY(CLASS_NAME, CLASS_ID) \
40//     tFactory<CLASS_NAME>* global_##CLASS_NAME##_Dynamic_Factory = new DynamicLoader<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
41
[4487]42//! The Factory is a loadable object handler
[4597]43class Factory : public BaseObject {
[3940]44
45 public:
[5156]46  virtual ~Factory ();
[3940]47
[5982]48  static void deleteFactories();
[4739]49
[7221]50  static  BaseObject* fabricate(const std::string& className);
[5982]51  static  BaseObject* fabricate(ClassID classID);
52  static  BaseObject* fabricate(const TiXmlElement* root = NULL);
[4597]53
[5984]54
55  bool operator==(ClassID classID) const;
[5982]56  bool operator==(const char* className) const;
[7221]57  bool operator==(const std::string& className) const;
[5982]58
[4932]59  protected:
[7221]60    Factory (const std::string& factoryName, ClassID classID);
[5982]61    virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
[4932]62
[5750]63  protected:
[7221]64    const ClassID                 classID;              //!< The Class-Identifyer of the Factory.
65    const std::string             className;            //!< The name of the Class.
[5982]66    static std::list<Factory*>*   factoryList;          //!< List of Registered Factories
[3940]67};
68
[4487]69/**
[7221]70 *  @brief a factory that is able to load any kind of Object
[5750]71 * (this is a Functor)
72 */
[4004]73template<class T> class tFactory : public Factory
74{
[5982]75 public:
[5984]76 /**
[7221]77  * @brief creates a new type Factory to enable the loading of T
[5984]78  * @param factoryName the Name of the Factory to load.
79  * @param classID the ID of the Class to be created.
80  */
[5982]81  tFactory (const char* factoryName, ClassID classID)
82   : Factory(factoryName, classID)
[5984]83  {  }
[4597]84
[4004]85  private:
[5982]86   /**
[7221]87    * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
[5982]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.