Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/lang/base_object.cc @ 7575

Last change on this file since 7575 was 7575, checked in by rennerc, 18 years ago

fixed some bugs

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