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 | { |
---|
47 | // std::cout << "~Test()\n"; |
---|
48 | } |
---|
49 | |
---|
50 | class Bone : public BaseObject |
---|
51 | { |
---|
52 | public: |
---|
53 | Bone() |
---|
54 | { |
---|
55 | this->registerObject(this, Bone::objectList); |
---|
56 | //std::cout << "Bone()\n"; |
---|
57 | }; |
---|
58 | ~Bone() { |
---|
59 | // std::cout << "~Bone()\n"; |
---|
60 | }; |
---|
61 | NewObjectListDeclaration(Bone); |
---|
62 | }; |
---|
63 | NewObjectListDefinition(Bone); |
---|
64 | |
---|
65 | int main() |
---|
66 | { |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | Test* test = new Test[1000000]; |
---|
71 | //test->setName("Test-object"); |
---|
72 | |
---|
73 | // Test::objectList.debug(); |
---|
74 | /* |
---|
75 | Bone* bone = new Bone(); |
---|
76 | bone->setName("Bone-object");*/ |
---|
77 | |
---|
78 | //std::cout << "Here is debug of all Classes\n"; |
---|
79 | //BaseObject::objectList.debug(); |
---|
80 | // delete bone; |
---|
81 | delete []test; |
---|
82 | } |
---|
83 | |
---|