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
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
[4744]65   \param id a number for the class from class_id.h enumeration
[4470]66   \param className the class name
[4321]67*/
[4591]68void BaseObject::setClassID(long classID, const char* className)
[4320]69{
[4592]70  this->classID |= classID;
[4320]71  this->className = className;
72}
[4318]73
[4435]74/**
[4591]75  \brief set the name of the Object
76 */
[4742]77void BaseObject::setName (const char* objectName)
[4435]78{
79  if (this->objectName)
80    delete []this->objectName;
[4591]81  if (objectName)
[4592]82  {
83    this->objectName = new char[strlen(objectName)+1];
84    strcpy(this->objectName, objectName);
85  }
[4591]86  else
[4435]87    this->objectName = NULL;
88}
[4592]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*/
[4595]96bool BaseObject::isA (ClassID classID) const
[4592]97{
[4594]98  // if classID is a derivable object
[4595]99  if (likely(classID & CL_MASK_SUPER_CLASS || classID & CL_MASK_SUBSUPER_CLASS))
[4594]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  }
[4592]110  return false;
111}
112
113/**
114 * @brief displays everything this class is
115 */
[4746]116void BaseObject::whatIs() const
[4592]117{
[4595]118  PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
[4596]119  if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
120    PRINT(0)("is a Singleton-Class ");
[4594]121  if (this->classID & CL_MASK_SUPER_CLASS)
[4592]122  {
[4596]123    PRINT(0)(" ->is a derived from the following superclasses:");
[4595]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");
[4592]137  }
[4595]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  }
[4592]156}
Note: See TracBrowser for help on using the repository browser.