Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelLoader/src/util/loading/factory.h @ 4251

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

orxonox/branches/levelLoader: some minor changes

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(x) tFactory<x>* global_ ## x ## Factory = new tFactory<x>(#x)
36
37
38               
39//! The Factory is
40class Factory {
41
42 public:
43  Factory (const char* name = NULL);
44  ~Factory ();
45 
46
47  virtual BaseObject* fabricate( TiXmlElement* root);
48  void initialize();
49  void registerFactory( Factory* factory);
50  void setFactoryName(const char* name);
51  const char* getFactoryName() {return factoryName;};
52  void setNext( Factory* factory) {next = factory;}
53  Factory* getNext() {return next;}
54       
55 private:
56  char* factoryName;
57       
58  Factory* next;
59};
60
61template<class T> class tFactory : public Factory
62{
63 public:
64  tFactory(const char* name);
65  virtual ~tFactory();
66 
67  private:
68  BaseObject* fabricate( TiXmlElement* root);
69};
70
71template<class T>
72tFactory<T>::tFactory(const char* name) : Factory(name)
73{
74  PRINTF(5)("fileName: %s\n", name);
75}
76 
77
78template<class T>
79tFactory<T>::~tFactory()
80{}
81
82template<class T>
83BaseObject* tFactory<T>::fabricate( TiXmlElement* root) 
84{ 
85  if(!strcmp(root->Value(), getFactoryName()))
86    return new T ( root);
87  else if( getNext() != NULL) 
88    return getNext()->fabricate( root);
89  else 
90    return NULL;
91}
92
93// helper function
94
95const char* grabParameter(const TiXmlElement* root, const char* name);
96
97#endif /* _FACTORY_H */
98
Note: See TracBrowser for help on using the repository browser.