Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelLoader: capabilities for documentation are close by

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