Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

some more DEBUG-functionality to the ObjectList… something is not quite right… i wonder, what this might be…

File size: 4.3 KB
Line 
1/*
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
13   co-programmer: Benjamin Grauer
14*/
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
16
17#include "base_object.h"
18
19#include "debug.h"
20#include "util/loading/load_param.h"
21
22ObjectListDefinition(BaseObject);
23
24/**
25 * @brief sets the name from a LoadXML-Element
26 * @param objectName: The name of the Object.
27 */
28BaseObject::BaseObject(const std::string& objectName)
29{
30  this->className = "BaseObject";
31
32  this->objectName = objectName;
33  this->xmlElem = NULL;
34  this->registerObject(this, BaseObject::_objectList);
35}
36
37/**
38 * @brief standard deconstructor
39*/
40BaseObject::~BaseObject ()
41{
42  /// Remove from the ObjectLists
43  ClassEntries::iterator it;
44  printf("Deleting Object of type %s::%s\n", this->getClassCName(), getCName());
45  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
46  {
47    assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this));
48    (*it)._objectList->unregisterObject((*it)._iterator);
49    delete (*it)._iterator;
50  }
51
52  if (this->xmlElem != NULL)
53    delete this->xmlElem;
54}
55
56/**
57 * @brief loads parameters
58 * @param root the element to load from
59 */
60void BaseObject::loadParams(const TiXmlElement* root)
61{
62  // all loadParams should arrive here, and be tested for (root != NULL)
63  assert (root != NULL);
64
65  // copy the xml-element for to know how it was loaded.
66  if (this->xmlElem != NULL)
67    delete this->xmlElem;
68  this->xmlElem = root->Clone();
69
70  // name setup
71  LoadParam(root, "name", this, BaseObject, setName)
72      .describe("the Name of the Object.");
73}
74
75/**
76 * @brief set the name of the Object
77 * @param objectName The new name of the Object.
78 */
79void BaseObject::setName (const std::string& objectName)
80{
81  this->objectName = objectName;
82}
83
84
85/**
86 * @brief Seeks in the Inheritance if it matches objectList.
87 * @param objectList The ObjectList this should be a member of (by Pointer-comparison).
88 * @return True if found, false if not.
89 */
90bool BaseObject::isA(const ObjectListBase& objectList) const
91{
92  ClassEntries::const_iterator it;
93  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
94    if ((*it)._objectList == &objectList)
95      return true;
96  return false;
97}
98
99
100/**
101 * @brief Seeks in the Inheritance if it matches objectList.
102 * @param classID The ClassID this should be a member of (by Pointer-comparison).
103 * @return True if found, false if not.
104 */
105bool BaseObject::isA(const ClassID& classID) const
106{
107  ClassEntries::const_iterator it;
108  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
109    if (*(*it)._objectList == classID)
110      return true;
111  return false;
112}
113
114/**
115 * @brief Seeks in the Inheritance if it matches objectList.
116 * @param classID The ClassID of the class this should be a member of.
117 * @return True if found, false if not.
118 */
119bool BaseObject::isA(int classID) const
120{
121  ClassEntries::const_iterator it;
122  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
123    if (*(*it)._objectList == classID)
124
125      return true;
126  return false;
127}
128
129/**
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.
133 */
134bool BaseObject::isA(const std::string& className) const
135{
136  ClassEntries::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;
141}
142
143
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 */
149void BaseObject::listInheritance() const
150{
151  PRINT(0)("Listing inheritance diagram for %s::%s: ", getClassCName(), getCName());
152  ClassEntries::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
157}
Note: See TracBrowser for help on using the repository browser.