Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9673 in orxonox.OLD for trunk/src/lib/lang


Ignore:
Timestamp:
Aug 21, 2006, 6:22:53 PM (18 years ago)
Author:
bensch
Message:

ClassList seems to work as it should.

Location:
trunk/src/lib/lang
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/lang/new_class_id.cc

    r9672 r9673  
    3535{
    3636  //  assert(_objectList != NULL);
    37   std::list<NewObjectListBase::ClassEntry>::iterator it;
     37  ClassList::iterator it;
    3838  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
    3939    (*it)._objectList->unregisterObject((*it)._iterator);
  • trunk/src/lib/lang/new_class_id.h

    r9672 r9673  
    88#define _NEW_CLASS_ID_H
    99
    10 #include "type_info.h"
     10#include "new_object_list.h"
     11
    1112#include <string>
    1213#include <list>
    13 #include "new_object_list.h"
    1414
    1515
     
    2323  ~NewClassID();
    2424
     25
    2526  template<class T> void registerObject(T* object, NewObjectList<T>& list);
     27  bool isA(const NewObjectListBase& objectList) const;
     28  bool isA(int id) const;
     29  bool isA(const std::string& className) const;
    2630
    2731private:
    28   std::list<NewObjectListBase::ClassEntry>       _classes;
     32
     33  //////////////////////////////
     34  //// Type Definition Part ////
     35  //////////////////////////////
     36  //! A ClassEntry so we can store Classes inside of Objects
     37  struct ClassEntry{
     38    /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */
     39    inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
     40    NewObjectListBase*                _objectList;  //!< A ObjectList this Object is part of
     41    NewObjectListBase::IteratorBase*  _iterator;    //!< An iterator pointing to the position of the Object inside of the List.
     42  };
     43  typedef std::list<ClassEntry>        ClassList;   //!< Type definition for the List.
     44  ClassList                           _classes;     //!< All Classes this object is part of.
    2945};
    3046
    3147
     48/**
     49 * @brief Registeres an Object of Type T to objectList
     50 * @param object The Object to append to the objectList.
     51 * @param objectList The ObjectList to append the Object to.
     52 *
     53 * This function is essential to integrate objects into their designated ObjectList.
     54 * Remember if you do not want objects to be stored in Lists (less overhead),
     55 * do not attempt to call this function.
     56 */
    3257template<class T>
    3358    inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList)
    3459{
    35   this->_classes.push_back(NewObjectListBase::ClassEntry(&objectList, objectList.registerObject(object)));
    36 
    37   /*  this->_objectList = &objectList;
    38   _iterators.push_back(objectList.registerObject(object, this->_objectList));*/
     60  this->_classes.push_back(ClassEntry(&objectList, objectList.registerObject(object)));
    3961}
    4062
  • trunk/src/lib/lang/new_object_list.h

    r9672 r9673  
    2121   NewObjectList<ClassName> ClassName::objectList(#ClassName)
    2222
     23
     24//! The superclass that all NewObjectLists follow.
     25/**
     26 * @see template<class T> NewObjectList<T>
     27 */
    2328class NewObjectListBase
    2429{
    2530public:
     31  //! An iterator Base-Class, for iterator-casting and storing.
    2632  class IteratorBase { };
    27   struct ClassEntry{
    28     inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
    29     NewObjectListBase*                _objectList;
    30     NewObjectListBase::IteratorBase*  _iterator;
    31   };
    3233
    3334public:
     
    8384//! Defines a ObjectsList handler for objects of type T.
    8485/**
     86 * To define a Class with a ObjectList, you have to:
     87 *  1. Include 'NewObjectListDeclaration(T);' in its Declaration (at the beginning)
     88 *  2. Include 'NewObjectListDefinition(T);' in some Definition file (cc-file)
     89 *  3. In the constructor add 'registerObject(this, objectList);'
     90 *
    8591 * @note The Class must define the compare with const std::string& operator for this to work.
    8692 */
  • trunk/src/lib/lang/test_object_list.cc

    r9672 r9673  
    55class BaseObject
    66{
    7   public:
    8     void setName(const std::string& name) { this->_objectName = name; };
     7public:
     8  void setName(const std::string& name) { this->_objectName = name; };
    99  const std::string& name() const { return _objectName; };
    1010  bool operator==(const std::string& name) const { return _objectName == name; };
     
    1616  BaseObject(const std::string& objectName = "") : _objectName(objectName) { this->registerObject(this, objectList); };
    1717  template<class T>
    18       inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); };
    19   private:
     18  inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); };
     19private:
    2020  NewClassID    _id;
    2121  std::string   _objectName;
     
    4141{
    4242  this->registerObject(this, Test::objectList);
    43   std::cout << "Test()\n";
     43 // std::cout << "Test()\n";
    4444};
    4545Test::~Test()
    46 { std::cout << "~Test()\n"; }
     46{
     47//  std::cout << "~Test()\n";
     48}
    4749
    4850class Bone : public BaseObject
    4951{
    5052public:
    51   Bone() {
     53  Bone()
     54  {
    5255    this->registerObject(this, Bone::objectList);
    53     std::cout << "Bone()\n"; };
    54   ~Bone() { std::cout << "~Bone()\n"; };
     56    //std::cout << "Bone()\n";
     57  };
     58  ~Bone() {
     59  //  std::cout << "~Bone()\n";
     60  };
    5561  NewObjectListDeclaration(Bone);
    5662};
     
    5965int main()
    6066{
    61   Test* test = new Test();
    62   test->setName("Test-object");
    63 
    64   Test::objectList.debug();
    6567
    6668
    67   Test::objectList.debug();
     69
     70  Test* test = new Test[1000000];
     71  //test->setName("Test-object");
     72
     73//  Test::objectList.debug();
     74/*
    6875  Bone* bone = new Bone();
    69   bone->setName("Bone-object");
     76  bone->setName("Bone-object");*/
    7077
    71   std::cout << "Here is debug of all Classes\n";
    72   BaseObject::objectList.debug();
    73   delete bone;
    74   delete test;
    75 
     78  //std::cout << "Here is debug of all Classes\n";
     79  //BaseObject::objectList.debug();
     80//   delete bone;
     81  delete []test;
    7682}
    7783
Note: See TracChangeset for help on using the changeset viewer.