Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: classList now counts the count of classes

File size: 3.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
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 = NULL;
35  this->classID = CL_BASE_OBJECT;
36  this->finalized = false;
37
38  this->objectName = 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   \brief loads parameters
59   \param root the element to load from
60*/
61void BaseObject::loadParams(const TiXmlElement* root)
62{
63  // name setup
64  LoadParam<BaseObject>(root, "name", this, &BaseObject::setName)
65  .describe("the name of the Object at hand");
66}
67
68/**
69   \brief 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(long classID, const char* className)
74{
75  this->classID |= 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)
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   \brief 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
106  if (likely(classID & CL_MASK_SUPER_CLASS || classID & CL_MASK_SUBSUPER_CLASS))
107  {
108    if( this->classID & classID)
109      return true;
110  }
111  // if classID is a LOWLEVEL-class
112  else
113  {
114    if ((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID)
115      return true;
116  }
117  return false;
118}
119
120/**
121 * @brief displays everything this class is
122 */
123void BaseObject::whatIs() const
124{
125  PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
126  if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
127    PRINT(0)("is a Singleton-Class ");
128  if (this->classID & CL_MASK_SUPER_CLASS)
129  {
130    PRINT(0)(" ->is a derived from the following superclasses:");
131    if (this->isA(CL_BASE_OBJECT))
132      PRINT(0)(" =BaseObject=");
133    if (this->isA(CL_PARENT_NODE))
134      PRINT(0)(" =PNode=");
135    if (this->isA(CL_WORLD_ENTITY))
136      PRINT(0)(" =WorldEntity=");
137    if (this->isA(CL_PHYSICS_INTERFACE))
138      PRINT(0)(" =PhysicsInterface=");
139    if (this->isA(CL_EVENT_LISTENER))
140      PRINT(0)(" =EventListener=");
141    if (this->isA(CL_STORY_ENTITY))
142      PRINT(0)(" =StoryEntity=");
143    PRINT(0)("\n");
144  }
145  // subsuper-classes
146  if (this->classID & CL_MASK_SUBSUPER_CLASS)
147  {
148    PRINT(0)(" ->further derivations: ");
149    if (this->isA(CL_PLAYER))
150      PRINT(0)(" -Player-");
151    if (this->isA(CL_NPC))
152      PRINT(0)(" -NPC-");
153    if (this->isA(CL_POWER_UP))
154      PRINT(0)(" -PowerUp-");
155    if (this->isA(CL_FIELD))
156      PRINT(0)(" -Field-");
157    if (this->isA(CL_PROJECTILE))
158      PRINT(0)(" -Projectile-");
159    if (this->isA(CL_WEAPON))
160      PRINT(0)(" -Weapon-");
161    PRINT(0)("\n");
162  }
163}
Note: See TracBrowser for help on using the repository browser.