Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

many many documentations and one new functiopm

File size: 4.0 KB
Line 
1
2
3/*
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
15   co-programmer: Benjamin Grauer
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
18
19#include "base_object.h"
20
21#include "util/loading/load_param.h"
22
23ObjectListDefinition(BaseObject);
24
25/**
26 * @brief sets the name from a LoadXML-Element
27 * @param objectName: The name of the Object.
28 */
29BaseObject::BaseObject(const std::string& objectName)
30{
31  this->className = "BaseObject";
32
33  this->objectName = objectName;
34  this->xmlElem = NULL;
35
36  //ClassList::addToClassList(this, this->classID, "BaseObject");
37}
38
39/**
40 * @brief standard deconstructor
41*/
42BaseObject::~BaseObject ()
43{
44  /// Remove from the ObjectLists
45  ClassList::iterator it;
46  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
47  {
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  ClassList::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  ClassList::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  ClassList::const_iterator it;
122  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
123    if (*(*it)._objectList == classID)
124      return true;
125  return false;
126}
127
128/**
129 * @brief Seeks in the Inheritance if it matches objectList.
130 * @param className The ClassName of the class this should be a member of.
131 * @return True if found, false if not.
132 */
133bool BaseObject::isA(const std::string& className) const
134{
135  ClassList::const_iterator it;
136  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
137    if (*(*it)._objectList == className)
138      return true;
139  return false;
140}
141
142
143/**
144 * @brief This is for debug purposes, to see the Inheritances of this Object and its classes.
145 *
146 * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency.
147 */
148void BaseObject::listInheritance() const
149{
150  PRINT(0)("Listing inheritance diagram for ....: ");
151  ClassList::const_iterator it;
152  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
153    PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());
154  PRINT(0)("\n");
155
156}
Note: See TracBrowser for help on using the repository browser.