Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelLoader: SkyBox loadable in the new Style

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