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
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 "debug.h"
22#include "util/loading/load_param.h"
23
24ObjectListDefinition(BaseObject);
25
26/**
27 * @brief sets the name from a LoadXML-Element
28 * @param objectName: The name of the Object.
29 */
30BaseObject::BaseObject(const std::string& objectName)
31{
32  this->className = "BaseObject";
33
34  this->objectName = objectName;
35  this->xmlElem = NULL;
36
37  //ClassList::addToClassList(this, this->classID, "BaseObject");
38}
39
40/**
41 * @brief standard deconstructor
42*/
43BaseObject::~BaseObject ()
44{
45  /// Remove from the ObjectLists
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  }
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  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;
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  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.
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  ClassList::const_iterator it;
123  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
124    if (*(*it)._objectList == classID)
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  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;
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 ....: ");
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
157}
Note: See TracBrowser for help on using the repository browser.