Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: new safer concept for NewClassID

File size: 1.2 KB
Line 
1/*!
2 * @file new_class_id.h
3 * @brief Definition of a dynamically allocating ClassID
4 *
5 */
6
7#ifndef _NEW_CLASS_ID_H
8#define _NEW_CLASS_ID_H
9
10#include <string>
11
12class NewObjectListBase;
13
14//! A class to dynamically allocate ClassID's and support a isA operator
15class NewClassID
16{
17public:
18  NewClassID();
19  NewClassID(const NewObjectListBase* id);
20  // the copy constructor is also defined.
21  const int& id() const { return *_id; };
22  const std::string& name() const { return *_name; };
23
24  bool operator==(const NewClassID& id) const { return *_id == *id._id /* || _name == id._name */; };
25  bool operator==(int id) const { return *_id == id; };
26  bool operator==(const std::string& name) const { return *_name == name; };
27  bool operator!=(const NewClassID& id) const { return *_id != *id._id /* && _name != id._name*/;  };
28  bool operator!=(int id) const { return *_id != id; };
29  bool operator!=(const std::string& name) const { return *_name != name; };
30
31private:
32  const int*                _id;
33  const std::string*        _name;
34};
35
36class NullClass
37{
38public:
39  static NewClassID classID() { return NullClass::_classID; }
40private:
41  NullClass();
42private:
43  static NewClassID _classID;
44};
45
46#endif /* _NEW_CLASS_ID_H */
Note: See TracBrowser for help on using the repository browser.