Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelloader: Finished implementation of LevelFactory and associated, only thing left to do is testing

File size: 2.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#include "orxonox.h"
14#include "world.h"
15
16class LoadParameters;
17
18#define FACTORY_ADD(CLASS) class CLASSFactory : public ObjectFactory { \
19 public:        \
20  CLASSFactory (){setNext( NULL); setClassname = "CLASS"; initialize();} \
21  ~CLASSFactory (); \
22 private: \
23        BaseObject* fabricateObject( LoadParameters* data) { return new CLASS( data);} \
24}; \
25CLASSFactory global_CLASSFactory();
26
27//! The Objectfactory is a virtual class that can be stored by the LevelFactory
28/**
29        The Objectfactory is just a definition of interface to be used with the LevelFactory
30*/
31class ObjectFactory {
32
33 public:
34  ObjectFactory ();
35  ~ObjectFactory ();
36
37        BaseObject* load( char* name, LoadParameters* data);
38        void initialize();
39  void registerFactory( ObjectFactory* factory);
40        void setClassname(char* name) {classname = name};
41        char* getClassname() {return classname};
42        void setNext( ObjectFactory* factory);
43       
44 private:
45        virtual BaseObject* fabricateObject( LoadParameters* data);
46        char* classname;
47       
48  ObjectFactory* next;
49};
50
51//! The Levelfactory is a simpleton class that serves as a central node for object archivation
52/**
53   The LevelFactory is desigend to serve as a node for the loading and stroing of objects within a level based context.
54   Any class that attaches the FACTORY_ADD() macro will register itself to the Factory at the beginning of execution,
55   enabling the factory to recognize this type of class.
56*/
57class LevelFactory {
58
59 public:
60  LevelFactory ();
61  ~LevelFactory ();
62 
63  static LevelFactory* getInstance();
64
65  void registerFactory( ObjectFactory* factory);
66  int loadXMLFile( char* filename);
67 
68 private:
69        static LevelFactory singletonRef*;
70       
71  ObjectFactory* first;
72 
73};
74
75//! The LoadParameters class is designed for encapsulated interfacing between TiXML and a loading costructor
76/**
77   This is the liaison between the ObjectFactories and their Objects. A LoadParameters object is passed to
78   the constructors of the objects when the ObjectFactory creates it. It can be easily parsed and features
79   special variable handling methods to extract numeric data from strings.
80*/
81class LoadParameters {
82       
83        public:
84                LoadParameters() {root = NULL;}
85                LoadParameters(TiXMLElement* element) {root = element;}
86                ~LoadParameters() {}
87               
88                const char* grabParameter( const char* name);
89                const char* grabParameter( const char* name, int* i);
90                const char* grabParameter( const char* name, double* d);
91               
92                void setElement(TiXMLElement* element) {root = element;}
93                TiXMLElement* getElement() {return root;}
94               
95        private:
96                TiXMLElement* root;
97       
98};
99
100#endif /* _LEVELFACTORY_H */
Note: See TracBrowser for help on using the repository browser.