Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4003 in orxonox.OLD


Ignore:
Timestamp:
Apr 28, 2005, 2:25:08 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/ll2trunktemp: some small modifications, testing, why 2 instances of fabricate are deleted, and not just the first one

Location:
orxonox/branches/ll2trunktemp/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/ll2trunktemp/src/defs/stdincl.h

    r3940 r4003  
    3030#include "factory.h"
    3131
    32 #define CREATE_FACTORY(x) \
    33                 class x ## Factory : public Factory { \
    34                  public:        \
    35                   x ## Factory (){setNext( NULL); setClassname( #x ); initialize();} \
    36                   ~x ## Factory () {}; \
    37                  private: \
    38                         BaseObject* fabricate( TiXmlElement* root) \
    39                         { \
    40                                 if(!strcmp(root->Value(), getClassname())) return new  x ( root); \
    41                                 else if( getNext() != NULL) return getNext()->fabricate( root); \
    42                                 else return NULL; \
    43                         } \
    44                 }; \
    45                 x ## Factory global_ ## x ## Factory;
    46                
    4732#endif /* _STDINCL_H */
  • orxonox/branches/ll2trunktemp/src/factory.cc

    r3994 r4003  
    1 
    2 
    31/*
    42   orxonox - the future of 3D-vertical-scrollers
     
    2321
    2422/*  --------------------------------------------------
    25 *                Factory
    26 *   --------------------------------------------------
    27 */
     23 *               Factory
     24 *   --------------------------------------------------
     25 */
    2826
    2927/**
     
    3432Factory::Factory ()
    3533{
    36         classname = "NULL";
    37         next = NULL;
     34  classname = "NULL";
     35  next = NULL;
     36 
     37  initialize();
    3838}
    3939
     
    4545Factory::~Factory ()
    4646{
    47   //if( next != NULL)   delete next;
     47  printf("%s\n", this->classname);
     48  Factory* tmpDel = this->next;
     49  this->next = NULL;
     50  //  if (tmpDel)
     51  //    delete tmpDel;
    4852}
    49 
    5053
    5154/**
     
    5457BaseObject* Factory::fabricate( TiXmlElement* data)
    5558{
    56         return NULL;
     59  return NULL;
    5760}
    5861
     
    6265void Factory::initialize()
    6366{
    64         assert( classname != NULL);
    65         GameLoader* gl = GameLoader::getInstance();
    66         gl->registerFactory( this);
     67  assert( classname != NULL);
     68  GameLoader* gl = GameLoader::getInstance();
     69  gl->registerFactory( this);
    6770}
    6871
     
    7275void Factory::registerFactory( Factory* factory)
    7376{
    74         if( next == NULL) setNext( factory);
    75         else next->registerFactory( factory);
     77  if( next == NULL) setNext( factory);
     78  else next->registerFactory( factory);
    7679}
    7780
    7881const char* grabParameter( TiXmlElement* root, const char* name)
    7982{
    80         TiXmlElement* element;
    81         TiXmlNode* node;
     83  TiXmlElement* element;
     84  TiXmlNode* node;
    8285       
    83         assert( root != NULL);
    84         assert( name != NULL);
     86  assert( root != NULL);
     87  assert( name != NULL);
    8588       
    86         element = root->FirstChildElement( name);
    87         if( element == NULL) return NULL;
     89  element = root->FirstChildElement( name);
     90  if( element == NULL) return NULL;
    8891       
    89         node = element->FirstChild();
    90         while( node != NULL)
    91         {
    92                 if( node->ToText()) return node->Value();
    93                 node = node->NextSibling();
    94         }
    95         return NULL;
     92  node = element->FirstChild();
     93  while( node != NULL)
     94    {
     95      if( node->ToText()) return node->Value();
     96      node = node->NextSibling();
     97    }
     98  return NULL;
    9699}
    97100
  • orxonox/branches/ll2trunktemp/src/factory.h

    r3940 r4003  
    1111#include "xmlparser/tinyxml.h"
    1212
     13#define CREATE_FACTORY(x) \
     14                class x ## Factory : public Factory { \
     15                 public:        \
     16                  x ## Factory (){setClassname( #x );} \
     17                  ~x ## Factory () {}; \
     18                 private: \
     19                        BaseObject* fabricate( TiXmlElement* root) \
     20                        { \
     21                                if(!strcmp(root->Value(), getClassname())) return new  x ( root); \
     22                                else if( getNext() != NULL) return getNext()->fabricate( root); \
     23                                else return NULL; \
     24                        } \
     25                }; \
     26                x ## Factory global_ ## x ## Factory;
     27               
    1328//! The Factory is
    1429/**
    15         Very philosophic description, huh?
     30   Very philosophic description, huh?
    1631*/
    1732class Factory {
     
    2035  Factory ();
    2136  ~Factory ();
     37 
    2238
    23         virtual BaseObject* fabricate( TiXmlElement* root);
    24         void initialize();
    25         void registerFactory( Factory* factory);
    26         void setClassname(char* name) {classname = name;}
    27         char* getClassname() {return classname;};
    28         void setNext( Factory* factory) {next = factory;}
    29         Factory* getNext() {return next;}
     39  virtual BaseObject* fabricate( TiXmlElement* root);
     40  void initialize();
     41  void registerFactory( Factory* factory);
     42  void setClassname(char* name) {classname = name;}
     43  char* getClassname() {return classname;};
     44  void setNext( Factory* factory) {next = factory;}
     45  Factory* getNext() {return next;}
    3046       
    3147 private:
    32         char* classname;
     48  char* classname;
    3349       
    3450  Factory* next;
  • orxonox/branches/ll2trunktemp/src/game_loader.cc

    r3989 r4003  
    166166 
    167167  if( name == NULL)
    168   {
    169                 PRINTF0("No filename specified for loading");
    170                 return NULL;
    171   }
     168    {
     169      PRINTF0("No filename specified for loading");
     170      return NULL;
     171    }
    172172 
    173         TiXmlDocument* XMLDoc = new TiXmlDocument( name);
    174         // load the campaign document
    175         if( !XMLDoc->LoadFile())
    176         {
    177                 // report an error
    178                 PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    179                 delete XMLDoc;
    180                 return NULL;
    181         }
    182        
    183         // check basic validity
    184         TiXmlElement* root = XMLDoc->RootElement();
    185         assert( root != NULL);
    186        
    187         if( strcmp( root->Value(), "Campaign"))
    188         {
    189                 // report an error
    190                 PRINTF0("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
    191                 delete XMLDoc;
    192                 return NULL;
    193         }
    194        
    195         // construct campaign
    196         Campaign* c = new Campaign( root);
    197        
    198         // free the XML data
    199         delete XMLDoc;
    200        
    201         return c;
     173  TiXmlDocument* XMLDoc = new TiXmlDocument( name);
     174  // load the campaign document
     175  if( !XMLDoc->LoadFile())
     176    {
     177      // report an error
     178      PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     179      delete XMLDoc;
     180      return NULL;
     181    }
     182       
     183  // check basic validity
     184  TiXmlElement* root = XMLDoc->RootElement();
     185  assert( root != NULL);
     186       
     187  if( strcmp( root->Value(), "Campaign"))
     188    {
     189      // report an error
     190      PRINTF0("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     191      delete XMLDoc;
     192      return NULL;
     193    }
     194       
     195  // construct campaign
     196  Campaign* c = new Campaign( root);
     197       
     198  // free the XML data
     199  delete XMLDoc;
     200       
     201  return c;
    202202}
    203203
Note: See TracChangeset for help on using the changeset viewer.