Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/lang/base_object.cc @ 8682

Last change on this file since 8682 was 8145, checked in by bensch, 19 years ago

trunk: merged the gui back
merged with command:
svn merge -r8114:HEAD https://svn.orxonox.net/orxonox/branches/gui .
→ no conflicts

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 "util/loading/load_param.h"
22#include "class_list.h"
23
24#include "synchronizeable.h"
25
26using namespace std;
27
28
29/**
30 * @brief sets the name from a LoadXML-Element
31 * @param root the element to load from
32 */
33BaseObject::BaseObject(const std::string& objectName)
34{
35  this->classID = CL_BASE_OBJECT;
36  this->className = "BaseObject";
37
38  this->objectName = objectName;
39  this->classList = NULL;
40  this->xmlElem = NULL;
41
42  //ClassList::addToClassList(this, this->classID, "BaseObject");
43}
44
45/**
46 * @brief standard deconstructor
47*/
48BaseObject::~BaseObject ()
49{
50  ClassList::removeFromClassList(this);
51
52  //  delete []this->className;
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 sometime arrive here.
64  assert (root != NULL);
65
66  if (this->xmlElem != NULL)
67    delete this->xmlElem;
68  this->xmlElem = root->Clone();
69  // name setup
70  LoadParam(root, "name", this, BaseObject, setName)
71      .describe("the Name of the Object.");
72}
73
74/**
75 * @brief sets the class identifiers
76 * @param id a number for the class from class_id.h enumeration
77 * @param className the class name
78*/
79void BaseObject::setClassID(ClassID classID, const std::string& className)
80{
81  //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);
82  assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA ));
83
84  this->leafClassID = classID;
85  this->classID |= (long)classID;
86  this->className = className;
87
88  this->classList = ClassList::addToClassList(this, classID, this->classID, className);
89}
90
91
92/**
93 * @brief set the name of the Object
94 */
95void BaseObject::setName (const std::string& objectName)
96{
97  this->objectName = objectName;
98}
99
100
101/**
102 * @brief queries for the ClassID of the Leaf Class (the last made class of this type
103 * @returns the ClassID of the Leaf Class (e.g. the ID of the Class)
104 *
105 * the returned ID can be used to generate new Objects of the same type through
106 * Factory::fabricate(Object->getLeafClassID());
107 */
108const ClassID& BaseObject::getLeafClassID() const
109{
110  return this->leafClassID;
111}
112
113
114
115/**
116 * @brief checks if the class is a classID
117 * @param classID the Identifier to check for
118 * @returns true if it is, false otherwise
119*/
120bool BaseObject::isA (ClassID classID) const
121{
122  // if classID is a derivable object from a SUPERCLASS
123  if (classID & CL_MASK_SUPER_CLASS)
124  {
125    if( likely(this->classID & classID))
126      return true;
127  }
128  // if classID is a SubSuperClass, and
129  else if (classID & CL_MASK_SUBSUPER_CLASS)
130  {
131    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
132        this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
133      return true;
134  }
135  // if classID is a LOWLEVEL-class
136  else
137  {
138    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
139      return true;
140  }
141  return false;
142}
143
144
145
146/**
147 * @brief checks if the class is a classID
148 * @param classID the Identifier to check for
149 * @returns true if it is, false otherwise
150 */
151bool BaseObject::isA (const std::string& className) const
152{
153  ClassID classID = ClassList::StringToID(className);
154  if (classID != CL_NULL)
155    return this->isA(classID);
156  else
157    return false;
158}
159
160
161/**
162 * @brief compares the ObjectName with an external name
163 * @param objectName: the name to check.
164 * @returns true on match, false otherwise.
165 */
166bool BaseObject::operator==(const std::string& objectName)
167{
168  return (this->objectName == objectName);
169}
170
171
172/**
173 * @brief displays everything this class is
174 * @TODO REIMPLEMENT WITH SENSE.
175 */
176void BaseObject::whatIs() const
177{
178
179}
Note: See TracBrowser for help on using the repository browser.