Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk:restoring the trunk…

File size: 4.0 KB
RevLine 
[3302]1
2
[4591]3/*
[3302]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"
[4747]20
[4436]21#include "load_param.h"
[4595]22#include "compiler.h"
[4747]23#include "class_list.h"
[3302]24
25using namespace std;
26
27
28/**
[4836]29 *  sets the name from a LoadXML-Element
30 * @param root the element to load from
[3302]31*/
[4436]32BaseObject::BaseObject(const TiXmlElement* root)
[3531]33{
34  this->className = NULL;
[4591]35  this->classID = CL_BASE_OBJECT;
[4435]36
37  this->objectName = NULL;
[4436]38
39  if (root)
40    this->loadParams(root);
[4747]41
[4778]42//  ClassList::addToClassList(this, this->classID, "BaseObject");
[3531]43}
[3302]44
45/**
[4836]46 *  standard deconstructor
[3302]47*/
[4591]48BaseObject::~BaseObject ()
[3531]49{
[4747]50  ClassList::removeFromClassList(this);
51
[4261]52  //  delete []this->className;
[4435]53  if (this->objectName)
[5113]54    delete[] this->objectName;}
[3302]55
[4436]56/**
[4836]57 *  loads parameters
58 * @param root the element to load from
[4436]59*/
60void BaseObject::loadParams(const TiXmlElement* root)
61{
62  // name setup
63  LoadParam<BaseObject>(root, "name", this, &BaseObject::setName)
[4874]64      .describe("the name of the Object at hand");
[4436]65}
[4321]66
67/**
[4836]68 *  sets the class identifiers
69 * @param id a number for the class from class_id.h enumeration
70 * @param className the class name
[4321]71*/
[4591]72void BaseObject::setClassID(long classID, const char* className)
[4320]73{
[4592]74  this->classID |= classID;
[4320]75  this->className = className;
[4747]76
77  ClassList::addToClassList(this, classID, className);
[4320]78}
[4318]79
[4435]80/**
[4591]81  \brief set the name of the Object
82 */
[4742]83void BaseObject::setName (const char* objectName)
[4435]84{
85  if (this->objectName)
[5113]86    delete[] this->objectName;
[4591]87  if (objectName)
[4592]88  {
89    this->objectName = new char[strlen(objectName)+1];
90    strcpy(this->objectName, objectName);
91  }
[4591]92  else
[4435]93    this->objectName = NULL;
94}
[4592]95
96
97/**
[4836]98 *  checks if the class is a classID
99 * @param classID the Identifier to check for
100 * @returns true if it is, false otherwise
[4592]101*/
[4747]102bool BaseObject::isA (long classID) const
[4592]103{
[4837]104  // if classID is a derivable object from a SUPERCLASS
105  if (classID & CL_MASK_SUPER_CLASS)
[4594]106  {
[4837]107    if( likely(this->classID & classID))
[4594]108      return true;
[4837]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
[4594]118  else
119  {
[4837]120    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
[4594]121      return true;
122  }
[4592]123  return false;
124}
125
126/**
[4836]127 *  displays everything this class is
[4592]128 */
[4746]129void BaseObject::whatIs() const
[4592]130{
[4595]131  PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
[4596]132  if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
133    PRINT(0)("is a Singleton-Class ");
[4594]134  if (this->classID & CL_MASK_SUPER_CLASS)
[4592]135  {
[4596]136    PRINT(0)(" ->is a derived from the following superclasses:");
[4595]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=");
[4874]149    if (this->isA(CL_ELEMENT_2D))
150      PRINT(0)(" =Element2D=");
[4595]151    PRINT(0)("\n");
[4592]152  }
[4595]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  }
[4592]171}
Note: See TracBrowser for help on using the repository browser.