Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/proxy: merged the proxy.old back again, and it seems to work.

Merged with command
svn merge -r9247:HEAD https://svn.orxonox.net/orxonox/branches/proxy.old .

no conflicts

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