Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/lang/base_object.cc @ 9304

Last change on this file since 9304 was 9304, checked in by bensch, 18 years ago

orxonox/trunk: virtual public and an ip class

File size: 4.1 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: Benjamin Grauer
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
18
19#include "base_object.h"
20
21#include "util/loading/load_param.h"
22#include "class_list.h"
23
24#include "synchronizeable.h"
25
26
27/**
28 * @brief sets the name from a LoadXML-Element
29 * @param root the element to load from
30 */
31BaseObject::BaseObject(const std::string& objectName)
32{
33  this->classID = CL_BASE_OBJECT;
34  this->className = "BaseObject";
35
36  this->objectName = objectName;
37  this->classList = NULL;
38  this->xmlElem = NULL;
39
40  //ClassList::addToClassList(this, this->classID, "BaseObject");
41}
42
43/**
44 * @brief standard deconstructor
45*/
46BaseObject::~BaseObject ()
47{
48  ClassList::removeFromClassList(this);
49
50  //  delete []this->className;
51  if (this->xmlElem != NULL)
52    delete this->xmlElem;
53}
54
55/**
56 * @brief loads parameters
57 * @param root the element to load from
58 */
59void BaseObject::loadParams(const TiXmlElement* root)
60{
61  // all loadParams should sometime arrive here.
62  assert (root != NULL);
63
64  if (this->xmlElem != NULL)
65    delete this->xmlElem;
66  this->xmlElem = root->Clone();
67  // name setup
68  LoadParam(root, "name", this, BaseObject, setName)
69      .describe("the Name of the Object.");
70}
71
72/**
73 * @brief sets the class identifiers
74 * @param id a number for the class from class_id.h enumeration
75 * @param className the class name
76*/
77void BaseObject::setClassID(ClassID classID, const std::string& className)
78{
79  //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);
80  assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA ));
81
82  this->leafClassID = classID;
83  this->classID |= (long)classID;
84  this->className = className;
85
86  this->classList = ClassList::addToClassList(this, classID, this->classID, className);
87}
88
89
90/**
91 * @brief set the name of the Object
92 */
93void BaseObject::setName (const std::string& objectName)
94{
95  this->objectName = objectName;
96}
97
98
99/**
100 * @brief queries for the ClassID of the Leaf Class (the last made class of this type
101 * @returns the ClassID of the Leaf Class (e.g. the ID of the Class)
102 *
103 * the returned ID can be used to generate new Objects of the same type through
104 * Factory::fabricate(Object->getLeafClassID());
105 */
106const ClassID& BaseObject::getLeafClassID() const
107{
108  return this->leafClassID;
109}
110
111
112
113/**
114 * @brief checks if the class is a classID
115 * @param classID the Identifier to check for
116 * @returns true if it is, false otherwise
117*/
118bool BaseObject::isA (ClassID classID) const
119{
120  // if classID is a derivable object from a SUPERCLASS
121  if (classID & CL_MASK_SUPER_CLASS)
122  {
123    if( likely(this->classID & classID))
124      return true;
125  }
126  // if classID is a SubSuperClass, and
127  else if (classID & CL_MASK_SUBSUPER_CLASS)
128  {
129    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
130        this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
131      return true;
132  }
133  // if classID is a LOWLEVEL-class
134  else
135  {
136    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
137      return true;
138  }
139  return false;
140}
141
142
143
144/**
145 * @brief checks if the class is a classID
146 * @param classID the Identifier to check for
147 * @returns true if it is, false otherwise
148 */
149bool BaseObject::isA (const std::string& className) const
150{
151  ClassID classID = ClassList::StringToID(className);
152  if (classID != CL_NULL)
153    return this->isA(classID);
154  else
155    return false;
156}
157
158
159/**
160 * @brief compares the ObjectName with an external name
161 * @param objectName: the name to check.
162 * @returns true on match, false otherwise.
163 */
164bool BaseObject::operator==(const std::string& objectName)
165{
166  return (this->objectName == objectName);
167}
168
169
170/**
171 * @brief displays everything this class is
172 * @TODO REIMPLEMENT WITH SENSE.
173 */
174void BaseObject::whatIs() const
175{
176
177}
Note: See TracBrowser for help on using the repository browser.