Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/levelfactory.h @ 3482

Last change on this file since 3482 was 3482, checked in by chris, 19 years ago

orxonox/branches/levelloader: Partial implementation of LevelFactory, still missing actual loading of stuff as well as a method to communicate loaded data to objects

File size: 1.8 KB
Line 
1/*!
2    \file levelfactory.h
3    \brief Contains all the classes used for loading a level and its objects from a XML-file
4*/
5
6#ifndef _LEVELFACTORY_H
7#define _LEVELFACTORY_H
8
9#include "stdincl.h"
10#include "xmlparser/tinyxml.h"
11#include "xmlparser/tinystr.h"
12#include "base_object.h"
13
14#define FACTORY_ADD(CLASS) class CLASSFactory : public ObjectFactory { \
15 public:        \
16  CLASSFactory (){setNext( NULL); setClassname = "CLASS"; initialize()}; \
17  ~CLASSFactory (); \
18 private: \
19        BaseObject* fabricateObject( void* data) { return new CLASS( data)}; \
20}; \
21CLASSFactory global_CLASSFactory();
22
23//! The Objectfactory is a virtual class that can be stored by the LevelFactory
24/**
25        The Objectfactory is just a definition of interface to be used with the LevelFactory
26*/
27class ObjectFactory {
28
29 public:
30  ObjectFactory ();
31  ~ObjectFactory ();
32
33        BaseObject* load( char* name, void* data);
34        void initialize();
35  void registerFactory( ObjectFactory* factory);
36        void setClassname(char* name) {classname = name};
37        void setNext( ObjectFactory* factory);
38       
39 private:
40        virtual BaseObject* fabricateObject( void* data);
41        char* classname;
42       
43  ObjectFactory* next;
44};
45
46//! The Levelfactory is a simpleton class that serves as a central node for object archivation
47/**
48   The LevelFactory is desigend to serve as a node for the loading and stroing of objects within a level based context.
49   Any class that attaches the FACTORY_ADD() macro will register itself to the Factory at the beginning of execution,
50   enabling the factory to recognize this type of class.
51*/
52class LevelFactory {
53
54 public:
55  LevelFactory ();
56  ~LevelFactory ();
57 
58  static LevelFactory* getInstance();
59
60  void registerFactory( ObjectFactory* factory);
61  int loadXMLFile( char* filename);
62 
63 private:
64        static LevelFactory singletonRef*;
65       
66  ObjectFactory* first;
67 
68};
69
70#endif /* _LEVELFACTORY_H */
Note: See TracBrowser for help on using the repository browser.