Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/lang/base_object.cc @ 10293

Last change on this file since 10293 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

File size: 4.6 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);
[3531]35}
[3302]36
[10114]37/**
38 * copyconstructor
39 * @param bo instance to copy
40 */
41BaseObject::BaseObject( const BaseObject& bo )
42{
43  this->className = "BaseObject";
44  this->objectName = bo.objectName;
45  this->xmlElem = (bo.xmlElem)? bo.xmlElem->Clone() : NULL;
46  this->registerObject( this, BaseObject::_objectList);
47}
48
49
[3302]50/**
[6280]51 * @brief standard deconstructor
[3302]52*/
[4591]53BaseObject::~BaseObject ()
[3531]54{
[9869]55  /// Remove from the ObjectLists
56  ClassEntries::iterator it;
57  PRINTF(5)("Deleting Object of type %s::%s\n", this->getClassCName(), getCName());
58  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
59  {
[10114]60    //if (ORX_DEBUG >= 5)
[9869]61      assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this));
62    (*it)._objectList->unregisterObject((*it)._iterator);
63    delete (*it)._iterator;
64  }
[4747]65
[6517]66  if (this->xmlElem != NULL)
67    delete this->xmlElem;
[5447]68}
[3302]69
[4436]70/**
[6280]71 * @brief loads parameters
[4836]72 * @param root the element to load from
[5439]73 */
[4436]74void BaseObject::loadParams(const TiXmlElement* root)
75{
[9406]76  // all loadParams should arrive here, and be tested for (root != NULL)
[6517]77  assert (root != NULL);
78
[9406]79  // copy the xml-element for to know how it was loaded.
[6517]80  if (this->xmlElem != NULL)
81    delete this->xmlElem;
82  this->xmlElem = root->Clone();
[9406]83
[4436]84  // name setup
[5671]85  LoadParam(root, "name", this, BaseObject, setName)
[5645]86      .describe("the Name of the Object.");
[4436]87}
[4321]88
89/**
[6280]90 * @brief set the name of the Object
[9406]91 * @param objectName The new name of the Object.
[4591]92 */
[7221]93void BaseObject::setName (const std::string& objectName)
[4435]94{
[7221]95  this->objectName = objectName;
[4435]96}
[4592]97
[6281]98
[6280]99/**
[9869]100 * @brief Seeks in the Inheritance if it matches objectList.
101 * @param objectList The ObjectList this should be a member of (by Pointer-comparison).
102 * @return True if found, false if not.
[6280]103 */
[9869]104bool BaseObject::isA(const ObjectListBase& objectList) const
[6280]105{
[9869]106  ClassEntries::const_iterator it;
107  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
108    if ((*it)._objectList == &objectList)
109      return true;
110  return false;
[6280]111}
[4592]112
[6280]113
[4592]114/**
[9869]115 * @brief Seeks in the Inheritance if it matches objectList.
116 * @param classID The ClassID this should be a member of (by Pointer-comparison).
117 * @return True if found, false if not.
118 */
119bool BaseObject::isA(const ClassID& classID) const
[4592]120{
[9869]121  ClassEntries::const_iterator it;
122  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
123    if (*(*it)._objectList == classID)
[4594]124      return true;
[4592]125  return false;
126}
127
[9869]128/**
129 * @brief Seeks in the Inheritance if it matches objectList.
130 * @param classID The ClassID of the class this should be a member of.
131 * @return True if found, false if not.
132 */
133bool BaseObject::isA(int classID) const
134{
135  ClassEntries::const_iterator it;
136  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
137    if (*(*it)._objectList == classID)
[6280]138
[9869]139      return true;
140  return false;
141}
[6280]142
[4592]143/**
[9869]144 * @brief Seeks in the Inheritance if it matches objectList.
145 * @param className The ClassName of the class this should be a member of.
146 * @return True if found, false if not.
[5513]147 */
[9869]148bool BaseObject::isA(const std::string& className) const
[5513]149{
[9869]150  ClassEntries::const_iterator it;
151  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
152    if (*(*it)._objectList == className)
153      return true;
154  return false;
[5513]155}
156
[6280]157
[5626]158/**
[9869]159 * @brief This is for debug purposes, to see the Inheritances of this Object and its classes.
160 *
161 * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency.
[5626]162 */
[9869]163void BaseObject::listInheritance() const
[5626]164{
[9869]165  PRINT(0)("Listing inheritance diagram for %s::%s: ", getClassCName(), getCName());
166  ClassEntries::const_iterator it;
167  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
168    PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());
169  PRINT(0)("\n");
170
[5626]171}
Note: See TracBrowser for help on using the repository browser.