Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9675 in orxonox.OLD for trunk/src/lib/util/loading


Ignore:
Timestamp:
Aug 21, 2006, 10:57:35 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: more Implementation of Functionality.
Introduced map for fast search of ID/Name pairs.
This will also be used to speedup the Factory create-process

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/loading/factory.cc

    r9406 r9675  
    2929 */
    3030Factory::Factory (const std::string& factoryName, ClassID classID)
    31   : classID(classID), className(factoryName)
     31    : classID(classID), className(factoryName)
    3232{
    3333  this->setClassID(CL_FACTORY, "Factory");
     
    8686bool Factory::operator==(const char* className) const
    8787{
    88   return(className != NULL && this->className == className);
     88  return (className != NULL && this->className == className);
    8989}
    9090
     
    9696bool Factory::operator==(const std::string& className) const
    9797{
    98   return(this->className == className);
     98  return (this->className == className);
    9999}
    100100
     
    105105 * @returns a new Object of Type root->Value() on match, NULL otherwise
    106106 */
    107  BaseObject* Factory::fabricate(const TiXmlElement* root)
     107BaseObject* Factory::fabricate(const TiXmlElement* root)
    108108{
    109   if (root == NULL || Factory::factoryList == NULL)
    110     return NULL;
     109  assert (root != NULL && Factory::factoryList != NULL);
    111110
    112111  std::list<Factory*>::const_iterator factory;
    113112  for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)
    114113    if (*(*factory) == root->Value())
    115       break;
     114    {
     115      PRINTF(2)("Create a new Object of type %s\n", (*factory)->getCName());
     116      return (*factory)->fabricateObject(root);
     117    }
    116118
    117   if (factory != Factory::factoryList->end())
    118   {
    119     PRINTF(2)("Create a new Object of type %s\n", (*factory)->getCName());
    120     return (*factory)->fabricateObject(root);
    121   }
    122   else
    123   {
    124     PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value());
    125     return NULL;
    126   }
     119  PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value());
     120  return NULL;
    127121}
    128122
    129123
    130124/**
    131  * Creates a new Object of type className
     125 * @brief Creates a new Object of type className
    132126 * @param className the ClassName to match for the newly created Object
    133127 * @returns a new Object of Type className on match, NULL otherwise
    134128 */
    135  BaseObject* Factory::fabricate(const std::string& className)
     129BaseObject* Factory::fabricate(const std::string& className)
    136130{
    137131  if (Factory::factoryList == NULL)
     
    141135  for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)
    142136    if (*(*factory) == className)
    143       break;
    144 
    145   if (factory != Factory::factoryList->end())
    146   {
    147     PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());
    148     return (*factory)->fabricateObject(NULL);
    149   }
    150   else
    151   {
    152     PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className.c_str());
    153     return NULL;
    154   }
     137    {
     138      PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());
     139      return (*factory)->fabricateObject(NULL);
     140    }
     141  PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className.c_str());
     142  return NULL;
    155143}
    156144
    157145
    158146/**
    159  * Creates a new Object of type classID
     147 * @brief Creates a new Object of type classID
    160148 * @param classID the ClassID to match for the newly created Object
    161149 * @returns a new Object of Type classID on match, NULL otherwise
     
    169157  for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)
    170158    if (*(*factory) == classID)
    171       break;
     159    {
     160      PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());
     161      return (*factory)->fabricateObject(NULL);
    172162
    173   if (factory != Factory::factoryList->end())
    174   {
    175     PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());
    176     return (*factory)->fabricateObject(NULL);
    177   }
    178   else
    179   {
    180     PRINTF(2)("Could not Fabricate an Object of ClassID '0x%h'\n", classID);
    181     return NULL;
    182   }
     163    }
     164  PRINTF(2)("Could not Fabricate an Object of ClassID '0x%h'\n", classID);
     165  return NULL;
    183166}
Note: See TracChangeset for help on using the changeset viewer.