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