1 | #include "new_class_id.h" |
---|
2 | #include "new_object_list.h" |
---|
3 | #include <iostream> |
---|
4 | |
---|
5 | class BaseObject |
---|
6 | { |
---|
7 | public: |
---|
8 | void setName(const std::string& name) { this->_objectName = name; }; |
---|
9 | const std::string& name() const { return _objectName; }; |
---|
10 | bool operator==(const std::string& name) const { return _objectName == name; }; |
---|
11 | |
---|
12 | NewObjectListDeclaration(BaseObject); |
---|
13 | |
---|
14 | |
---|
15 | protected: |
---|
16 | BaseObject(const std::string& objectName = "") : _objectName(objectName) { this->registerObject(this, objectList); }; |
---|
17 | template<class T> |
---|
18 | inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); }; |
---|
19 | private: |
---|
20 | NewClassID _id; |
---|
21 | std::string _objectName; |
---|
22 | |
---|
23 | |
---|
24 | }; |
---|
25 | NewObjectListDefinition(BaseObject); |
---|
26 | |
---|
27 | |
---|
28 | class Test : public BaseObject |
---|
29 | { |
---|
30 | public: |
---|
31 | Test(); |
---|
32 | ~Test(); |
---|
33 | |
---|
34 | |
---|
35 | NewObjectListDeclaration(Test); |
---|
36 | //ObjectListDeclaration(Test); |
---|
37 | }; |
---|
38 | NewObjectListDefinition(Test); |
---|
39 | |
---|
40 | Test::Test() |
---|
41 | { |
---|
42 | this->registerObject(this, Test::objectList); |
---|
43 | std::cout << "Test()\n"; |
---|
44 | }; |
---|
45 | Test::~Test() |
---|
46 | { std::cout << "~Test()\n"; } |
---|
47 | |
---|
48 | class Bone : public BaseObject |
---|
49 | { |
---|
50 | public: |
---|
51 | Bone() { |
---|
52 | this->registerObject(this, Bone::objectList); |
---|
53 | std::cout << "Bone()\n"; }; |
---|
54 | ~Bone() { std::cout << "~Bone()\n"; }; |
---|
55 | NewObjectListDeclaration(Bone); |
---|
56 | }; |
---|
57 | NewObjectListDefinition(Bone); |
---|
58 | |
---|
59 | int main() |
---|
60 | { |
---|
61 | Test* test = new Test(); |
---|
62 | test->setName("Test-object"); |
---|
63 | |
---|
64 | Test::objectList.debug(); |
---|
65 | |
---|
66 | |
---|
67 | Test::objectList.debug(); |
---|
68 | Bone* bone = new Bone(); |
---|
69 | bone->setName("Bone-object"); |
---|
70 | |
---|
71 | std::cout << "Here is debug of all Classes\n"; |
---|
72 | BaseObject::objectList.debug(); |
---|
73 | delete bone; |
---|
74 | delete test; |
---|
75 | |
---|
76 | } |
---|
77 | |
---|