Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/lang/class_id.h @ 10578

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.2 KB
RevLine 
[4838]1/*!
[9716]2 * @file class_id.h
[9659]3 * @brief Definition of a dynamically allocating ClassID
4 *
5 */
[1853]6
[9716]7#ifndef _CLASS_ID_H
8#define _CLASS_ID_H
[1853]9
[9659]10#include <string>
[9663]11
[9715]12class ObjectListBase;
[9701]13
[9709]14//! A class to dynamically allocate ClassID's and to support a isA operator
15/**
[9715]16 * A ClassID can only be aquired over a ObjectList,
[9709]17 * thus enabling the developer to have permanent access to the correct ID and ClassName
18 *
[9715]19 * The Idea behind this concept is, that storing a ClassID that changes its internal state
20 * all ClassID's will be updated correctly.
[9709]21 *
[9715]22 * Since the Existance of any ObjectList is a requirement during the working process all
[9709]23 * ID's should reference a valid ID and ClassName
24 */
[9715]25class ClassID
[9659]26{
27public:
[9715]28  ClassID();
29  ClassID(const ObjectListBase* const id);
[9709]30  /// the copy constructor is also defined implicitely.
31
32  /** @returns A constant reference to the ID. */
[9701]33  const int& id() const { return *_id; };
[9709]34  /** @returns A constant reference to the Name. */
[9701]35  const std::string& name() const { return *_name; };
[3245]36
[9709]37  /** @param id the id to compare @returns true on match (match is same ID) @brief compares two id's */
[9715]38  bool operator==(const ClassID& id) const { return *_id == *id._id /* || _name == id._name */; };
[9709]39  /** @param id the id to compare @returns true on match (match is same ID) @brief compares two id's */
[9701]40  bool operator==(int id) const { return *_id == id; };
[9709]41  /** @param name the id to compare @returns true on match (match is same Name) @brief compares an ID with a ClassName */
[9701]42  bool operator==(const std::string& name) const { return *_name == name; };
[9709]43  /** @param id the id to compare @returns false on match (match is same ID) @brief compares two id's */
[9715]44  bool operator!=(const ClassID& id) const { return *_id != *id._id /* && _name != id._name*/;  };
[9709]45  /** @param id the id to compare @returns false on match (match is same ID) @brief compares two id's */
[9701]46  bool operator!=(int id) const { return *_id != id; };
[9709]47  /** @param name the id to compare @returns false on match (match is same Name) @brief compares an ID with a ClassName */
[9701]48  bool operator!=(const std::string& name) const { return *_name != name; };
[9762]49  /** @param classID: the Id to compare @returns true if this id is smaller than the classID's ID */
50  bool operator<(const ClassID& classID) const { return *this->_id < *classID._id; };
[9678]51
[9659]52private:
[9709]53  const int*                _id;           //!< A pointer to the ID of the ClassID.
54  const std::string*        _name;         //!< A pointer to the Name of the ClassID.
[1853]55};
[9698]56
[9709]57//! A NullClass. This is the Null of the ClassID.
58/**
59 * implemented as a Class id can be used to reference NullObjects.
60 */
[9698]61class NullClass
62{
63public:
[9709]64  /** @returns the NullClass' ID. */
[9757]65  static const ClassID& staticClassID() { return NullClass::_classID; }
[9709]66  /** @param id the ID to acquire @param name the name to acquire @brief acquires the ID of this Class */
67  static void acquireID(const int*& id, const std::string*& name) { id = &_nullID; name = &_nullName; };
68
[9698]69private:
[9709]70  NullClass() {}; //!< The Default Constructor is hidden from the User.
71
[9698]72private:
[9757]73  static ClassID            _classID;      //!< The NullClass' ID
[9709]74  static const std::string  _nullName;     //!< The NullClass' Name ("NullClass")
75  static int                _nullID;       //!< The NullClass' ID
[9698]76};
77
[9716]78#endif /* _CLASS_ID_H */
Note: See TracBrowser for help on using the repository browser.