Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

cleaner executor with evaluate function, that will be made an Object Soon.

File size: 4.1 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
35  //ClassList::addToClassList(this, this->classID, "BaseObject");
36}
37
38/**
39 * @brief standard deconstructor
40*/
41BaseObject::~BaseObject ()
42{
43  /// Remove from the ObjectLists
44  ClassList::iterator it;
45  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
46  {
47    (*it)._objectList->unregisterObject((*it)._iterator);
48    delete (*it)._iterator;
49  }
50
51  if (this->xmlElem != NULL)
52    delete this->xmlElem;
53}
54
55/**
56 * @brief loads parameters
57 * @param root the element to load from
58 */
59void BaseObject::loadParams(const TiXmlElement* root)
60{
61  // all loadParams should arrive here, and be tested for (root != NULL)
62  assert (root != NULL);
63
64  // copy the xml-element for to know how it was loaded.
65  if (this->xmlElem != NULL)
66    delete this->xmlElem;
67  this->xmlElem = root->Clone();
68
69  // name setup
70  LoadParam(root, "name", this, BaseObject, setName)
71      .describe("the Name of the Object.");
72}
73
74/**
75 * @brief set the name of the Object
76 * @param objectName The new name of the Object.
77 */
78void BaseObject::setName (const std::string& objectName)
79{
80  this->objectName = objectName;
81}
82
83
84/**
85 * @brief Seeks in the Inheritance if it matches objectList.
86 * @param objectList The ObjectList this should be a member of (by Pointer-comparison).
87 * @return True if found, false if not.
88 */
89bool BaseObject::isA(const ObjectListBase& objectList) const
90{
91  ClassList::const_iterator it;
92  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
93    if ((*it)._objectList == &objectList)
94      return true;
95  return false;
96}
97
98
99/**
100 * @brief Seeks in the Inheritance if it matches objectList.
101 * @param classID The ClassID this should be a member of (by Pointer-comparison).
102 * @return True if found, false if not.
103 */
104bool BaseObject::isA(const ClassID& classID) const
105{
106  ClassList::const_iterator it;
107  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
108    if (*(*it)._objectList == classID)
109      return true;
110  return false;
111}
112
113/**
114 * @brief Seeks in the Inheritance if it matches objectList.
115 * @param classID The ClassID of the class this should be a member of.
116 * @return True if found, false if not.
117 */
118bool BaseObject::isA(int classID) const
119{
120  ClassList::const_iterator it;
121  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
122    if (*(*it)._objectList == classID)
123      return true;
124  return false;
125}
126
127/**
128 * @brief Seeks in the Inheritance if it matches objectList.
129 * @param className The ClassName of the class this should be a member of.
130 * @return True if found, false if not.
131 */
132bool BaseObject::isA(const std::string& className) const
133{
134  ClassList::const_iterator it;
135  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
136    if (*(*it)._objectList == className)
137      return true;
138  return false;
139}
140
141
142/**
143 * @brief This is for debug purposes, to see the Inheritances of this Object and its classes.
144 *
145 * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency.
146 */
147void BaseObject::listInheritance() const
148{
149  PRINT(0)("Listing inheritance diagram for ....: ");
150  ClassList::const_iterator it;
151  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
152    PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());
153  PRINT(0)("\n");
154
155}
Note: See TracBrowser for help on using the repository browser.