Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/std/src/lib/lang/base_object.cc @ 7214

Last change on this file since 7214 was 7214, checked in by bensch, 20 years ago

orxonox/trunk: now the branche works again, as it did before

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