Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/volumetric_fog/src/lib/lang/class_id.h @ 10172

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