Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: changed (void) → ()

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