Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelLoader: constifization

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