Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/lang/base_object.cc @ 9727

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

orxonox/new_class_id: new Executor construct, that is much more typesafe, faster, and easier to extend…

Also changed the LoadParam process, and adapted ScriptEngine calls

Then at the end, some missing headers appeared, and appended them to all the cc-files again.

File size: 4.1 KB
RevLine 
[3302]1
2
[4591]3/*
[3302]4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
[6640]15   co-programmer: Benjamin Grauer
[3302]16*/
[5439]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
[3302]18
19#include "base_object.h"
[4747]20
[9727]21#include "debug.h"
[7193]22#include "util/loading/load_param.h"
[3302]23
[9715]24ObjectListDefinition(BaseObject);
[9691]25
[3302]26/**
[6280]27 * @brief sets the name from a LoadXML-Element
[9724]28 * @param objectName: The name of the Object.
[5439]29 */
[7661]30BaseObject::BaseObject(const std::string& objectName)
[3531]31{
[6276]32  this->className = "BaseObject";
[4435]33
[7661]34  this->objectName = objectName;
[6517]35  this->xmlElem = NULL;
[4436]36
[7429]37  //ClassList::addToClassList(this, this->classID, "BaseObject");
[3531]38}
[3302]39
40/**
[6280]41 * @brief standard deconstructor
[3302]42*/
[4591]43BaseObject::~BaseObject ()
[3531]44{
[9715]45  /// Remove from the ObjectLists
[9684]46  ClassList::iterator it;
47  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
48  {
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/**
[9684]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 */
[9715]91bool BaseObject::isA(const ObjectListBase& objectList) const
[6280]92{
[9684]93  ClassList::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
[9686]100
[4592]101/**
[9684]102 * @brief Seeks in the Inheritance if it matches objectList.
[9724]103 * @param classID The ClassID this should be a member of (by Pointer-comparison).
[9686]104 * @return True if found, false if not.
105 */
[9715]106bool BaseObject::isA(const ClassID& classID) const
[9686]107{
108  ClassList::const_iterator it;
109  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
110    if (*(*it)._objectList == classID)
111      return true;
112  return false;
113}
114
115/**
116 * @brief Seeks in the Inheritance if it matches objectList.
[9684]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
[4592]121{
[9684]122  ClassList::const_iterator it;
123  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
124    if (*(*it)._objectList == classID)
[4594]125      return true;
[4592]126  return false;
127}
128
129/**
[9684]130 * @brief Seeks in the Inheritance if it matches objectList.
131 * @param className The ClassName of the class this should be a member of.
132 * @return True if found, false if not.
[5513]133 */
[9684]134bool BaseObject::isA(const std::string& className) const
[5513]135{
[9684]136  ClassList::const_iterator it;
137  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
138    if (*(*it)._objectList == className)
139      return true;
140  return false;
[5513]141}
142
[6280]143
[9724]144/**
145 * @brief This is for debug purposes, to see the Inheritances of this Object and its classes.
146 *
147 * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency.
148 */
[9684]149void BaseObject::listInheritance() const
[5626]150{
[9684]151  PRINT(0)("Listing inheritance diagram for ....: ");
152  ClassList::const_iterator it;
153  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
154    PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());
155  PRINT(0)("\n");
156
[5626]157}
Note: See TracBrowser for help on using the repository browser.