Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9702 in orxonox.OLD for branches


Ignore:
Timestamp:
Aug 25, 2006, 11:54:18 AM (18 years ago)
Author:
bensch
Message:

new BaseObjectList retrieval function, thus removing the awefully strange and confusing virutal base_iterator

Location:
branches/new_class_id/src/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/lang/new_object_list.h

    r9701 r9702  
    1313#include <string>
    1414#include <iostream>
    15 
    16 
    1715
    1816/**
     
    7068  virtual void unregisterObject(IteratorBase* _iterators) = 0;
    7169
     70public:
     71  typedef std::list<BaseObject*>            base_list;
     72  typedef std::list<BaseObject*>::iterator  base_iterator;
     73
     74  virtual void getBaseObjectList(base_list* list) const = 0;
     75
     76  static const NewObjectListBase* const getObjectList(int classID);
     77  static const NewObjectListBase* const getObjectList(const std::string& className);
     78  static const NewObjectListBase* const getObjectList(const NewClassID& classID);
     79
     80  static BaseObject* getBaseObject(int classID, const std::string& objectName);
     81  static BaseObject* getBaseObject(const std::string& className, const std::string& objectName);
     82  static BaseObject* getBaseObject(const NewClassID& classID, const std::string& objectName);
     83
     84  virtual BaseObject* getBaseObject(const std::string& name) const = 0;
     85
    7286protected:
    7387  NewObjectListBase(const std::string& className, int id = -1);
     
    8094  static bool classNameExists(const std::string& className);
    8195
    82 public:
    83   class base_iterator
    84   {
    85   public:
    86     /// @NOTE Do not use this class. For internal handling.
    87     class __base_iterator_base
    88     {
    89     public:
    90       virtual void operator++(int) = 0;
    91       virtual void operator++() = 0;
    92       virtual void operator--(int) = 0;
    93       virtual void operator--() = 0;
    94       virtual BaseObject* operator*() = 0;
    95       virtual __base_iterator_base* operator=(const __base_iterator_base& iterator) = 0;
    96       virtual bool operator==(const __base_iterator_base& iterator) const = 0;
    97       virtual bool operator!=(const __base_iterator_base& iterator) const = 0;
    98       virtual __base_iterator_base* clone() const;
    99     };
    100 
    101   public:
    102     base_iterator(const __base_iterator_base& it) { _it = it.clone(); };
    103     ~base_iterator() { delete _it; }
    104     void operator++() { (*_it)++; };
    105     void operator++(int) { ++(*_it); };
    106     void operator--() { (*_it)--; };
    107     void operator--(int) { --(*_it); };
    108     BaseObject* operator*() { return *(*_it); };
    109     base_iterator& operator=(const base_iterator& iterator);
    110     bool operator==(const base_iterator& iter) const { return *this->_it == *iter._it; };
    111     bool operator!=(const base_iterator& iter) const { return *this->_it != *iter._it; };
    112 
    113   private:
    114     __base_iterator_base*    _it;
    115   };
    116 
    117   virtual base_iterator base_begin() const = 0;
    118   virtual base_iterator base_end() const = 0;
    119 
    120   static const NewObjectListBase* const getObjectList(int classID);
    121   static const NewObjectListBase* const getObjectList(const std::string& className);
    122   static const NewObjectListBase* const getObjectList(const NewClassID& classID);
    123 
    124   static BaseObject* getBaseObject(int classID, const std::string& objectName);
    125   static BaseObject* getBaseObject(const std::string& className, const std::string& objectName);
    126   static BaseObject* getBaseObject(const NewClassID& classID, const std::string& objectName);
    127 
    128   virtual BaseObject* getBaseObject(const std::string& name) const = 0;
    12996
    13097protected:
     
    162129  typedef typename list::iterator        iterator;
    163130  typedef typename list::const_iterator  const_iterator;
    164 
    165   virtual base_iterator base_begin() const { return base_iterator(__base_iterator(this->_objects.begin())); };
    166   virtual base_iterator base_end() const { return base_iterator(__base_iterator(this->_objects.end())); };
    167131
    168132
     
    199163
    200164protected:
    201 class __base_iterator : public base_iterator::__base_iterator_base
    202   {
    203   public:
    204     __base_iterator(const const_iterator& iter);
    205     void operator++(int) { ++_iter; };
    206     void operator++()  { _iter++; };
    207     void operator--(int) { --_iter; };
    208     void operator--()  { _iter--; };
    209     BaseObject* operator*() { return *_iter; };
    210     base_iterator::__base_iterator_base* operator=(const __base_iterator_base& iterator) { this->_iter = static_cast<const __base_iterator&>(iterator)._iter; return this; };
    211     bool operator==(const __base_iterator_base& iterator) const { return _iter == static_cast<const __base_iterator&>(iterator)._iter; };
    212     bool operator!=(const __base_iterator_base& iterator) const { return _iter != static_cast<const __base_iterator&>(iterator)._iter; };
    213   private:
    214     const_iterator _iter;
    215   };
     165  virtual void getBaseObjectList(NewObjectListBase::base_list* list) const;
     166
    216167
    217168private:
     
    282233
    283234/**
     235 * @brief retrieves a List of BaseObjects
     236 * @param list the list to push the ObjectList into.
     237 */
     238template <class T>
     239void NewObjectList<T>::getBaseObjectList(NewObjectListBase::base_list* list) const
     240{
     241  assert (list != NULL);
     242  const_iterator it;
     243  for (it = this->_objects.begin(); it != this->_objects.end(); ++it)
     244    list->push_back(*it);
     245}
     246
     247
     248/**
    284249 * @brief registers an Object to the NewObjectList.
    285250 * @param T object the Object to register.
  • branches/new_class_id/src/lib/shell/shell_command.cc

    r9697 r9702  
    244244    if (objectList != NULL)
    245245    {
    246       NewObjectListBase::base_iterator bo(objectList->base_begin());
     246      NewObjectListBase::base_list list;
     247      objectList->getBaseObjectList(&list);
     248      NewObjectListBase::base_iterator it;
    247249
    248250      // No Description given (only for speedup)
    249251      if (objectDescriptor.empty())
    250252      {
    251         for (; bo != objectList->base_end(); bo++)
    252           boList->push_back(*bo);
     253        for (it = list.begin(); it != list.end(); it++)
     254          boList->push_back(*it);
    253255      }
    254256      // some description
    255257      else
    256258      {
    257         for (bo = objectList->base_begin(); bo != objectList->base_end(); bo++)
    258           if (!nocaseCmp(objectDescriptor, (*bo)->getName(), objectDescriptor.size()))
    259             boList->push_back(*bo);
     259        for (it = list.begin(); it != list.end(); it++)
     260          if (!nocaseCmp(objectDescriptor, (*it)->getName(), objectDescriptor.size()))
     261            boList->push_back(*it);
    260262      }
    261263    }
Note: See TracChangeset for help on using the changeset viewer.