Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/lang/base_object.cc @ 6461

Last change on this file since 6461 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
RevLine 
[3302]1
2
[4591]3/*
[3302]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*/
[5439]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
[3302]18
19#include "base_object.h"
[4747]20
[4436]21#include "load_param.h"
[4595]22#include "compiler.h"
[4747]23#include "class_list.h"
[3302]24
[6341]25#include "synchronizeable.h"
26
[3302]27using namespace std;
28
29
30/**
[6280]31 * @brief sets the name from a LoadXML-Element
[4836]32 * @param root the element to load from
[5439]33 */
[4436]34BaseObject::BaseObject(const TiXmlElement* root)
[3531]35{
[6276]36  this->className = "BaseObject";
[4591]37  this->classID = CL_BASE_OBJECT;
[4435]38
39  this->objectName = NULL;
[6280]40  this->classList = NULL;
[4436]41
42  if (root)
43    this->loadParams(root);
[4747]44
[4778]45//  ClassList::addToClassList(this, this->classID, "BaseObject");
[3531]46}
[3302]47
48/**
[6280]49 * @brief standard deconstructor
[3302]50*/
[4591]51BaseObject::~BaseObject ()
[3531]52{
[4747]53  ClassList::removeFromClassList(this);
54
[4261]55  //  delete []this->className;
[4435]56  if (this->objectName)
[5447]57    delete[] this->objectName;
58}
[3302]59
[4436]60/**
[6280]61 * @brief loads parameters
[4836]62 * @param root the element to load from
[5439]63 */
[4436]64void BaseObject::loadParams(const TiXmlElement* root)
65{
66  // name setup
[5671]67  LoadParam(root, "name", this, BaseObject, setName)
[5645]68      .describe("the Name of the Object.");
[4436]69}
[4321]70
71/**
[6280]72 * @brief sets the class identifiers
[4836]73 * @param id a number for the class from class_id.h enumeration
74 * @param className the class name
[4321]75*/
[5791]76void BaseObject::setClassID(ClassID classID, const char* className)
[4320]77{
[6282]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 ));
[6276]80
[5791]81  this->classID |= (long)classID;
[4320]82  this->className = className;
[4747]83
[6280]84  this->classList = ClassList::addToClassList(this, classID, this->classID, className);
[4320]85}
[4318]86
[6280]87
[4435]88/**
[6280]89 * @brief set the name of the Object
[4591]90 */
[4742]91void BaseObject::setName (const char* objectName)
[4435]92{
93  if (this->objectName)
[5113]94    delete[] this->objectName;
[5645]95  if (objectName != NULL)
[4592]96  {
97    this->objectName = new char[strlen(objectName)+1];
98    strcpy(this->objectName, objectName);
99  }
[4591]100  else
[4435]101    this->objectName = NULL;
102}
[4592]103
[6281]104
[6280]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}
[4592]117
[6280]118
119
[4592]120/**
[6280]121 * @brief checks if the class is a classID
[4836]122 * @param classID the Identifier to check for
123 * @returns true if it is, false otherwise
[4592]124*/
[6077]125bool BaseObject::isA (ClassID classID) const
[4592]126{
[4837]127  // if classID is a derivable object from a SUPERCLASS
128  if (classID & CL_MASK_SUPER_CLASS)
[4594]129  {
[4837]130    if( likely(this->classID & classID))
[4594]131      return true;
[4837]132  }
133  // if classID is a SubSuperClass, and
134  else if (classID & CL_MASK_SUBSUPER_CLASS)
135  {
[5915]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))
[4837]138      return true;
139  }
140  // if classID is a LOWLEVEL-class
[4594]141  else
142  {
[4837]143    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
[4594]144      return true;
145  }
[4592]146  return false;
147}
148
[6280]149
150
[4592]151/**
[6280]152 * @brief checks if the class is a classID
[5513]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{
[6077]158  ClassID classID = ClassList::StringToID(className);
[5513]159  if (classID != CL_NULL)
160    return this->isA(classID);
161}
162
[6280]163
[5626]164/**
[6280]165 * @brief compares the ObjectName with an external name
[5626]166 * @param objectName: the name to check.
167 * @returns true on match, false otherwise.
168 */
[5791]169bool BaseObject::operator==(const char* objectName)
[5626]170{
171  if (likely(this->objectName != NULL && objectName != NULL))
172    return (strcmp(this->objectName, objectName)) ? false : true;
173}
[5513]174
[5626]175
[5513]176/**
[6280]177 * @brief displays everything this class is
[5642]178 * @TODO REIMPLEMENT WITH SENSE.
[4592]179 */
[4746]180void BaseObject::whatIs() const
[4592]181{
[6280]182
[4592]183}
[6341]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.