Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: one can now also tell Singleton-classes

File size: 3.9 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"
[4436]20#include "load_param.h"
[4595]21#include "compiler.h"
[3302]22
23using namespace std;
24
25
26/**
[4436]27   \brief sets the name from a LoadXML-Element
28   \param root the element to load from
[3302]29*/
[4436]30BaseObject::BaseObject(const TiXmlElement* root)
[3531]31{
32  this->className = NULL;
[4591]33  this->classID = CL_BASE_OBJECT;
[3646]34  this->finalized = false;
[4435]35
36  this->objectName = NULL;
[4436]37
38  if (root)
39    this->loadParams(root);
[3531]40}
[3302]41
42/**
43   \brief standard deconstructor
44*/
[4591]45BaseObject::~BaseObject ()
[3531]46{
[4261]47  //  delete []this->className;
[4435]48  if (this->objectName)
49    delete []this->objectName;
[3531]50}
[3302]51
[4436]52/**
53   \brief loads parameters
54   \param root the element to load from
55*/
56void BaseObject::loadParams(const TiXmlElement* root)
57{
58  // name setup
59  LoadParam<BaseObject>(root, "name", this, &BaseObject::setName)
[4591]60  .describe("the name of the Object at hand");
[4436]61}
[4321]62
63/**
64   \brief sets the class identifiers
[4470]65   \param id a number for the class from class_list.h enumeration
66   \param className the class name
[4321]67*/
[4591]68void BaseObject::setClassID(long classID, const char* className)
[4320]69{
[4591]70  this->setClassID(classID);
71  this->setClassName(className);
[4320]72}
[4318]73
[4320]74
[4321]75/**
76   \brief sets the class identifier
[4470]77   \param id a number for the class from class_list.h enumeration
[4321]78*/
[4591]79void BaseObject::setClassID (long classID)
[3302]80{
[4592]81  this->classID |= classID;
[3302]82}
83
[4321]84
85/**
86   \brief sets the class identifiers
[4470]87   \param className the class name
[4321]88*/
[4320]89void BaseObject::setClassName(const char* className)
90{
91  this->className = className;
92}
[4318]93
[4435]94/**
[4591]95  \brief set the name of the Object
96 */
[4592]97             void BaseObject::setName (const char* objectName)
[4435]98{
99  if (this->objectName)
100    delete []this->objectName;
[4591]101  if (objectName)
[4592]102  {
103    this->objectName = new char[strlen(objectName)+1];
104    strcpy(this->objectName, objectName);
105  }
[4591]106  else
[4435]107    this->objectName = NULL;
108}
[4592]109
110
111/**
112   \brief checks if the class is a classID
113   \param classID the Identifier to check for
114   \returns true if it is, false otherwise
115*/
[4595]116bool BaseObject::isA (ClassID classID) const
[4592]117{
[4594]118  // if classID is a derivable object
[4595]119  if (likely(classID & CL_MASK_SUPER_CLASS || classID & CL_MASK_SUBSUPER_CLASS))
[4594]120  {
121    if( this->classID & classID)
122      return true;
123  }
124  // if classID is a LOWLEVEL-class
125  else
126  {
127    if ((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID)
128      return true;
129  }
[4592]130  return false;
131}
132
133/**
134 * @brief displays everything this class is
135 */
136void BaseObject::whatIs(void) const
137{
[4595]138  PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
[4596]139  if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
140    PRINT(0)("is a Singleton-Class ");
[4594]141  if (this->classID & CL_MASK_SUPER_CLASS)
[4592]142  {
[4596]143    PRINT(0)(" ->is a derived from the following superclasses:");
[4595]144    if (this->isA(CL_BASE_OBJECT))
145      PRINT(0)(" =BaseObject=");
146    if (this->isA(CL_PARENT_NODE))
147      PRINT(0)(" =PNode=");
148    if (this->isA(CL_WORLD_ENTITY))
149      PRINT(0)(" =WorldEntity=");
150    if (this->isA(CL_PHYSICS_INTERFACE))
151      PRINT(0)(" =PhysicsInterface=");
152    if (this->isA(CL_EVENT_LISTENER))
153      PRINT(0)(" =EventListener=");
154    if (this->isA(CL_STORY_ENTITY))
155      PRINT(0)(" =StoryEntity=");
156    PRINT(0)("\n");
[4592]157  }
[4595]158  // subsuper-classes
159  if (this->classID & CL_MASK_SUBSUPER_CLASS)
160  {
161    PRINT(0)(" ->further derivations: ");
162    if (this->isA(CL_PLAYER))
163      PRINT(0)(" -Player-");
164    if (this->isA(CL_NPC))
165      PRINT(0)(" -NPC-");
166    if (this->isA(CL_POWER_UP))
167      PRINT(0)(" -PowerUp-");
168    if (this->isA(CL_FIELD))
169      PRINT(0)(" -Field-");
170    if (this->isA(CL_PROJECTILE))
171      PRINT(0)(" -Projectile-");
172    if (this->isA(CL_WEAPON))
173      PRINT(0)(" -Weapon-");
174    PRINT(0)("\n");
175  }
[4592]176}
Note: See TracBrowser for help on using the repository browser.