Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/height_map_merge/src/lib/lang/base_object.cc @ 6540

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

orxonox/trunk: merged the network branche back to the trunk, so we do not get away from each other to fast

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