Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/lang/test_object_list.cc @ 9672

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

orxonox/trunk: ClassList objectively implemented. This is not the fastest, but the most modular approach.
Now is the question of redundancy in code writing:
Should the ClassWriter explicitely declare a Class with superclasses, or should on runtime each object decide for itself, as it is done in BaseObject at the moment… questions questions questions…

File size: 1.6 KB
Line 
1#include "new_class_id.h"
2#include "new_object_list.h"
3#include <iostream>
4
5class 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
15protected:
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};
25NewObjectListDefinition(BaseObject);
26
27
28class Test : public BaseObject
29{
30public:
31  Test();
32  ~Test();
33
34
35  NewObjectListDeclaration(Test);
36  //ObjectListDeclaration(Test);
37};
38NewObjectListDefinition(Test);
39
40Test::Test()
41{
42  this->registerObject(this, Test::objectList);
43  std::cout << "Test()\n";
44};
45Test::~Test()
46{ std::cout << "~Test()\n"; }
47
48class Bone : public BaseObject
49{
50public:
51  Bone() {
52    this->registerObject(this, Bone::objectList);
53    std::cout << "Bone()\n"; };
54  ~Bone() { std::cout << "~Bone()\n"; };
55  NewObjectListDeclaration(Bone);
56};
57NewObjectListDefinition(Bone);
58
59int 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
Note: See TracBrowser for help on using the repository browser.