Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

more renamings

File size: 3.0 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
50private:
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.
53};
54
55//! A NullClass. This is the Null of the ClassID.
56/**
57 * implemented as a Class id can be used to reference NullObjects.
58 */
59class NullClass
60{
61public:
62  /** @returns the NullClass' ID. */
63  static const ClassID& classID() { return NullClass::_classID; }
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
67private:
68  NullClass() {}; //!< The Default Constructor is hidden from the User.
69
70private:
71  static ClassID         _classID;      //!< The NullClass' ID
72  static const std::string  _nullName;     //!< The NullClass' Name ("NullClass")
73  static int                _nullID;       //!< The NullClass' ID
74};
75
76#endif /* _CLASS_ID_H */
Note: See TracBrowser for help on using the repository browser.