Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5967 was 5915, checked in by bensch, 19 years ago

orxonox/trunk: merged branches/spaceshipControll back to the trunk:
merged with command:
svn merge -r5835:HEAD branches/spaceshipcontroll trunk
conflicts resolved with dynamic indentation methodology algorithms

File size: 4.7 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 *  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 = NULL;
35  this->classID = CL_BASE_OBJECT;
36
37  this->objectName = NULL;
38
39  if (root)
40    this->loadParams(root);
41
42//  ClassList::addToClassList(this, this->classID, "BaseObject");
43}
44
45/**
46 *  standard deconstructor
47*/
48BaseObject::~BaseObject ()
49{
50  ClassList::removeFromClassList(this);
51
52  //  delete []this->className;
53  if (this->objectName)
54    delete[] this->objectName;
55}
56
57/**
58 *  loads parameters
59 * @param root the element to load from
60 */
61void BaseObject::loadParams(const TiXmlElement* root)
62{
63  // name setup
64  LoadParam(root, "name", this, BaseObject, setName)
65      .describe("the Name of the Object.");
66}
67
68/**
69 *  sets the class identifiers
70 * @param id a number for the class from class_id.h enumeration
71 * @param className the class name
72*/
73void BaseObject::setClassID(ClassID classID, const char* className)
74{
75  this->classID |= (long)classID;
76  this->className = className;
77
78  ClassList::addToClassList(this, classID, className);
79}
80
81/**
82  \brief set the name of the Object
83 */
84void BaseObject::setName (const char* objectName)
85{
86  if (this->objectName)
87    delete[] this->objectName;
88  if (objectName != NULL)
89  {
90    this->objectName = new char[strlen(objectName)+1];
91    strcpy(this->objectName, objectName);
92  }
93  else
94    this->objectName = NULL;
95}
96
97
98/**
99 *  checks if the class is a classID
100 * @param classID the Identifier to check for
101 * @returns true if it is, false otherwise
102*/
103bool BaseObject::isA (long classID) const
104{
105  // if classID is a derivable object from a SUPERCLASS
106  if (classID & CL_MASK_SUPER_CLASS)
107  {
108    if( likely(this->classID & classID))
109      return true;
110  }
111  // if classID is a SubSuperClass, and
112  else if (classID & CL_MASK_SUBSUPER_CLASS)
113  {
114    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (this->classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
115        this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
116      return true;
117  }
118  // if classID is a LOWLEVEL-class
119  else
120  {
121    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
122      return true;
123  }
124  return false;
125}
126
127/**
128 *  checks if the class is a classID
129 * @param classID the Identifier to check for
130 * @returns true if it is, false otherwise
131 */
132bool BaseObject::isA (const char* className) const
133{
134  long classID = ClassList::StringToID(className);
135  if (classID != CL_NULL)
136    return this->isA(classID);
137}
138
139/**
140 * compares the ObjectName with an external name
141 * @param objectName: the name to check.
142 * @returns true on match, false otherwise.
143 */
144bool BaseObject::operator==(const char* objectName)
145{
146  if (likely(this->objectName != NULL && objectName != NULL))
147    return (strcmp(this->objectName, objectName)) ? false : true;
148}
149
150
151/**
152 *  displays everything this class is
153 * @TODO REIMPLEMENT WITH SENSE.
154 */
155void BaseObject::whatIs() const
156{
157  PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
158  if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
159    PRINT(0)("is a Singleton-Class ");
160  if (this->classID & CL_MASK_SUPER_CLASS)
161  {
162    PRINT(0)(" ->is a derived from the following superclasses:");
163    if (this->isA(CL_BASE_OBJECT))
164      PRINT(0)(" =BaseObject=");
165    if (this->isA(CL_PARENT_NODE))
166      PRINT(0)(" =PNode=");
167    if (this->isA(CL_WORLD_ENTITY))
168      PRINT(0)(" =WorldEntity=");
169    if (this->isA(CL_PHYSICS_INTERFACE))
170      PRINT(0)(" =PhysicsInterface=");
171    if (this->isA(CL_EVENT_LISTENER))
172      PRINT(0)(" =EventListener=");
173    if (this->isA(CL_STORY_ENTITY))
174      PRINT(0)(" =StoryEntity=");
175    if (this->isA(CL_ELEMENT_2D))
176      PRINT(0)(" =Element2D=");
177    PRINT(0)("\n");
178  }
179  // subsuper-classes
180  if (this->classID & CL_MASK_SUBSUPER_CLASS)
181  {
182    PRINT(0)(" ->further derivations: ");
183    if (this->isA(CL_PLAYER))
184      PRINT(0)(" -Player-");
185    if (this->isA(CL_NPC))
186      PRINT(0)(" -NPC-");
187    if (this->isA(CL_POWER_UP))
188      PRINT(0)(" -PowerUp-");
189    if (this->isA(CL_FIELD))
190      PRINT(0)(" -Field-");
191    if (this->isA(CL_PROJECTILE))
192      PRINT(0)(" -Projectile-");
193    if (this->isA(CL_WEAPON))
194      PRINT(0)(" -Weapon-");
195    PRINT(0)("\n");
196}
197}
Note: See TracBrowser for help on using the repository browser.