Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/movie_player/src/factory.h @ 4582

Last change on this file since 4582 was 4217, checked in by bensch, 20 years ago

orxonox/branches/movie_player: merged the trunk back into the movie_player
merged with command:
svn merge -r 4014:HEAD ../trunk/ movie_player/
no conflicts

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 "xmlparser/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( TiXmlElement* root, const char* name);
82
83#endif /* _FACTORY_H */
84
Note: See TracBrowser for help on using the repository browser.