Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/2d-recalc/src/lib/lang/base_object.cc @ 5379

Last change on this file since 5379 was 5113, checked in by bensch, 19 years ago

orxonox/trunk:restoring the trunk…

File size: 4.0 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
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 *  loads parameters
58 * @param root the element to load from
59*/
60void BaseObject::loadParams(const TiXmlElement* root)
61{
62  // name setup
63  LoadParam<BaseObject>(root, "name", this, &BaseObject::setName)
64      .describe("the name of the Object at hand");
65}
66
67/**
68 *  sets the class identifiers
69 * @param id a number for the class from class_id.h enumeration
70 * @param className the class name
71*/
72void BaseObject::setClassID(long classID, const char* className)
73{
74  this->classID |= classID;
75  this->className = className;
76
77  ClassList::addToClassList(this, classID, className);
78}
79
80/**
81  \brief set the name of the Object
82 */
83void BaseObject::setName (const char* objectName)
84{
85  if (this->objectName)
86    delete[] this->objectName;
87  if (objectName)
88  {
89    this->objectName = new char[strlen(objectName)+1];
90    strcpy(this->objectName, objectName);
91  }
92  else
93    this->objectName = NULL;
94}
95
96
97/**
98 *  checks if the class is a classID
99 * @param classID the Identifier to check for
100 * @returns true if it is, false otherwise
101*/
102bool BaseObject::isA (long classID) const
103{
104  // if classID is a derivable object from a SUPERCLASS
105  if (classID & CL_MASK_SUPER_CLASS)
106  {
107    if( likely(this->classID & classID))
108      return true;
109  }
110  // if classID is a SubSuperClass, and
111  else if (classID & CL_MASK_SUBSUPER_CLASS)
112  {
113    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_ID) == (this->classID & CL_MASK_SUBSUPER_CLASS_ID)) &&
114        this->classID & classID & CL_MASK_SUBSUPER_CLASS_ID2))
115      return true;
116  }
117  // if classID is a LOWLEVEL-class
118  else
119  {
120    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
121      return true;
122  }
123  return false;
124}
125
126/**
127 *  displays everything this class is
128 */
129void BaseObject::whatIs() const
130{
131  PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
132  if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
133    PRINT(0)("is a Singleton-Class ");
134  if (this->classID & CL_MASK_SUPER_CLASS)
135  {
136    PRINT(0)(" ->is a derived from the following superclasses:");
137    if (this->isA(CL_BASE_OBJECT))
138      PRINT(0)(" =BaseObject=");
139    if (this->isA(CL_PARENT_NODE))
140      PRINT(0)(" =PNode=");
141    if (this->isA(CL_WORLD_ENTITY))
142      PRINT(0)(" =WorldEntity=");
143    if (this->isA(CL_PHYSICS_INTERFACE))
144      PRINT(0)(" =PhysicsInterface=");
145    if (this->isA(CL_EVENT_LISTENER))
146      PRINT(0)(" =EventListener=");
147    if (this->isA(CL_STORY_ENTITY))
148      PRINT(0)(" =StoryEntity=");
149    if (this->isA(CL_ELEMENT_2D))
150      PRINT(0)(" =Element2D=");
151    PRINT(0)("\n");
152  }
153  // subsuper-classes
154  if (this->classID & CL_MASK_SUBSUPER_CLASS)
155  {
156    PRINT(0)(" ->further derivations: ");
157    if (this->isA(CL_PLAYER))
158      PRINT(0)(" -Player-");
159    if (this->isA(CL_NPC))
160      PRINT(0)(" -NPC-");
161    if (this->isA(CL_POWER_UP))
162      PRINT(0)(" -PowerUp-");
163    if (this->isA(CL_FIELD))
164      PRINT(0)(" -Field-");
165    if (this->isA(CL_PROJECTILE))
166      PRINT(0)(" -Projectile-");
167    if (this->isA(CL_WEAPON))
168      PRINT(0)(" -Weapon-");
169    PRINT(0)("\n");
170  }
171}
Note: See TracBrowser for help on using the repository browser.