Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4004 in orxonox.OLD for orxonox/branches/ll2trunktemp


Ignore:
Timestamp:
Apr 28, 2005, 7:41:27 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/ll2trunktemp: changed the Factory-Macro into a Template, this code will be easyer to read and to debug
also found the segfault when deleting orxonox.
each factory tried to delete itself, because they were initialized implicitely (not with new).
now we only have to delete the first factory at the beginning

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

Legend:

Unmodified
Added
Removed
  • orxonox/branches/ll2trunktemp/src/factory.cc

    r4003 r4004  
    3030   set everything to zero and define classname
    3131*/
    32 Factory::Factory ()
     32Factory::Factory (const char* name)
    3333{
    34   classname = "NULL";
     34  this->setClassname(name);
    3535  next = NULL;
    3636 
     
    4545Factory::~Factory ()
    4646{
    47   printf("%s\n", this->classname);
    48   Factory* tmpDel = this->next;
    49   this->next = NULL;
    50   //  if (tmpDel)
    51   //    delete tmpDel;
     47  //  printf("%s\n", this->classname);
     48  //  Factory* tmpDel = this->next;
     49  //  this->next = NULL;
     50  if (this->next)
     51    delete this->next;
    5252}
     53
     54void Factory::setClassname(const char* name)
     55{
     56  if (classname)
     57    delete classname;
     58  classname = new char[strlen(name)+1];
     59  strcpy(classname, name);
     60}
     61
    5362
    5463/**
  • orxonox/branches/ll2trunktemp/src/factory.h

    r4003 r4004  
    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;
     13/**
     14    Creates a factory to a Loadable Class.
     15    this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
     16*/
     17#define CREATE_FACTORY(x) tFactory<x>* global_ ## x ## Factory = new tFactory<x>(#x);
     18
     19
    2720               
    2821//! The Factory is
     
    3326
    3427 public:
    35   Factory ();
     28  Factory (const char* name = NULL);
    3629  ~Factory ();
    3730 
     
    4033  void initialize();
    4134  void registerFactory( Factory* factory);
    42   void setClassname(char* name) {classname = name;}
    43   char* getClassname() {return classname;};
     35  void setClassname(const char* name);
     36  const char* getClassname() {return classname;};
    4437  void setNext( Factory* factory) {next = factory;}
    4538  Factory* getNext() {return next;}
     
    5144};
    5245
     46template<class T> class tFactory : public Factory
     47{
     48 public:
     49  tFactory(const char* name);
     50  virtual ~tFactory();
     51 
     52  private:
     53  BaseObject* fabricate( TiXmlElement* root);
     54};
     55
     56template<class T>
     57tFactory<T>::tFactory(const char* name) : Factory(name)
     58{
     59  printf("fileName: %s\n", name);
     60}
     61 
     62
     63template<class T>
     64tFactory<T>::~tFactory()
     65{}
     66
     67template<class T>
     68BaseObject* tFactory<T>::fabricate( TiXmlElement* root)
     69{
     70  if(!strcmp(root->Value(), getClassname()))
     71    return new T ( root);
     72  else if( getNext() != NULL)
     73    return getNext()->fabricate( root);
     74  else
     75    return NULL;
     76}
     77
    5378// helper function
    5479
    5580const char* grabParameter( TiXmlElement* root, const char* name);
    5681
     82
     83
     84
    5785#endif /* _FACTORY_H */
    5886
  • orxonox/branches/ll2trunktemp/src/game_loader.cc

    r4003 r4004  
    2525#include "command_node.h"
    2626#include "vector.h"
     27#include "factory.h"
    2728
    2829#include <string.h>
     
    188189    {
    189190      // report an error
    190       PRINTF0("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     191      PRINTF(0)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
    191192      delete XMLDoc;
    192193      return NULL;
  • orxonox/branches/ll2trunktemp/src/game_loader.h

    r3940 r4004  
    1010#include "story_def.h"
    1111#include "comincl.h"
     12
    1213
    1314//-----------------------------------------------------------------------------
  • orxonox/branches/ll2trunktemp/src/orxonox.cc

    r3989 r4004  
    3434#include "resource_manager.h"
    3535#include "text_engine.h"
     36#include "factory.h"
    3637
    3738#include <string.h>
  • orxonox/branches/ll2trunktemp/src/story_entities/world.cc

    r3994 r4004  
    114114}
    115115
    116 CREATE_FACTORY(World)
     116CREATE_FACTORY(World);
    117117
    118118World::World( TiXmlElement* root)
Note: See TracChangeset for help on using the changeset viewer.