Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9709 in orxonox.OLD for branches/new_class_id/src/lib/util/loading


Ignore:
Timestamp:
Aug 31, 2006, 10:51:08 PM (18 years ago)
Author:
bensch
Message:

orxonox/branches/new_class_id: new_class ID working, adapdet many classes, and reinvented some of the ClassID stuff

Location:
branches/new_class_id/src/lib/util/loading
Files:
3 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/util/loading/dynamic_loader.cc

    r9684 r9709  
    3131*/
    3232DynamicLoader::DynamicLoader (const std::string& libName)
    33     : Factory(NULL, 0)
     33    : Factory(libName)
    3434{
    3535  this->registerObject(this, DynamicLoader::_objectList);
  • branches/new_class_id/src/lib/util/loading/factory.cc

    r9695 r9709  
    2828 * set everything to zero and define factoryName
    2929 */
    30 Factory::Factory (const std::string& factoryName, int classID)
    31     : _classID(classID), _className(factoryName)
     30Factory::Factory (const NewClassID& classID)
     31    : _classID(classID)
    3232{
    33   this->registerObject(this, Factory::_objectList);
    34   this->setName(factoryName);
     33  printf("Factory::create(%s::%d)\n", classID.name().c_str(), classID.id());
     34  //this->registerObject(this, Factory::_objectList);
     35  this->setName(classID.name());
    3536
    3637  if( Factory::_factoryList == NULL)
     
    7980}
    8081
    81 /**
    82  * @brief Compares the Factories Name against a given ClassName
    83  * @param className the Name of the Class to Query
    84  * @returns true on match, false otherwise.
    85  */
    86 bool Factory::operator==(const char* className) const
    87 {
    88   return (className != NULL && this->_className == className);
    89 }
    9082
    9183/**
     
    9688bool Factory::operator==(const std::string& className) const
    9789{
    98   return (this->_className == className);
     90  return (this->_classID.name() == className);
    9991}
    10092
     
    143135}
    144136
    145 
    146137/**
    147138 * @brief Creates a new Object of type classID
     
    149140 * @returns a new Object of Type classID on match, NULL otherwise
    150141 */
    151 BaseObject* Factory::fabricate(int classID)
     142BaseObject* Factory::fabricate(const NewClassID& classID)
    152143{
    153144  if (Factory::_factoryList == NULL)
     
    157148  for (factory = Factory::_factoryList->begin(); factory != Factory::_factoryList->end(); factory++)
    158149    if (*(*factory) == classID)
    159     {
    160       PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());
    161       return (*factory)->fabricateObject(NULL);
     150  {
     151    PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());
     152    return (*factory)->fabricateObject(NULL);
    162153
    163     }
    164   PRINTF(2)("Could not Fabricate an Object of ClassID '0x%h'\n", classID);
     154  }
     155  PRINTF(2)("Could not Fabricate an Object of ClassID '%d'\n", classID.id());
    165156  return NULL;
    166157}
    167 
    168 
    169 /**
    170  * @brief Creates a new Object of type classID
    171  * @param classID the ClassID to match for the newly created Object
    172  * @returns a new Object of Type classID on match, NULL otherwise
    173  */
    174 BaseObject* Factory::fabricate(const NewClassID& classID)
    175 {
    176   return Factory::fabricate(classID.id());
    177 }
  • branches/new_class_id/src/lib/util/loading/factory.h

    r9691 r9709  
    2020
    2121
    22 #ifndef _FACTORY_H
    23 #define _FACTORY_H
     22#ifndef __FACTORY_H
     23#define __FACTORY_H
    2424
    2525class BaseObject;
     
    2727#include "parser/tinyxml/tinyxml.h"
    2828#include "base_object.h"
    29 #include <vector>
    3029#include <list>
    3130
     
    3433 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    3534 */
    36 #define CREATE_FACTORY(CLASS_NAME, CLASS_ID) \
    37     tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
     35#define CREATE_FACTORY(CLASS_NAME) \
     36    tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(CLASS_NAME::classID())
    3837
    3938//! The Factory is a loadable object handler
     
    4847  static  BaseObject* fabricate(const std::string& className);
    4948  static  BaseObject* fabricate(const NewClassID& classID);
    50   static  BaseObject* fabricate(int classID);
    51   static  BaseObject* fabricate(const TiXmlElement* root = NULL);
     49  static  BaseObject* fabricate(const TiXmlElement* root);
    5250
    5351
    5452  bool operator==(int classID) const;
    55   bool operator==(const char* className) const;
    5653  bool operator==(const std::string& className) const;
     54  bool operator==(const NewClassID& classID) const { return _classID == classID; };
    5755
    5856protected:
    59   Factory (const std::string& factoryName, int classID);
     57  Factory (const NewClassID& id);
    6058  virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
    6159
     60private:
     61  Factory (const Factory&) {};
     62
    6263protected:
    63   const int                     _classID;              //!< The Class-Identifyer of the Factory.
    64   const std::string             _className;            //!< The name of the Class.
     64  const NewClassID              _classID;              //!< The Class-Identifyer of the Factory.
    6565  static std::list<Factory*>*   _factoryList;          //!< List of Registered Factories
    6666};
     
    7878   * @param classID the ID of the Class to be created.
    7979   */
    80   tFactory (const char* factoryName, int classID)
    81       : Factory(factoryName, classID)
     80  tFactory (const NewClassID& classID)
     81      : Factory(classID)
    8282  {  }
    8383
    8484private:
     85  tFactory (const tFactory&) {};
    8586  /**
    8687   * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
  • branches/new_class_id/src/lib/util/loading/fast_factory.h

    r9707 r9709  
    122122{
    123123public:
    124   static tFastFactory<T>* getFastFactory(const NewClassID& classID, const std::string& fastFactoryName = NULL);
     124  static tFastFactory<T>* getFastFactory(const NewClassID& classID, const std::string& fastFactoryName);
    125125
    126126private:
Note: See TracChangeset for help on using the changeset viewer.