Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/physics/src/util/loading/factory.h @ 4301

Last change on this file since 4301 was 4283, checked in by bensch, 20 years ago

orxonox/branches/physics: merged the trunk back to branches/physics
merged with command
svn merge -r 4223:HEAD ../../trunk/ .
conflicts additively included

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