Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/qt_gui/src/lib/lang/base_object.cc @ 7447

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

qt_gui: some more stuff

File size: 4.8 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
[6640]15   co-programmer: Benjamin Grauer
[3302]16*/
[5439]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE
[3302]18
19#include "base_object.h"
[4747]20
[7193]21#include "util/loading/load_param.h"
[4747]22#include "class_list.h"
[3302]23
[6341]24#include "synchronizeable.h"
25
[3302]26using namespace std;
27
28
29/**
[6280]30 * @brief sets the name from a LoadXML-Element
[4836]31 * @param root the element to load from
[5439]32 */
[7447]33BaseObject::BaseObject(const std::string& objectName)
[3531]34{
[7221]35  this->classID = CL_BASE_OBJECT;
[6276]36  this->className = "BaseObject";
[4435]37
[7447]38  this->objectName = objectName;
[6280]39  this->classList = NULL;
[6517]40  this->xmlElem = NULL;
[4436]41
[7429]42  //ClassList::addToClassList(this, this->classID, "BaseObject");
[3531]43}
[3302]44
45/**
[6280]46 * @brief standard deconstructor
[3302]47*/
[4591]48BaseObject::~BaseObject ()
[3531]49{
[4747]50  ClassList::removeFromClassList(this);
51
[4261]52  //  delete []this->className;
[6517]53  if (this->xmlElem != NULL)
54    delete this->xmlElem;
[5447]55}
[3302]56
[4436]57/**
[6280]58 * @brief loads parameters
[4836]59 * @param root the element to load from
[5439]60 */
[4436]61void BaseObject::loadParams(const TiXmlElement* root)
62{
[6517]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();
[4436]69  // name setup
[5671]70  LoadParam(root, "name", this, BaseObject, setName)
[5645]71      .describe("the Name of the Object.");
[4436]72}
[4321]73
74/**
[6280]75 * @brief sets the class identifiers
[4836]76 * @param id a number for the class from class_id.h enumeration
77 * @param className the class name
[4321]78*/
[7221]79void BaseObject::setClassID(ClassID classID, const std::string& className)
[4320]80{
[6282]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 ));
[6276]83
[5791]84  this->classID |= (long)classID;
[4320]85  this->className = className;
[4747]86
[6280]87  this->classList = ClassList::addToClassList(this, classID, this->classID, className);
[4320]88}
[4318]89
[6280]90
[4435]91/**
[6280]92 * @brief set the name of the Object
[4591]93 */
[7221]94void BaseObject::setName (const std::string& objectName)
[4435]95{
[7221]96  this->objectName = objectName;
[4435]97}
[4592]98
[6281]99
[6280]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}
[4592]112
[6280]113
114
[4592]115/**
[6280]116 * @brief checks if the class is a classID
[4836]117 * @param classID the Identifier to check for
118 * @returns true if it is, false otherwise
[4592]119*/
[6077]120bool BaseObject::isA (ClassID classID) const
[4592]121{
[4837]122  // if classID is a derivable object from a SUPERCLASS
123  if (classID & CL_MASK_SUPER_CLASS)
[4594]124  {
[4837]125    if( likely(this->classID & classID))
[4594]126      return true;
[4837]127  }
128  // if classID is a SubSuperClass, and
129  else if (classID & CL_MASK_SUBSUPER_CLASS)
130  {
[7123]131    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
[5915]132        this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
[4837]133      return true;
134  }
135  // if classID is a LOWLEVEL-class
[4594]136  else
137  {
[4837]138    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
[4594]139      return true;
140  }
[4592]141  return false;
142}
143
[6280]144
145
[4592]146/**
[6280]147 * @brief checks if the class is a classID
[5513]148 * @param classID the Identifier to check for
149 * @returns true if it is, false otherwise
150 */
[7221]151bool BaseObject::isA (const std::string& className) const
[5513]152{
[6077]153  ClassID classID = ClassList::StringToID(className);
[5513]154  if (classID != CL_NULL)
155    return this->isA(classID);
156}
157
[6280]158
[5626]159/**
[6280]160 * @brief compares the ObjectName with an external name
[5626]161 * @param objectName: the name to check.
162 * @returns true on match, false otherwise.
163 */
[7221]164bool BaseObject::operator==(const std::string& objectName)
[5626]165{
[7221]166  return (this->objectName == objectName);
[5626]167}
[5513]168
[5626]169
[5513]170/**
[6280]171 * @brief displays everything this class is
[5642]172 * @TODO REIMPLEMENT WITH SENSE.
[4592]173 */
[4746]174void BaseObject::whatIs() const
[4592]175{
[6280]176
[4592]177}
[6341]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{
[7230]187  SYNCHELP_READ_BEGIN();
[6341]188
[7230]189  SYNCHELP_READ_STRING( this->objectName, NWT_BO_NAME );
[7221]190
[7230]191  return SYNCHELP_READ_N;
[6341]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{
[7230]202  SYNCHELP_WRITE_BEGIN();
[6341]203
[6634]204  //PRINTF(0)("objectname = %s\n", this->objectName);
[6815]205  SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME );
[6341]206
[7230]207  return SYNCHELP_WRITE_N;
[6341]208}
Note: See TracBrowser for help on using the repository browser.