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 | |
---|
12 | class NewObjectListBase; |
---|
13 | |
---|
14 | //! A class to dynamically allocate ClassID's and support a isA operator |
---|
15 | class NewClassID |
---|
16 | { |
---|
17 | public: |
---|
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 | |
---|
31 | private: |
---|
32 | const int* _id; |
---|
33 | const std::string* _name; |
---|
34 | }; |
---|
35 | |
---|
36 | class NullClass |
---|
37 | { |
---|
38 | public: |
---|
39 | static NewClassID classID() { return NullClass::_classID; } |
---|
40 | private: |
---|
41 | NullClass(); |
---|
42 | private: |
---|
43 | static NewClassID _classID; |
---|
44 | }; |
---|
45 | |
---|
46 | #endif /* _NEW_CLASS_ID_H */ |
---|
Note: See
TracBrowser
for help on using the repository browser.