| 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 |  | 
|---|
| 18 |  | 
|---|
| 19 | #include "base_object.h" | 
|---|
| 20 | #include "load_param.h" | 
|---|
| 21 |  | 
|---|
| 22 | using namespace std; | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | /** | 
|---|
| 26 |    \brief sets the name from a LoadXML-Element | 
|---|
| 27 |    \param root the element to load from | 
|---|
| 28 | */ | 
|---|
| 29 | BaseObject::BaseObject(const TiXmlElement* root) | 
|---|
| 30 | { | 
|---|
| 31 |   this->className = NULL; | 
|---|
| 32 |   this->id = -1; | 
|---|
| 33 |   this->finalized = false; | 
|---|
| 34 |  | 
|---|
| 35 |   this->objectName = NULL; | 
|---|
| 36 |  | 
|---|
| 37 |   if (root) | 
|---|
| 38 |     this->loadParams(root); | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | /** | 
|---|
| 42 |    \brief standard deconstructor | 
|---|
| 43 | */ | 
|---|
| 44 | BaseObject::~BaseObject ()  | 
|---|
| 45 | { | 
|---|
| 46 |   //  delete []this->className; | 
|---|
| 47 |   if (this->objectName) | 
|---|
| 48 |     delete []this->objectName; | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | /** | 
|---|
| 52 |    \brief loads parameters | 
|---|
| 53 |    \param root the element to load from | 
|---|
| 54 | */ | 
|---|
| 55 | void BaseObject::loadParams(const TiXmlElement* root) | 
|---|
| 56 | { | 
|---|
| 57 |   // name setup | 
|---|
| 58 |   LoadParam<BaseObject>(root, "name", this, &BaseObject::setName) | 
|---|
| 59 |     .describe("the name of the Object at hand"); | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | /** | 
|---|
| 63 |    \brief sets the class identifiers | 
|---|
| 64 |    \param id a number for the class from class_list.h enumeration | 
|---|
| 65 |    \param className the class name | 
|---|
| 66 | */ | 
|---|
| 67 | void BaseObject::setClassID(int id, const char* className) | 
|---|
| 68 | { | 
|---|
| 69 |   this->id = id; | 
|---|
| 70 |   this->className = className; | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 |  | 
|---|
| 74 | /** | 
|---|
| 75 |    \brief sets the class identifier | 
|---|
| 76 |    \param id a number for the class from class_list.h enumeration | 
|---|
| 77 | */ | 
|---|
| 78 | void BaseObject::setClassID (int id) | 
|---|
| 79 | { | 
|---|
| 80 |   this->id = id; | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 |  | 
|---|
| 84 | /** | 
|---|
| 85 |    \brief sets the class identifiers | 
|---|
| 86 |    \param className the class name | 
|---|
| 87 | */ | 
|---|
| 88 | void BaseObject::setClassName(const char* className) | 
|---|
| 89 | { | 
|---|
| 90 |   this->className = className; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 |  | 
|---|
| 94 | /* | 
|---|
| 95 |    \brief sets the class identifiers | 
|---|
| 96 |    \param a number for the class from class_list.h enumeration | 
|---|
| 97 |    \param the class name | 
|---|
| 98 |  | 
|---|
| 99 | bool BaseObject::isA (char* className) | 
|---|
| 100 | { | 
|---|
| 101 |   if( this->className == className) | 
|---|
| 102 |     return false; | 
|---|
| 103 |   return true; | 
|---|
| 104 | } | 
|---|
| 105 | */ | 
|---|
| 106 |  | 
|---|
| 107 | /** | 
|---|
| 108 |   \brief set the name of the node | 
|---|
| 109 |  | 
|---|
| 110 |   for debug purposes realy usefull, not used to work properly | 
|---|
| 111 | */ | 
|---|
| 112 | void BaseObject::setName (const char* newName) | 
|---|
| 113 | { | 
|---|
| 114 |   if (this->objectName) | 
|---|
| 115 |     delete []this->objectName; | 
|---|
| 116 |   if (newName) | 
|---|
| 117 |     { | 
|---|
| 118 |       this->objectName = new char[strlen(newName)+1]; | 
|---|
| 119 |       strcpy(this->objectName, newName); | 
|---|
| 120 |     } | 
|---|
| 121 |   else  | 
|---|
| 122 |     this->objectName = NULL; | 
|---|
| 123 | } | 
|---|