Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: ClassList now supports getLeafID() to retriefe the ID on hot to generate an object of the same type

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: ...
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
18
19#include "base_object.h"
20
21#include "load_param.h"
22#include "compiler.h"
23#include "class_list.h"
24
25using namespace std;
26
27
28/**
29 * @brief sets the name from a LoadXML-Element
30 * @param root the element to load from
31 */
32BaseObject::BaseObject(const TiXmlElement* root)
33{
34  this->className = "BaseObject";
35  this->classID = CL_BASE_OBJECT;
36
37  this->objectName = NULL;
38  this->classList = NULL;
39
40  if (root)
41    this->loadParams(root);
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->objectName)
55    delete[] this->objectName;
56}
57
58/**
59 * @brief loads parameters
60 * @param root the element to load from
61 */
62void BaseObject::loadParams(const TiXmlElement* root)
63{
64  // name setup
65  LoadParam(root, "name", this, BaseObject, setName)
66      .describe("the Name of the Object.");
67}
68
69/**
70 * @brief sets the class identifiers
71 * @param id a number for the class from class_id.h enumeration
72 * @param className the class name
73*/
74void BaseObject::setClassID(ClassID classID, const char* className)
75{
76  //  printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);
77  assert (!(this->classID & classID));
78
79  this->classID |= (long)classID;
80  this->className = className;
81
82  this->classList = ClassList::addToClassList(this, classID, this->classID, className);
83}
84
85
86/**
87 * @brief set the name of the Object
88 */
89void BaseObject::setName (const char* objectName)
90{
91  if (this->objectName)
92    delete[] this->objectName;
93  if (objectName != NULL)
94  {
95    this->objectName = new char[strlen(objectName)+1];
96    strcpy(this->objectName, objectName);
97  }
98  else
99    this->objectName = NULL;
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 */
109ClassID BaseObject::getLeafClassID() const
110{
111  assert (this->classList != NULL);
112  return this->classList->getLeafClassID();
113}
114
115
116
117/**
118 * @brief checks if the class is a classID
119 * @param classID the Identifier to check for
120 * @returns true if it is, false otherwise
121*/
122bool BaseObject::isA (ClassID classID) const
123{
124  // if classID is a derivable object from a SUPERCLASS
125  if (classID & CL_MASK_SUPER_CLASS)
126  {
127    if( likely(this->classID & classID))
128      return true;
129  }
130  // if classID is a SubSuperClass, and
131  else if (classID & CL_MASK_SUBSUPER_CLASS)
132  {
133    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (this->classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
134        this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
135      return true;
136  }
137  // if classID is a LOWLEVEL-class
138  else
139  {
140    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
141      return true;
142  }
143  return false;
144}
145
146
147
148/**
149 * @brief checks if the class is a classID
150 * @param classID the Identifier to check for
151 * @returns true if it is, false otherwise
152 */
153bool BaseObject::isA (const char* className) const
154{
155  ClassID classID = ClassList::StringToID(className);
156  if (classID != CL_NULL)
157    return this->isA(classID);
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 char* objectName)
167{
168  if (likely(this->objectName != NULL && objectName != NULL))
169    return (strcmp(this->objectName, objectName)) ? false : true;
170}
171
172
173/**
174 * @brief displays everything this class is
175 * @TODO REIMPLEMENT WITH SENSE.
176 */
177void BaseObject::whatIs() const
178{
179
180}
Note: See TracBrowser for help on using the repository browser.