Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9869 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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