Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/lang/base_object.cc @ 7907

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

orxonox/trunk: merged the QT_GUI back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/qt_gui . -r7607:HEAD

absolutely no conflicts :)

File size: 4.8 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
26using namespace std;
27
28
29/**
30 * @brief sets the name from a LoadXML-Element
31 * @param root the element to load from
32 */
33BaseObject::BaseObject(const std::string& objectName)
34{
35  this->classID = CL_BASE_OBJECT;
36  this->className = "BaseObject";
37
38  this->objectName = objectName;
39  this->classList = NULL;
40  this->xmlElem = NULL;
41
42  //ClassList::addToClassList(this, this->classID, "BaseObject");
43}
44
45/**
46 * @brief standard deconstructor
47*/
48BaseObject::~BaseObject ()
49{
50  ClassList::removeFromClassList(this);
51
52  //  delete []this->className;
53  if (this->xmlElem != NULL)
54    delete this->xmlElem;
55}
56
57/**
58 * @brief loads parameters
59 * @param root the element to load from
60 */
61void BaseObject::loadParams(const TiXmlElement* root)
62{
63  // all loadParams should sometime arrive here.
64  assert (root != NULL);
65
66  if (this->xmlElem != NULL)
67    delete this->xmlElem;
68  this->xmlElem = root->Clone();
69  // name setup
70  LoadParam(root, "name", this, BaseObject, setName)
71      .describe("the Name of the Object.");
72}
73
74/**
75 * @brief sets the class identifiers
76 * @param id a number for the class from class_id.h enumeration
77 * @param className the class name
78*/
79void BaseObject::setClassID(ClassID classID, const std::string& className)
80{
81  //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);
82  assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA ));
83
84  this->classID |= (long)classID;
85  this->className = className;
86
87  this->classList = ClassList::addToClassList(this, classID, this->classID, className);
88}
89
90
91/**
92 * @brief set the name of the Object
93 */
94void BaseObject::setName (const std::string& objectName)
95{
96  this->objectName = objectName;
97}
98
99
100/**
101 * @brief queries for the ClassID of the Leaf Class (the last made class of this type
102 * @returns the ClassID of the Leaf Class (e.g. the ID of the Class)
103 *
104 * the returned ID can be used to generate new Objects of the same type through
105 * Factory::fabricate(Object->getLeafClassID());
106 */
107ClassID BaseObject::getLeafClassID() const
108{
109  assert (this->classList != NULL);
110  return this->classList->getLeafClassID();
111}
112
113
114
115/**
116 * @brief checks if the class is a classID
117 * @param classID the Identifier to check for
118 * @returns true if it is, false otherwise
119*/
120bool BaseObject::isA (ClassID classID) const
121{
122  // if classID is a derivable object from a SUPERCLASS
123  if (classID & CL_MASK_SUPER_CLASS)
124  {
125    if( likely(this->classID & classID))
126      return true;
127  }
128  // if classID is a SubSuperClass, and
129  else if (classID & CL_MASK_SUBSUPER_CLASS)
130  {
131    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
132        this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
133      return true;
134  }
135  // if classID is a LOWLEVEL-class
136  else
137  {
138    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
139      return true;
140  }
141  return false;
142}
143
144
145
146/**
147 * @brief checks if the class is a classID
148 * @param classID the Identifier to check for
149 * @returns true if it is, false otherwise
150 */
151bool BaseObject::isA (const std::string& className) const
152{
153  ClassID classID = ClassList::StringToID(className);
154  if (classID != CL_NULL)
155    return this->isA(classID);
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}
178
179/**
180 * Writes data from network containing information about the state
181 * @param data pointer to data
182 * @param length length of data
183 * @param sender hostID of sender
184 */
185int BaseObject::writeState( const byte * data, int length, int sender )
186{
187  SYNCHELP_READ_BEGIN();
188
189  SYNCHELP_READ_STRING( this->objectName, NWT_BO_NAME );
190
191  return SYNCHELP_READ_N;
192}
193
194/**
195 * data copied in data will bee sent to another host
196 * @param data pointer to data
197 * @param maxLength max length of data
198 * @return the number of bytes writen
199 */
200int BaseObject::readState( byte * data, int maxLength )
201{
202  SYNCHELP_WRITE_BEGIN();
203
204  //PRINTF(0)("objectname = %s\n", this->objectName);
205  SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME );
206
207  return SYNCHELP_WRITE_N;
208}
Note: See TracBrowser for help on using the repository browser.