Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/lang/base_object.cc @ 9316

Last change on this file since 9316 was 9304, checked in by bensch, 19 years ago

orxonox/trunk: virtual public and an ip class

File size: 4.1 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]26
27/**
[6280]28 * @brief sets the name from a LoadXML-Element
[4836]29 * @param root the element to load from
[5439]30 */
[7661]31BaseObject::BaseObject(const std::string& objectName)
[3531]32{
[7221]33  this->classID = CL_BASE_OBJECT;
[6276]34  this->className = "BaseObject";
[4435]35
[7661]36  this->objectName = objectName;
[6280]37  this->classList = NULL;
[6517]38  this->xmlElem = NULL;
[4436]39
[7429]40  //ClassList::addToClassList(this, this->classID, "BaseObject");
[3531]41}
[3302]42
43/**
[6280]44 * @brief standard deconstructor
[3302]45*/
[4591]46BaseObject::~BaseObject ()
[3531]47{
[4747]48  ClassList::removeFromClassList(this);
49
[4261]50  //  delete []this->className;
[6517]51  if (this->xmlElem != NULL)
52    delete this->xmlElem;
[5447]53}
[3302]54
[4436]55/**
[6280]56 * @brief loads parameters
[4836]57 * @param root the element to load from
[5439]58 */
[4436]59void BaseObject::loadParams(const TiXmlElement* root)
60{
[6517]61  // all loadParams should sometime arrive here.
62  assert (root != NULL);
63
64  if (this->xmlElem != NULL)
65    delete this->xmlElem;
66  this->xmlElem = root->Clone();
[4436]67  // name setup
[5671]68  LoadParam(root, "name", this, BaseObject, setName)
[5645]69      .describe("the Name of the Object.");
[4436]70}
[4321]71
72/**
[6280]73 * @brief sets the class identifiers
[4836]74 * @param id a number for the class from class_id.h enumeration
75 * @param className the class name
[4321]76*/
[7221]77void BaseObject::setClassID(ClassID classID, const std::string& className)
[4320]78{
[6282]79  //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);
80  assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA ));
[6276]81
[7954]82  this->leafClassID = classID;
[5791]83  this->classID |= (long)classID;
[4320]84  this->className = className;
[4747]85
[6280]86  this->classList = ClassList::addToClassList(this, classID, this->classID, className);
[4320]87}
[4318]88
[6280]89
[4435]90/**
[6280]91 * @brief set the name of the Object
[4591]92 */
[7221]93void BaseObject::setName (const std::string& objectName)
[4435]94{
[7221]95  this->objectName = objectName;
[4435]96}
[4592]97
[6281]98
[6280]99/**
100 * @brief queries for the ClassID of the Leaf Class (the last made class of this type
101 * @returns the ClassID of the Leaf Class (e.g. the ID of the Class)
102 *
103 * the returned ID can be used to generate new Objects of the same type through
104 * Factory::fabricate(Object->getLeafClassID());
105 */
[7954]106const ClassID& BaseObject::getLeafClassID() const
[6280]107{
[7954]108  return this->leafClassID;
[6280]109}
[4592]110
[6280]111
112
[4592]113/**
[6280]114 * @brief checks if the class is a classID
[4836]115 * @param classID the Identifier to check for
116 * @returns true if it is, false otherwise
[4592]117*/
[6077]118bool BaseObject::isA (ClassID classID) const
[4592]119{
[4837]120  // if classID is a derivable object from a SUPERCLASS
121  if (classID & CL_MASK_SUPER_CLASS)
[4594]122  {
[4837]123    if( likely(this->classID & classID))
[4594]124      return true;
[4837]125  }
126  // if classID is a SubSuperClass, and
127  else if (classID & CL_MASK_SUBSUPER_CLASS)
128  {
[7123]129    if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
[5915]130        this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
[4837]131      return true;
132  }
133  // if classID is a LOWLEVEL-class
[4594]134  else
135  {
[4837]136    if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
[4594]137      return true;
138  }
[4592]139  return false;
140}
141
[6280]142
143
[4592]144/**
[6280]145 * @brief checks if the class is a classID
[5513]146 * @param classID the Identifier to check for
147 * @returns true if it is, false otherwise
148 */
[7221]149bool BaseObject::isA (const std::string& className) const
[5513]150{
[6077]151  ClassID classID = ClassList::StringToID(className);
[5513]152  if (classID != CL_NULL)
153    return this->isA(classID);
[8145]154  else
155    return false;
[5513]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}
Note: See TracBrowser for help on using the repository browser.