Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: SoundSource completely added as a Resource

File size: 4.2 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    PRINTF(5)("DELETING OBJECT %s::%s FROM %s\n", this->getClassCName(), getCName(), (*it)._objectList->name().c_str());
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.