[Orxonox-commit 4927] r9596 - code/branches/core6/src/libraries/core/object
landauf at orxonox.net
landauf at orxonox.net
Fri Mar 29 00:42:24 CET 2013
Author: landauf
Date: 2013-03-29 00:42:24 +0100 (Fri, 29 Mar 2013)
New Revision: 9596
Modified:
code/branches/core6/src/libraries/core/object/Iterator.h
code/branches/core6/src/libraries/core/object/MetaObjectList.cc
code/branches/core6/src/libraries/core/object/ObjectList.h
code/branches/core6/src/libraries/core/object/ObjectListBase.cc
code/branches/core6/src/libraries/core/object/ObjectListBase.h
Log:
ObjectListBaseElement now stores a pointer to the object list it belongs to. Removed ObjectListBase::Export. Iterator will now always use the list from the element.
Modified: code/branches/core6/src/libraries/core/object/Iterator.h
===================================================================
--- code/branches/core6/src/libraries/core/object/Iterator.h 2013-03-28 22:09:38 UTC (rev 9595)
+++ code/branches/core6/src/libraries/core/object/Iterator.h 2013-03-28 23:42:24 UTC (rev 9596)
@@ -55,7 +55,6 @@
#include "core/CorePrereqs.h"
-#include "core/class/Identifier.h"
#include "ObjectListBase.h"
namespace orxonox
@@ -77,42 +76,28 @@
*/
inline Iterator()
{
- this->element_ = 0;
- this->list_ = 0;
+ this->element_ = NULL;
+ this->list_ = NULL;
}
/**
- @brief Constructor: Sets this element to the exported element.
- @param exp The exported element
- */
- inline Iterator(const ObjectListBase::Export& exp)
- {
- this->element_ = exp.element_;
- this->list_ = exp.list_;
- this->list_->registerIterator(this);
- }
-
- /**
@brief Constructor: Sets this element to the element of another Iterator.
@param other The other Iterator
*/
inline Iterator(const Iterator<T>& other)
{
this->element_ = other.element_;
- this->list_ = other.list_;
- this->list_->registerIterator(this);
+ this->registerIterator();
}
/**
@brief Constructor: Sets this element to a given element
@param element The element
*/
- template <class O>
- inline Iterator(ObjectListElement<O>* element)
+ inline Iterator(ObjectListBaseElement* element)
{
this->element_ = element;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
+ this->registerIterator();
}
/**
@@ -123,8 +108,7 @@
inline Iterator(const ObjectListIterator<O>& other)
{
this->element_ = other.element_;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
+ this->registerIterator();
}
/**
@@ -132,37 +116,18 @@
*/
inline ~Iterator()
{
- this->list_->unregisterIterator(this);
+ this->unregisterIterator();
}
/**
- @brief Assigns an exported element.
- @param exp The exported element
- */
- inline Iterator<T>& operator=(const ObjectListBase::Export& exp)
- {
- if (this->list_)
- this->list_->unregisterIterator(this);
-
- this->element_ = exp.element_;
- this->list_ = exp.list_;
- this->list_->registerIterator(this);
-
- return (*this);
- }
-
- /**
@brief Assigns the element of another Iterator.
@param other The other Iterator
*/
inline Iterator<T>& operator=(const Iterator<T>& other)
{
- if (this->list_)
- this->list_->unregisterIterator(this);
-
+ this->unregisterIterator();
this->element_ = other.element_;
- this->list_ = other.list_;
- this->list_->registerIterator(this);
+ this->registerIterator();
return (*this);
}
@@ -171,15 +136,11 @@
@brief Assigns a given element.
@param element The element
*/
- template <class O>
- inline Iterator<T>& operator=(ObjectListElement<O>* element)
+ inline Iterator<T>& operator=(ObjectListBaseElement* element)
{
- if (this->list_)
- this->list_->unregisterIterator(this);
-
+ this->unregisterIterator();
this->element_ = element;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
+ this->registerIterator();
return (*this);
}
@@ -191,12 +152,9 @@
template <class O>
inline Iterator<T>& operator=(const ObjectListIterator<O>& other)
{
- if (this->list_)
- this->list_->unregisterIterator(this);
-
+ this->unregisterIterator();
this->element_ = other.element_;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
+ this->registerIterator();
return (*this);
}
@@ -267,7 +225,7 @@
*/
inline operator bool() const
{
- return (this->element_ != 0);
+ return (this->element_ != NULL);
}
/**
@@ -300,9 +258,32 @@
this->operator++();
}
- protected:
- ObjectListBaseElement* element_; //!< The element the Iterator points at
- ObjectListBase* list_; //!< The list wherein the element is
+ private:
+ /**
+ * @brief Registers the Iterator at the list to which it belongs
+ */
+ inline void registerIterator()
+ {
+ if (this->element_)
+ {
+ this->list_ = this->element_->list_;
+ this->list_->registerIterator(this);
+ }
+ else
+ this->list_ = NULL;
+ }
+
+ /**
+ * @brief Unregisters the Iterator from the list (if any)
+ */
+ inline void unregisterIterator()
+ {
+ if (this->list_)
+ this->list_->unregisterIterator(this);
+ }
+
+ ObjectListBaseElement* element_; //!< The element the Iterator points at
+ ObjectListBase* list_; //!< The list in which the Iterator registered itself
};
}
Modified: code/branches/core6/src/libraries/core/object/MetaObjectList.cc
===================================================================
--- code/branches/core6/src/libraries/core/object/MetaObjectList.cc 2013-03-28 22:09:38 UTC (rev 9595)
+++ code/branches/core6/src/libraries/core/object/MetaObjectList.cc 2013-03-28 23:42:24 UTC (rev 9596)
@@ -47,7 +47,6 @@
*/
MetaObjectListElement::~MetaObjectListElement()
{
- this->list_->removeElement(this->element_);
delete this->element_;
}
Modified: code/branches/core6/src/libraries/core/object/ObjectList.h
===================================================================
--- code/branches/core6/src/libraries/core/object/ObjectList.h 2013-03-28 22:09:38 UTC (rev 9595)
+++ code/branches/core6/src/libraries/core/object/ObjectList.h 2013-03-28 23:42:24 UTC (rev 9596)
@@ -71,28 +71,28 @@
inline static ObjectListElement<T>* begin()
{
ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
- return static_cast<ObjectListElement<T>*>(list->begin().element_);
+ return static_cast<ObjectListElement<T>*>(list->begin());
}
/// Returns an Iterator to the element after the last element in the list.
inline static ObjectListElement<T>* end()
{
ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
- return static_cast<ObjectListElement<T>*>(list->end().element_);
+ return static_cast<ObjectListElement<T>*>(list->end());
}
/// Returns an Iterator to the last element in the list.
inline static ObjectListElement<T>* rbegin()
{
ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
- return static_cast<ObjectListElement<T>*>(list->rbegin().element_);
+ return static_cast<ObjectListElement<T>*>(list->rbegin());
}
/// Returns an Iterator to the element before the first element in the list.
inline static ObjectListElement<T>* rend()
{
ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
- return static_cast<ObjectListElement<T>*>(list->rend().element_);
+ return static_cast<ObjectListElement<T>*>(list->rend());
}
};
}
Modified: code/branches/core6/src/libraries/core/object/ObjectListBase.cc
===================================================================
--- code/branches/core6/src/libraries/core/object/ObjectListBase.cc 2013-03-28 22:09:38 UTC (rev 9595)
+++ code/branches/core6/src/libraries/core/object/ObjectListBase.cc 2013-03-28 23:42:24 UTC (rev 9596)
@@ -40,6 +40,11 @@
namespace orxonox
{
+ ObjectListBaseElement::~ObjectListBaseElement()
+ {
+ this->list_->removeElement(this);
+ }
+
/**
@brief Constructor: Sets default values.
*/
Modified: code/branches/core6/src/libraries/core/object/ObjectListBase.h
===================================================================
--- code/branches/core6/src/libraries/core/object/ObjectListBase.h 2013-03-28 22:09:38 UTC (rev 9595)
+++ code/branches/core6/src/libraries/core/object/ObjectListBase.h 2013-03-28 23:42:24 UTC (rev 9596)
@@ -55,11 +55,13 @@
@brief Constructor: Creates the list-element with an object.
@param objectBase The object to store
*/
- ObjectListBaseElement(Listable* objectBase) : next_(0), prev_(0), objectBase_(objectBase) {}
+ ObjectListBaseElement(Listable* object, ObjectListBase* list) : next_(0), prev_(0), objectBase_(object), list_(list) {}
+ ~ObjectListBaseElement();
ObjectListBaseElement* next_; //!< The next element in the list
ObjectListBaseElement* prev_; //!< The previous element in the list
- Listable* objectBase_;
+ Listable* objectBase_; //!< The object
+ ObjectListBase* list_; //!< The list
};
@@ -71,7 +73,7 @@
class ObjectListElement : public ObjectListBaseElement
{
public:
- ObjectListElement(T* object) : ObjectListBaseElement(static_cast<Listable*>(object)), object_(object) {}
+ ObjectListElement(T* object, ObjectListBase* list) : ObjectListBaseElement(static_cast<Listable*>(object), list), object_(object) {}
T* object_; //!< The object
};
@@ -98,27 +100,19 @@
template <class T>
inline ObjectListBaseElement* add(T* object)
- { return this->addElement(new ObjectListElement<T>(object)); }
+ { return this->addElement(new ObjectListElement<T>(object, this)); }
ObjectListBaseElement* addElement(ObjectListBaseElement* element);
void removeElement(ObjectListBaseElement* element);
- /// Helper struct, used to export an element and the list to an instance of Iterator.
- struct Export
- {
- Export(ObjectListBase* list, ObjectListBaseElement* element) : list_(list), element_(element) {}
- ObjectListBase* list_;
- ObjectListBaseElement* element_;
- };
-
/// Returns a pointer to the first element in the list. Works only with Iterator.
- inline Export begin() { return ObjectListBase::Export(this, this->first_); }
+ inline ObjectListBaseElement* begin() { return this->first_; }
/// Returns a pointer to the element after the last element in the list. Works only with Iterator.
- inline Export end() { return ObjectListBase::Export(this, 0); }
+ inline ObjectListBaseElement* end() { return 0; }
/// Returns a pointer to the last element in the list. Works only with Iterator.
- inline Export rbegin() { return ObjectListBase::Export(this, this->last_); }
+ inline ObjectListBaseElement* rbegin() { return this->last_; }
/// Returns a pointer to the element in front of the first element in the list. Works only with Iterator.
- inline Export rend() { return ObjectListBase::Export(this, 0); }
+ inline ObjectListBaseElement* rend() { return 0; }
inline void registerIterator(void* iterator) { this->iterators_.push_back(iterator); }
inline void unregisterIterator(void* iterator)
More information about the Orxonox-commit
mailing list