Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/test/src/lib/lang/base_object.cc @ 9929

Last change on this file since 9929 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
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 "util/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(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  }
52
53  if (this->xmlElem != NULL)
54    delete this->xmlElem;
55}
56
57/**
58 * @brief loads parameters
59 * @param root the element to load from
60 */
61void BaseObject::loadParams(const TiXmlElement* root)
62{
63  // all loadParams should arrive here, and be tested for (root != NULL)
64  assert (root != NULL);
65
66  // copy the xml-element for to know how it was loaded.
67  if (this->xmlElem != NULL)
68    delete this->xmlElem;
69  this->xmlElem = root->Clone();
70
71  // name setup
72  LoadParam(root, "name", this, BaseObject, setName)
73      .describe("the Name of the Object.");
74}
75
76/**
77 * @brief set the name of the Object
78 * @param objectName The new name of the Object.
79 */
80void BaseObject::setName (const std::string& objectName)
81{
82  this->objectName = objectName;
83}
84
85
86/**
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.
90 */
91bool BaseObject::isA(const ObjectListBase& objectList) const
92{
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;
98}
99
100
101/**
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
107{
108  ClassEntries::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.
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)
125
126      return true;
127  return false;
128}
129
130/**
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.
134 */
135bool BaseObject::isA(const std::string& className) const
136{
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;
142}
143
144
145/**
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.
149 */
150void BaseObject::listInheritance() const
151{
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
158}
Note: See TracBrowser for help on using the repository browser.