Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/lib/lang/base_object.cc @ 10763

Last change on this file since 10763 was 10738, checked in by nicolasc, 18 years ago

move random seed to main()

File size: 4.7 KB
RevLine 
[4591]1/*
[3302]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
[6640]13   co-programmer: Benjamin Grauer
[3302]14*/
[5439]15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
[3302]16
17#include "base_object.h"
[4747]18
[9869]19#include "util/debug.h"
[7193]20#include "util/loading/load_param.h"
[3302]21
[9869]22ObjectListDefinition(BaseObject);
23
[3302]24/**
[6280]25 * @brief sets the name from a LoadXML-Element
[9869]26 * @param objectName: The name of the Object.
[5439]27 */
[7661]28BaseObject::BaseObject(const std::string& objectName)
[3531]29{
[6276]30  this->className = "BaseObject";
[4435]31
[7661]32  this->objectName = objectName;
[6517]33  this->xmlElem = NULL;
[9869]34  this->registerObject(this, BaseObject::_objectList);
[10701]35
36  srand(time(0));   //initialize Random Nomber Generator
[3531]37}
[3302]38
[10114]39/**
40 * copyconstructor
41 * @param bo instance to copy
42 */
43BaseObject::BaseObject( const BaseObject& bo )
44{
45  this->className = "BaseObject";
46  this->objectName = bo.objectName;
47  this->xmlElem = (bo.xmlElem)? bo.xmlElem->Clone() : NULL;
48  this->registerObject( this, BaseObject::_objectList);
[10701]49
[10738]50//   srand(time(0));   //initialize Random Nomber Generator
[10114]51}
52
53
[3302]54/**
[6280]55 * @brief standard deconstructor
[3302]56*/
[4591]57BaseObject::~BaseObject ()
[3531]58{
[9869]59  /// Remove from the ObjectLists
60  ClassEntries::iterator it;
61  PRINTF(5)("Deleting Object of type %s::%s\n", this->getClassCName(), getCName());
62  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
63  {
[10114]64    //if (ORX_DEBUG >= 5)
[9869]65      assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this));
66    (*it)._objectList->unregisterObject((*it)._iterator);
67    delete (*it)._iterator;
68  }
[4747]69
[6517]70  if (this->xmlElem != NULL)
71    delete this->xmlElem;
[5447]72}
[3302]73
[4436]74/**
[6280]75 * @brief loads parameters
[4836]76 * @param root the element to load from
[5439]77 */
[4436]78void BaseObject::loadParams(const TiXmlElement* root)
79{
[9406]80  // all loadParams should arrive here, and be tested for (root != NULL)
[6517]81  assert (root != NULL);
82
[9406]83  // copy the xml-element for to know how it was loaded.
[6517]84  if (this->xmlElem != NULL)
85    delete this->xmlElem;
86  this->xmlElem = root->Clone();
[9406]87
[4436]88  // name setup
[5671]89  LoadParam(root, "name", this, BaseObject, setName)
[5645]90      .describe("the Name of the Object.");
[4436]91}
[4321]92
93/**
[6280]94 * @brief set the name of the Object
[9406]95 * @param objectName The new name of the Object.
[4591]96 */
[7221]97void BaseObject::setName (const std::string& objectName)
[4435]98{
[7221]99  this->objectName = objectName;
[4435]100}
[4592]101
[6281]102
[6280]103/**
[9869]104 * @brief Seeks in the Inheritance if it matches objectList.
105 * @param objectList The ObjectList this should be a member of (by Pointer-comparison).
106 * @return True if found, false if not.
[6280]107 */
[9869]108bool BaseObject::isA(const ObjectListBase& objectList) const
[6280]109{
[9869]110  ClassEntries::const_iterator it;
111  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
112    if ((*it)._objectList == &objectList)
113      return true;
114  return false;
[6280]115}
[4592]116
[6280]117
[4592]118/**
[9869]119 * @brief Seeks in the Inheritance if it matches objectList.
120 * @param classID The ClassID this should be a member of (by Pointer-comparison).
121 * @return True if found, false if not.
122 */
123bool BaseObject::isA(const ClassID& classID) const
[4592]124{
[9869]125  ClassEntries::const_iterator it;
126  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
127    if (*(*it)._objectList == classID)
[4594]128      return true;
[4592]129  return false;
130}
131
[9869]132/**
133 * @brief Seeks in the Inheritance if it matches objectList.
134 * @param classID The ClassID of the class this should be a member of.
135 * @return True if found, false if not.
136 */
137bool BaseObject::isA(int classID) const
138{
139  ClassEntries::const_iterator it;
140  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
141    if (*(*it)._objectList == classID)
[6280]142
[9869]143      return true;
144  return false;
145}
[6280]146
[4592]147/**
[9869]148 * @brief Seeks in the Inheritance if it matches objectList.
149 * @param className The ClassName of the class this should be a member of.
150 * @return True if found, false if not.
[5513]151 */
[9869]152bool BaseObject::isA(const std::string& className) const
[5513]153{
[9869]154  ClassEntries::const_iterator it;
155  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
156    if (*(*it)._objectList == className)
157      return true;
158  return false;
[5513]159}
160
[6280]161
[5626]162/**
[9869]163 * @brief This is for debug purposes, to see the Inheritances of this Object and its classes.
164 *
165 * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency.
[5626]166 */
[9869]167void BaseObject::listInheritance() const
[5626]168{
[9869]169  PRINT(0)("Listing inheritance diagram for %s::%s: ", getClassCName(), getCName());
170  ClassEntries::const_iterator it;
171  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
172    PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());
173  PRINT(0)("\n");
174
[5626]175}
Note: See TracBrowser for help on using the repository browser.