Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/lang/class_id.h @ 9717

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

more renamings

File size: 3.0 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; };
[9678]49
[9659]50private:
[9709]51  const int*                _id;           //!< A pointer to the ID of the ClassID.
52  const std::string*        _name;         //!< A pointer to the Name of the ClassID.
[1853]53};
[9698]54
[9709]55//! A NullClass. This is the Null of the ClassID.
56/**
57 * implemented as a Class id can be used to reference NullObjects.
58 */
[9698]59class NullClass
60{
61public:
[9709]62  /** @returns the NullClass' ID. */
[9715]63  static const ClassID& classID() { return NullClass::_classID; }
[9709]64  /** @param id the ID to acquire @param name the name to acquire @brief acquires the ID of this Class */
65  static void acquireID(const int*& id, const std::string*& name) { id = &_nullID; name = &_nullName; };
66
[9698]67private:
[9709]68  NullClass() {}; //!< The Default Constructor is hidden from the User.
69
[9698]70private:
[9715]71  static ClassID         _classID;      //!< The NullClass' ID
[9709]72  static const std::string  _nullName;     //!< The NullClass' Name ("NullClass")
73  static int                _nullID;       //!< The NullClass' ID
[9698]74};
75
[9716]76#endif /* _CLASS_ID_H */
Note: See TracBrowser for help on using the repository browser.