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