Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelLoader/src/factory.h @ 4239

Last change on this file since 4239 was 4239, checked in by bensch, 19 years ago

orxonox/branches/levelLoader: factory not in stdincl anymore

File size: 1.6 KB
Line 
1/*!
2    \file factory.h
3    \brief philosophy stuff
4*/
5
6#ifndef _FACTORY_H
7#define _FACTORY_H
8
9class BaseObject;
10
11#include "tinyxml.h"
12#include "debug.h"
13
14/**
15    Creates a factory to a Loadable Class.
16    this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
17*/
18#define CREATE_FACTORY(x) tFactory<x>* global_ ## x ## Factory = new tFactory<x>(#x)
19
20
21               
22//! The Factory is
23/**
24   Very philosophic description, huh?
25*/
26class Factory {
27
28 public:
29  Factory (const char* name = NULL);
30  ~Factory ();
31 
32
33  virtual BaseObject* fabricate( TiXmlElement* root);
34  void initialize();
35  void registerFactory( Factory* factory);
36  void setFactoryName(const char* name);
37  const char* getFactoryName() {return factoryName;};
38  void setNext( Factory* factory) {next = factory;}
39  Factory* getNext() {return next;}
40       
41 private:
42  char* factoryName;
43       
44  Factory* next;
45};
46
47template<class T> class tFactory : public Factory
48{
49 public:
50  tFactory(const char* name);
51  virtual ~tFactory();
52 
53  private:
54  BaseObject* fabricate( TiXmlElement* root);
55};
56
57template<class T>
58tFactory<T>::tFactory(const char* name) : Factory(name)
59{
60  PRINTF(5)("fileName: %s\n", name);
61}
62 
63
64template<class T>
65tFactory<T>::~tFactory()
66{}
67
68template<class T>
69BaseObject* tFactory<T>::fabricate( TiXmlElement* root) 
70{ 
71  if(!strcmp(root->Value(), getFactoryName()))
72    return new T ( root);
73  else if( getNext() != NULL) 
74    return getNext()->fabricate( root);
75  else 
76    return NULL;
77}
78
79// helper function
80
81const char* grabParameter(const TiXmlElement* root, const char* name);
82
83#endif /* _FACTORY_H */
84
Note: See TracBrowser for help on using the repository browser.