Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: isA should work now

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