Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/new_class_id: slowly but surely reimplementing to the new groove… way to go

File size: 3.4 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
23/**
24 * @brief sets the name from a LoadXML-Element
25 * @param root the element to load from
26 */
27BaseObject::BaseObject(const std::string& objectName)
28{
29  this->className = "BaseObject";
30
31  this->objectName = objectName;
32  this->xmlElem = NULL;
33
34  //ClassList::addToClassList(this, this->classID, "BaseObject");
35}
36
37/**
38 * @brief standard deconstructor
39*/
40BaseObject::~BaseObject ()
41{
42  /// Remove from the NewObjectLists
43  ClassList::iterator it;
44  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
45  {
46    (*it)._objectList->unregisterObject((*it)._iterator);
47    delete (*it)._iterator;
48  }
49
50  if (this->xmlElem != NULL)
51    delete this->xmlElem;
52}
53
54/**
55 * @brief loads parameters
56 * @param root the element to load from
57 */
58void BaseObject::loadParams(const TiXmlElement* root)
59{
60  // all loadParams should arrive here, and be tested for (root != NULL)
61  assert (root != NULL);
62
63  // copy the xml-element for to know how it was loaded.
64  if (this->xmlElem != NULL)
65    delete this->xmlElem;
66  this->xmlElem = root->Clone();
67
68  // name setup
69  LoadParam(root, "name", this, BaseObject, setName)
70      .describe("the Name of the Object.");
71}
72
73/**
74 * @brief set the name of the Object
75 * @param objectName The new name of the Object.
76 */
77void BaseObject::setName (const std::string& objectName)
78{
79  this->objectName = objectName;
80}
81
82
83/**
84 * @brief Seeks in the Inheritance if it matches objectList.
85 * @param objectList The ObjectList this should be a member of (by Pointer-comparison).
86 * @return True if found, false if not.
87 */
88bool BaseObject::isA(const NewObjectListBase& objectList) const
89{
90  ClassList::const_iterator it;
91  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
92    if ((*it)._objectList == &objectList)
93      return true;
94  return false;
95}
96
97/**
98 * @brief Seeks in the Inheritance if it matches objectList.
99 * @param classID The ClassID of the class this should be a member of.
100 * @return True if found, false if not.
101 */
102bool BaseObject::isA(int classID) const
103{
104  ClassList::const_iterator it;
105  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
106    if (*(*it)._objectList == classID)
107      return true;
108  return false;
109}
110
111/**
112 * @brief Seeks in the Inheritance if it matches objectList.
113 * @param className The ClassName of the class this should be a member of.
114 * @return True if found, false if not.
115 */
116bool BaseObject::isA(const std::string& className) const
117{
118  ClassList::const_iterator it;
119  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
120    if (*(*it)._objectList == className)
121      return true;
122  return false;
123}
124
125
126void BaseObject::listInheritance() const
127{
128  PRINT(0)("Listing inheritance diagram for ....: ");
129  ClassList::const_iterator it;
130  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
131    PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());
132  PRINT(0)("\n");
133
134}
Note: See TracBrowser for help on using the repository browser.