[Orxonox-commit 4888] r9557 - in code/branches/core6/src: libraries/core libraries/core/input libraries/core/object libraries/network libraries/network/packet modules/objects modules/objects/triggers modules/pickup orxonox orxonox/controllers orxonox/interfaces orxonox/sound
landauf at orxonox.net
landauf at orxonox.net
Sat Mar 23 18:49:53 CET 2013
Author: landauf
Date: 2013-03-23 18:49:52 +0100 (Sat, 23 Mar 2013)
New Revision: 9557
Added:
code/branches/core6/src/libraries/core/object/
code/branches/core6/src/libraries/core/object/CMakeLists.txt
code/branches/core6/src/libraries/core/object/ClassFactory.h
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/MetaObjectList.h
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
code/branches/core6/src/libraries/core/object/ObjectListIterator.h
code/branches/core6/src/libraries/core/object/SmartPtr.h
code/branches/core6/src/libraries/core/object/WeakPtr.h
Removed:
code/branches/core6/src/libraries/core/ClassFactory.h
code/branches/core6/src/libraries/core/Iterator.h
code/branches/core6/src/libraries/core/MetaObjectList.cc
code/branches/core6/src/libraries/core/MetaObjectList.h
code/branches/core6/src/libraries/core/ObjectList.h
code/branches/core6/src/libraries/core/ObjectListBase.cc
code/branches/core6/src/libraries/core/ObjectListBase.h
code/branches/core6/src/libraries/core/ObjectListIterator.h
code/branches/core6/src/libraries/core/SmartPtr.h
code/branches/core6/src/libraries/core/WeakPtr.h
Modified:
code/branches/core6/src/libraries/core/BaseObject.cc
code/branches/core6/src/libraries/core/BaseObject.h
code/branches/core6/src/libraries/core/CMakeLists.txt
code/branches/core6/src/libraries/core/ClassTreeMask.h
code/branches/core6/src/libraries/core/Core.cc
code/branches/core6/src/libraries/core/CoreIncludes.h
code/branches/core6/src/libraries/core/Identifier.cc
code/branches/core6/src/libraries/core/Identifier.h
code/branches/core6/src/libraries/core/Loader.cc
code/branches/core6/src/libraries/core/OrxonoxClass.cc
code/branches/core6/src/libraries/core/input/JoyStickQuantityListener.cc
code/branches/core6/src/libraries/network/Host.cc
code/branches/core6/src/libraries/network/Server.cc
code/branches/core6/src/libraries/network/packet/FunctionIDs.cc
code/branches/core6/src/libraries/network/packet/Gamestate.cc
code/branches/core6/src/modules/objects/SpaceBoundaries.cc
code/branches/core6/src/modules/objects/SpaceBoundaries.h
code/branches/core6/src/modules/objects/triggers/DistanceMultiTrigger.h
code/branches/core6/src/modules/pickup/PickupManager.h
code/branches/core6/src/orxonox/CameraManager.cc
code/branches/core6/src/orxonox/Radar.cc
code/branches/core6/src/orxonox/Radar.h
code/branches/core6/src/orxonox/controllers/DroneController.h
code/branches/core6/src/orxonox/interfaces/PlayerTrigger.h
code/branches/core6/src/orxonox/interfaces/RadarViewable.h
code/branches/core6/src/orxonox/sound/SoundManager.h
Log:
moved all files in core which are used for object management to a new subdirectory (core/object/)
Modified: code/branches/core6/src/libraries/core/BaseObject.cc
===================================================================
--- code/branches/core6/src/libraries/core/BaseObject.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/BaseObject.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -38,12 +38,12 @@
#include "CoreIncludes.h"
#include "Event.h"
#include "EventIncludes.h"
-#include "Iterator.h"
#include "Template.h"
#include "XMLFile.h"
#include "XMLNameListener.h"
#include "XMLPort.h"
#include "command/Functor.h"
+#include "object/Iterator.h"
namespace orxonox
{
Modified: code/branches/core6/src/libraries/core/BaseObject.h
===================================================================
--- code/branches/core6/src/libraries/core/BaseObject.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/BaseObject.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -50,7 +50,7 @@
#include "util/mbool.h"
#include "OrxonoxClass.h"
#include "Super.h"
-#include "SmartPtr.h"
+#include "object/SmartPtr.h"
namespace orxonox
{
Modified: code/branches/core6/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/core6/src/libraries/core/CMakeLists.txt 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/CMakeLists.txt 2013-03-23 17:49:52 UTC (rev 9557)
@@ -33,10 +33,8 @@
Language.cc
Loader.cc
LuaState.cc
- MetaObjectList.cc
Namespace.cc
NamespaceNode.cc
- ObjectListBase.cc
OrxonoxClass.cc
Template.cc
ViewportEventListener.cc
@@ -69,6 +67,7 @@
ADD_SUBDIRECTORY(command)
ADD_SUBDIRECTORY(input)
+ADD_SUBDIRECTORY(object)
ORXONOX_ADD_LIBRARY(core
FIND_HEADER_FILES
Deleted: code/branches/core6/src/libraries/core/ClassFactory.h
===================================================================
--- code/branches/core6/src/libraries/core/ClassFactory.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/ClassFactory.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,91 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @ingroup Object Factory
- @brief Definition and implementation of the ClassFactory class
-
- The ClassFactory is able to create new objects of a specific class which creates objects.
-*/
-
-#ifndef _ClassFactory_H__
-#define _ClassFactory_H__
-
-#include "CorePrereqs.h"
-
-#include <string>
-
-#include "util/Output.h"
-#include "Identifier.h"
-
-namespace orxonox
-{
- // ###########################
- // ### Factory ###
- // ###########################
- /// Base-class of ClassFactory.
- class _CoreExport Factory
- {
- public:
- virtual ~Factory() {};
- virtual OrxonoxClass* fabricate(BaseObject* creator) = 0;
- };
-
- // ###############################
- // ### ClassFactory ###
- // ###############################
- /// The ClassFactory is able to create new objects of a specific class.
- template <class T>
- class ClassFactory : public Factory
- {
- public:
- /**
- @brief Constructor: Adds the ClassFactory to the Identifier of the same type.
- @param name The name of the class
- @param bLoadable True if the class can be loaded through XML
- */
- ClassFactory(const std::string& name, bool bLoadable = true)
- {
- orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;
- ClassIdentifier<T>::getIdentifier(name)->addFactory(this);
- ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
- }
-
- /**
- @brief Creates and returns a new object of class T.
- @return The new object
- */
- inline OrxonoxClass* fabricate(BaseObject* creator)
- {
- return static_cast<OrxonoxClass*>(new T(creator));
- }
- };
-}
-
-#endif /* _ClassFactory_H__ */
Modified: code/branches/core6/src/libraries/core/ClassTreeMask.h
===================================================================
--- code/branches/core6/src/libraries/core/ClassTreeMask.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/ClassTreeMask.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -72,7 +72,7 @@
#include <list>
#include <stack>
#include "BaseObject.h"
-#include "Iterator.h"
+#include "object/Iterator.h"
namespace orxonox
{
Modified: code/branches/core6/src/libraries/core/Core.cc
===================================================================
--- code/branches/core6/src/libraries/core/Core.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/Core.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -70,12 +70,12 @@
#include "Identifier.h"
#include "Language.h"
#include "LuaState.h"
-#include "ObjectList.h"
#include "command/ConsoleCommand.h"
#include "command/IOConsole.h"
#include "command/TclBind.h"
#include "command/TclThreadManager.h"
#include "input/InputManager.h"
+#include "object/ObjectList.h"
namespace orxonox
{
Modified: code/branches/core6/src/libraries/core/CoreIncludes.h
===================================================================
--- code/branches/core6/src/libraries/core/CoreIncludes.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/CoreIncludes.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -79,8 +79,8 @@
#include "util/Output.h"
#include "Identifier.h"
-#include "ClassFactory.h"
-#include "ObjectList.h"
+#include "object/ClassFactory.h"
+#include "object/ObjectList.h"
/**
Modified: code/branches/core6/src/libraries/core/Identifier.cc
===================================================================
--- code/branches/core6/src/libraries/core/Identifier.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/Identifier.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -37,8 +37,8 @@
#include "util/StringUtils.h"
#include "ConfigValueContainer.h"
-#include "ClassFactory.h"
#include "XMLPort.h"
+#include "object/ClassFactory.h"
namespace orxonox
{
Modified: code/branches/core6/src/libraries/core/Identifier.h
===================================================================
--- code/branches/core6/src/libraries/core/Identifier.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/Identifier.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -89,9 +89,9 @@
#include <loki/TypeTraits.h>
#include "util/Output.h"
-#include "MetaObjectList.h"
-#include "ObjectList.h"
-#include "ObjectListBase.h"
+#include "object/MetaObjectList.h"
+#include "object/ObjectList.h"
+#include "object/ObjectListBase.h"
#include "Super.h"
namespace orxonox
Deleted: code/branches/core6/src/libraries/core/Iterator.h
===================================================================
--- code/branches/core6/src/libraries/core/Iterator.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/Iterator.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,311 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @ingroup Object ObjectList
- @brief Definition of the Iterator class, used to iterate through object-lists.
-
- @anchor IteratorExample
-
- @ref orxonox::Iterator "Iterator" allows to iterate through an @ref orxonox::ObjectListBase
- "ObjectListBase". Objects in this list are cast to the template argument @a T of Iterator<T> using
- @c dynamic_cast. In contrast to @ref orxonox::ObjectListIterator "ObjectListIterator<T>",
- @ref orxonox::Iterator "Iterator<T>" can iterate through every object-list. In practice though it
- is limited to objects of type @a T and its subclasses. Because of the @c dynamic_cast, this iterator
- is much slower than ObjectListIterator.
-
- Usage:
- @code
- for (Iterator<myClass> it = anyidentifier->getObjects()->begin(); it != anyidentifier->getObjects()->end(); ++it)
- {
- it->someFunction(...);
- myClass* myObject = *it;
- }
- @endcode
-*/
-
-#ifndef _Iterator_H__
-#define _Iterator_H__
-
-#include "CorePrereqs.h"
-
-#include "Identifier.h"
-#include "ObjectListBase.h"
-
-namespace orxonox
-{
- /**
- @brief The Iterator allows to iterate through a given ObjectList.
-
- Independent of the object-list's type, the objects in the list are always casted
- to @a T using @c dynamic_cast.
-
- @see See @ref IteratorExample "Iterator.h" for more information an example.
- */
- template <class T = OrxonoxClass>
- class Iterator
- {
- public:
- /**
- @brief Constructor: Sets the element, whereon the iterator points, to zero.
- */
- inline Iterator()
- {
- this->element_ = 0;
- this->list_ = 0;
- }
-
- /**
- @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);
- }
-
- /**
- @brief Constructor: Sets this element to a given element
- @param element The element
- */
- template <class O>
- inline Iterator(ObjectListElement<O>* element)
- {
- this->element_ = element;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
- }
-
- /**
- @brief Constructor: Sets this element to the element an ObjectListIterator.
- @param other The ObjectListIterator
- */
- template <class O>
- inline Iterator(const ObjectListIterator<O>& other)
- {
- this->element_ = other.element_;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
- }
-
- /**
- @brief Unregisters the Iterator from the ObjectList.
- */
- inline ~Iterator()
- {
- this->list_->unregisterIterator(this);
- }
-
- /**
- @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->element_ = other.element_;
- this->list_ = other.list_;
- this->list_->registerIterator(this);
-
- return (*this);
- }
-
- /**
- @brief Assigns a given element.
- @param element The element
- */
- template <class O>
- inline Iterator<T>& operator=(ObjectListElement<O>* element)
- {
- if (this->list_)
- this->list_->unregisterIterator(this);
-
- this->element_ = element;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
-
- return (*this);
- }
-
- /**
- @brief Assigns the element of an ObjectListIterator.
- @param other The ObjectListIterator
- */
- template <class O>
- inline Iterator<T>& operator=(const ObjectListIterator<O>& other)
- {
- if (this->list_)
- this->list_->unregisterIterator(this);
-
- this->element_ = other.element_;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
-
- return (*this);
- }
-
- /**
- @brief Overloading of the ++it operator: Iterator points to the next object in the list.
- @return The Iterator itself
- */
- inline const Iterator<T>& operator++()
- {
- this->element_ = this->element_->next_;
- return *this;
- }
-
- /**
- @brief Overloading of the it++ operator: Iterator points to the next object in the list.
- @return The Iterator itself
- */
- inline Iterator<T> operator++(int)
- {
- Iterator<T> copy = *this;
- this->element_ = this->element_->next_;
- return copy;
- }
-
- /**
- @brief Overloading of the --it operator: Iterator points to the previous object in the list.
- @return The Iterator itself
- */
- inline const Iterator<T>& operator--()
- {
- this->element_ = this->element_->prev_;
- return *this;
- }
-
- /**
- @brief Overloading of the it-- operator: Iterator points to the previous object in the list.
- @return The Iterator itself
- */
- inline Iterator<T> operator--(int i)
- {
- Iterator<T> copy = *this;
- this->element_ = this->element_->prev_;
- return copy;
- }
-
- /**
- @brief Overloading of the *it operator: returns the pointer to the object.
- @return The object the Iterator points at
- */
- inline T* operator*() const
- {
- return orxonox_cast<T*>(this->element_->objectBase_);
- }
-
- /**
- @brief Overloading of the it-> operator: returns the pointer to the object.
- @return The object the Iterator points at
- */
- inline T* operator->() const
- {
- return orxonox_cast<T*>(this->element_->objectBase_);
- }
-
- /**
- @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.
- @return True if the Iterator points to an existing object.
- */
- inline operator bool() const
- {
- return (this->element_ != 0);
- }
-
- /**
- @brief Overloading of the == operator to compare with another Iterator.
- @param compare The other Iterator
- @return True if the iterators point to the same element
- */
- inline bool operator==(const Iterator<T>& compare) const
- {
- return (this->element_ == compare.element_);
- }
-
- /**
- @brief Overloading of the != operator to compare with another Iterator.
- @param compare The other Iterator
- @return True if the iterators point to different elements
- */
- inline bool operator!=(const Iterator<T>& compare) const
- {
- return (this->element_ != compare.element_);
- }
-
- /**
- @brief Increments the Iterator if it points at the given object.
- @param object The object to compare with
- */
- inline void incrementIfEqual(OrxonoxClass* object)
- {
- if (this->element_ && this->element_->objectBase_ == object)
- this->operator++();
- }
-
- protected:
- ObjectListBaseElement* element_; //!< The element the Iterator points at
- ObjectListBase* list_; //!< The list wherein the element is
- };
-
- typedef Iterator<OrxonoxClass> BaseIterator;
-}
-
-#endif /* _Iterator_H__ */
Modified: code/branches/core6/src/libraries/core/Loader.cc
===================================================================
--- code/branches/core6/src/libraries/core/Loader.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/Loader.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -36,12 +36,12 @@
#include "util/Exception.h"
#include "util/StringUtils.h"
#include "BaseObject.h"
-#include "Iterator.h"
-#include "ObjectList.h"
#include "LuaState.h"
#include "Namespace.h"
#include "Resource.h"
#include "XMLFile.h"
+#include "object/Iterator.h"
+#include "object/ObjectList.h"
namespace orxonox
{
Deleted: code/branches/core6/src/libraries/core/MetaObjectList.cc
===================================================================
--- code/branches/core6/src/libraries/core/MetaObjectList.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/MetaObjectList.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,103 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the MetaObjectList class.
-*/
-
-#include "MetaObjectList.h"
-
-#include "util/Output.h"
-#include "Identifier.h"
-#include "ObjectListBase.h"
-
-namespace orxonox
-{
- // ###############################
- // ### MetaObjectListElement ###
- // ###############################
- /**
- @brief Destructor: Removes the ObjectListBaseElement from the ObjectListBase by linking next_ and prev_ of the ObjectListBaseElement.
- */
- MetaObjectListElement::~MetaObjectListElement()
- {
- orxout(verbose, context::object_list) << "Removing Object from " << this->list_->getIdentifier()->getName() << "-list." << endl;
- this->list_->notifyIterators(this->element_->objectBase_);
-
- if (this->element_->next_)
- this->element_->next_->prev_ = this->element_->prev_;
- else
- this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list
-
- if (this->element_->prev_)
- this->element_->prev_->next_ = this->element_->next_;
- else
- this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list
-
- delete this->element_;
- }
-
-
- // ###############################
- // ### MetaObjectList ###
- // ###############################
- /**
- @brief Constructor: Sets first_ to zero.
- */
- MetaObjectList::MetaObjectList()
- {
- this->first_ = 0;
- }
-
- /**
- @brief Destructor: Removes all elements from the list, causing them to remove the stored ObjectListElement from the ObjectList.
- */
- MetaObjectList::~MetaObjectList()
- {
- MetaObjectListElement* temp;
- while (this->first_)
- {
- temp = this->first_->next_;
- delete this->first_;
- this->first_ = temp;
- }
- }
-
- /**
- @brief Adds an ObjectList and an element of that list to the MetaObjectList.
- @param list The ObjectList wherein the element is
- @param element The element wherein the object is
- */
- void MetaObjectList::add(ObjectListBase* list, ObjectListBaseElement* element)
- {
- MetaObjectListElement* temp = this->first_;
- this->first_ = new MetaObjectListElement(list, element);
- this->first_->next_ = temp;
- }
-}
Deleted: code/branches/core6/src/libraries/core/MetaObjectList.h
===================================================================
--- code/branches/core6/src/libraries/core/MetaObjectList.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/MetaObjectList.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,86 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @ingroup Object ObjectList
- @brief Declaration of the MetaObjectList class.
-
- The MetaObjectList is a single-linked list, containing all list-elements and their
- lists wherein the object, owning the MetaObjectList, is registered.
- This allows much faster deletion of objects because no iteration is needed.
-*/
-
-#ifndef _MetaObjectList_H__
-#define _MetaObjectList_H__
-
-#include "CorePrereqs.h"
-
-namespace orxonox
-{
- // ###############################
- // ### MetaObjectListElement ###
- // ###############################
- /// The list-element of the MetaObjectList
- class _CoreExport MetaObjectListElement
- {
- public:
- /**
- @brief Constructor: Creates the list-element with given list and element.
- */
- MetaObjectListElement(ObjectListBase* list, ObjectListBaseElement* element) : next_(0), element_(element), list_(list) {}
- ~MetaObjectListElement();
-
- MetaObjectListElement* next_; //!< The next Element in the list
- ObjectListBaseElement* element_; //!< The list element, containing the object
- ObjectListBase* list_; //!< The list, containing the element
- };
-
-
- // ###############################
- // ### MetaObjectList ###
- // ###############################
- /**
- @brief The MetaObjectList contains ObjectListBaseElements and their ObjectListBases.
-
- The MetaObjectList is a single-linked list, containing all list-elements and their
- lists wherein the object that owns the MetaObjectList is registered.
- This allows much faster deletion of objects because no iteration is needed.
- */
- class _CoreExport MetaObjectList
- {
- public:
- MetaObjectList();
- ~MetaObjectList();
- void add(ObjectListBase* list, ObjectListBaseElement* element);
-
- MetaObjectListElement* first_; //!< The first element in the list
- };
-}
-
-#endif /* _MetaObjectList_H__ */
Deleted: code/branches/core6/src/libraries/core/ObjectList.h
===================================================================
--- code/branches/core6/src/libraries/core/ObjectList.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/ObjectList.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,101 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @defgroup ObjectList Object-lists and iterators
- @ingroup Object
-*/
-
-/**
- @file
- @ingroup Object ObjectList
- @brief Definition of the ObjectList class, a wrapper of ObjectListBase.
-
- @ref orxonox::ObjectList "ObjectList<T>" is a wrapper of an @ref orxonox::ObjectListBase
- "ObjectListBase" of class @a T. Use @ref orxonox::ObjectListIterator "ObjectListIterator<T>"
- to iterate through the list.
-*/
-
-#ifndef _ObjectList_H__
-#define _ObjectList_H__
-
-#include "CorePrereqs.h"
-
-#include "Identifier.h"
-#include "ObjectListBase.h"
-#include "ObjectListIterator.h"
-
-namespace orxonox
-{
- // ###############################
- // ### ObjectList ###
- // ###############################
- /**
- @brief The ObjectList contains all objects of the given class.
-
- Wraps the ObjectListBase which contains all objects of type @a T. Use @ref ObjectListIterator
- "ObjectListIterator<T>" or its typedef ObjectList<T>::iterator to iterate through all objects
- in the list.
- */
- template <class T>
- class ObjectList
- {
- public:
- typedef ObjectListIterator<T> iterator;
-
- /// Returns an Iterator to the first element in the list.
- inline static ObjectListElement<T>* begin()
- {
- ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
- return static_cast<ObjectListElement<T>*>(list->begin().element_);
- }
-
- /// 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_);
- }
-
- /// 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_);
- }
-
- /// 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_);
- }
- };
-}
-
-#endif /* _ObjectList_H__ */
Deleted: code/branches/core6/src/libraries/core/ObjectListBase.cc
===================================================================
--- code/branches/core6/src/libraries/core/ObjectListBase.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/ObjectListBase.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,103 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the ObjectListBase class.
-*/
-
-#include "ObjectListBase.h"
-
-#include <set>
-#include "Identifier.h"
-#include "Iterator.h"
-#include "ObjectListIterator.h"
-
-namespace orxonox
-{
- /**
- @brief Constructor: Sets default values.
- */
- ObjectListBase::ObjectListBase(Identifier* identifier)
- {
- this->identifier_ = identifier;
- this->first_ = 0;
- this->last_ = 0;
- }
-
- /**
- @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS.
- */
- ObjectListBase::~ObjectListBase()
- {
- ObjectListBaseElement* temp;
- while (this->first_)
- {
- temp = this->first_->next_;
- delete this->first_;
- this->first_ = temp;
- }
- }
-
- /**
- @brief Increases all Iterators that currently point on the given element (because it gets removed).
- @param object The object that gets removed
- */
- void ObjectListBase::notifyIterators(OrxonoxClass* object) const
- {
- for (std::vector<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)
- ((Iterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
- for (std::vector<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it)
- ((ObjectListIterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
- }
-
- /**
- @brief Adds a new object to the end of the list.
- @param element The element to add
- @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object
- */
- ObjectListBaseElement* ObjectListBase::add(ObjectListBaseElement* element)
- {
- if (!this->last_)
- {
- // If the list is empty
- this->last_ = element;
- this->first_ = this->last_; // There's only one object in the list now
- }
- else
- {
- // If the list isn't empty
- ObjectListBaseElement* temp = this->last_;
- this->last_ = element;
- this->last_->prev_ = temp;
- temp->next_ = this->last_;
- }
-
- return this->last_;
- }
-}
Deleted: code/branches/core6/src/libraries/core/ObjectListBase.h
===================================================================
--- code/branches/core6/src/libraries/core/ObjectListBase.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/ObjectListBase.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,157 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @ingroup Object ObjectList
- @brief Declaration of the ObjectListBase class which stores all objects of each class.
-
- orxonox::ObjectListBase is a double-linked list, used by @ref orxonox::Identifier "Identifiers"
- to store all objects of a given class. Newly created objects are added to the list through the
- @c RegisterObject() macro in the constructor.
-*/
-
-#ifndef _ObjectListBase_H__
-#define _ObjectListBase_H__
-
-#include "CorePrereqs.h"
-#include <vector>
-
-namespace orxonox
-{
- // ###############################
- // ### ObjectListBaseElement ###
- // ###############################
- /// The list-element of the ObjectListBase
- class _CoreExport ObjectListBaseElement
- {
- public:
- /**
- @brief Constructor: Creates the list-element with an object.
- @param objectBase The object to store
- */
- ObjectListBaseElement(OrxonoxClass* objectBase) : next_(0), prev_(0), objectBase_(objectBase) {}
-
- ObjectListBaseElement* next_; //!< The next element in the list
- ObjectListBaseElement* prev_; //!< The previous element in the list
- OrxonoxClass* objectBase_;
- };
-
-
- // ###############################
- // ### ObjectListElement ###
- // ###############################
- /// The list-element that actually contains the object
- template <class T>
- class ObjectListElement : public ObjectListBaseElement
- {
- public:
- ObjectListElement(T* object) : ObjectListBaseElement(static_cast<OrxonoxClass*>(object)), object_(object) {}
- T* object_; //!< The object
- };
-
-
- // ###############################
- // ### ObjectListBase ###
- // ###############################
- /**
- @brief The ObjectListBase contains all objects of a given class.
-
- The ObjectListBase is used by Identifiers to store all objects of their class.
- You can use Identifier::getObjects() to get the object-list from an Identifier.
- Use @ref Iterator "Iterator<T>" to iterate through them.
-
- Alternatively you can also use the static helper class @ref orxonox::ObjectList "ObjectList<T>"
- to get the list of all objects of type @a T. Use @ref ObjectListIterator "ObjectListIterator<T>"
- or @ref Iterator "Iterator<T>" to iterate through them.
- */
- class _CoreExport ObjectListBase
- {
- friend class MetaObjectListElement;
-
- public:
- ObjectListBase(Identifier* identifier);
- ~ObjectListBase();
-
- ObjectListBaseElement* add(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_); }
- /// 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); }
- /// Returns a pointer to the last element in the list. Works only with Iterator.
- inline Export rbegin() { return ObjectListBase::Export(this, 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 void registerIterator(void* iterator) { this->iterators_.push_back(iterator); }
- inline void unregisterIterator(void* iterator)
- {
- for (unsigned int i = 0; i < this->iterators_.size(); ++i)
- {
- if (iterators_[i] == iterator)
- {
- iterators_.erase(iterators_.begin() + i);
- break;
- }
- }
- }
- inline void registerObjectListIterator(void* iterator) { this->objectListIterators_.push_back(iterator); }
- inline void unregisterObjectListIterator(void* iterator)
- {
- for (unsigned int i = 0; i < this->objectListIterators_.size(); ++i)
- {
- if (objectListIterators_[i] == iterator)
- {
- objectListIterators_.erase(objectListIterators_.begin() + i);
- break;
- }
- }
- }
- void notifyIterators(OrxonoxClass* object) const;
-
- inline Identifier* getIdentifier() const { return this->identifier_; }
-
- private:
- Identifier* identifier_; //!< The Iterator owning this list
- ObjectListBaseElement* first_; //!< The first element in the list
- ObjectListBaseElement* last_; //!< The last element in the list
- std::vector<void*> iterators_; //!< A list of Iterators pointing on an element in this list
- std::vector<void*> objectListIterators_; //!< A list of ObjectListIterators pointing on an element in this list
- };
-}
-
-#endif /* _ObjectListBase_H__ */
Deleted: code/branches/core6/src/libraries/core/ObjectListIterator.h
===================================================================
--- code/branches/core6/src/libraries/core/ObjectListIterator.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/ObjectListIterator.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,236 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @ingroup Object ObjectList
- @brief Definition of the ObjectListIterator class, used to iterate through object-lists.
-
- @anchor ObjectListIteratorExample
-
- @ref orxonox::ObjectListIterator "ObjectListIterator<T>" allows to iterate through
- @ref orxonox::ObjectList "ObjectList<T>", containing all objects of type @a T. In contrast to
- @ref orxonox::Iterator "Iterator<T>", this iterator is limited to the object-list of type @a T.
- It is, however, much faster as it doesn't need a @c dynamic_cast.
-
- Usage:
- @code
- for (ObjectListIterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it)
- {
- it->someFunction(...);
- myClass* myObject = *it;
- }
- @endcode
-
- @note @ref orxonox::ObjectList::iterator "ObjectList<T>::iterator" is identical to
- @ref orxonox::ObjectListIterator "ObjectListIterator<T>" (it's just a typedef).
-*/
-
-#ifndef _ObjectListIterator_H__
-#define _ObjectListIterator_H__
-
-#include "CorePrereqs.h"
-#include "Identifier.h"
-#include "ObjectList.h"
-
-namespace orxonox
-{
- /**
- @brief ObjectListIterator<T> allows to iterate through the ObjectList of class @a T.
-
- @see See @ref ObjectListIteratorExample "ObjectListIterator.h" for more information an example.
- */
- template <class T>
- class ObjectListIterator
- {
- template <class I>
- friend class Iterator;
-
- public:
- /**
- @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero.
- */
- inline ObjectListIterator()
- {
- this->element_ = 0;
- ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
- }
-
- /**
- @brief Constructor: Sets this element to a given element.
- @param element The element to start with
- */
- inline ObjectListIterator(ObjectListElement<T>* element)
- {
- this->element_ = element;
- ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
- }
-
- /**
- @brief Constructor: Sets this element to the element of another ObjectListIterator.
- @param other The other ObjectListIterator
- */
- inline ObjectListIterator(const ObjectListIterator<T>& other)
- {
- this->element_ = other.element_;
- ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
- }
-
- /**
- @brief Unregisters the ObjectListIterator from the ObjectList.
- */
- inline ~ObjectListIterator()
- {
- ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterObjectListIterator(this);
- }
-
- /**
- @brief Assigns an ObjectListElement.
- @param element The ObjectListElement
- */
- inline ObjectListIterator<T>& operator=(ObjectListElement<T>* element)
- {
- this->element_ = element;
- return (*this);
- }
-
- /**
- @brief Assigns the element of another ObjectListIterator.
- @param other The other ObjectListIterator
- */
- inline ObjectListIterator<T>& operator=(const ObjectListIterator<T>& other)
- {
- this->element_ = other.element_;
- return (*this);
- }
-
- /**
- @brief Overloading of the ++it operator: ObjectListIterator points to the next object in the list.
- @return The ObjectListIterator itself
- */
- inline const ObjectListIterator<T>& operator++()
- {
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
- return *this;
- }
-
- /**
- @brief Overloading of the it++ operator: ObjectListIterator points to the next object in the list.
- @return The ObjectListIterator itself
- */
- inline ObjectListIterator<T> operator++(int)
- {
- ObjectListIterator<T> copy = *this;
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
- return copy;
- }
-
- /**
- @brief Overloading of the --it operator: ObjectListIterator points to the previous object in the list.
- @return The ObjectListIterator itself
- */
- inline const ObjectListIterator<T>& operator--()
- {
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
- return *this;
- }
-
- /**
- @brief Overloading of the it-- operator: ObjectListIterator points to the previous object in the list.
- @return The ObjectListIterator itself
- */
- inline ObjectListIterator<T> operator--(int i)
- {
- ObjectListIterator<T> copy = *this;
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
- return copy;
- }
-
- /**
- @brief Overloading of the *it operator: returns the pointer to the object.
- @return The object the ObjectListIterator points at
- */
- inline T* operator*() const
- {
- return this->element_->object_;
- }
-
- /**
- @brief Overloading of the it-> operator: returns the pointer to the object.
- @return The object the ObjectListIterator points at
- */
- inline T* operator->() const
- {
- return this->element_->object_;
- }
-
- /**
- @brief Overloading of the typecast-operator to bool: returns true if the ObjectListIterator points to an existing object.
- @return True if the ObjectListIterator points to an existing object.
- */
- inline operator bool() const
- {
- return (this->element_ != 0);
- }
-
- /**
- @brief Overloading of the == operator to compare with another ObjectListIterator.
- @param compare The other ObjectListIterator
- @return True if the ObjectListIterator point to the same element
- */
- inline bool operator==(const ObjectListIterator<T>& compare) const
- {
- return (this->element_ == compare.element_);
- }
-
- /**
- @brief Overloading of the != operator to compare with another ObjectListIterator.
- @param compare The other ObjectListIterator
- @return True if the ObjectListIterator point to different elements
- */
- inline bool operator!=(const ObjectListIterator<T>& compare) const
- {
- return (this->element_ != compare.element_);
- }
-
- /**
- @brief Increments the ObjectListIterator if it points at the given object.
- @param object The object to compare with
- */
- inline void incrementIfEqual(OrxonoxClass* object)
- {
- if (this->element_ && this->element_->objectBase_ == object)
- this->operator++();
- }
-
- private:
- ObjectListElement<T>* element_; //!< The element the iterator points at
- };
-}
-
-#endif /* _ObjectListIterator_H__ */
Modified: code/branches/core6/src/libraries/core/OrxonoxClass.cc
===================================================================
--- code/branches/core6/src/libraries/core/OrxonoxClass.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/OrxonoxClass.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -34,7 +34,7 @@
#include "OrxonoxClass.h"
#include <cassert>
-#include "MetaObjectList.h"
+#include "object/MetaObjectList.h"
#include "Identifier.h"
namespace orxonox
Deleted: code/branches/core6/src/libraries/core/SmartPtr.h
===================================================================
--- code/branches/core6/src/libraries/core/SmartPtr.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/SmartPtr.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,317 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-// Inspired by boost::intrusive_ptr by Peter Dimov
-
-/**
- @defgroup SmartPtr SmartPtr<T> and WeakPtr<T>
- @ingroup Object
-*/
-
-/**
- @file
- @ingroup Object SmartPtr
- @brief Definition of SmartPtr<T>, wraps a pointer to an object and keeps it alive.
-
- @anchor SmartPtrExample
-
- orxonox::SmartPtr is an implementation of a smart pointer - it wraps a pointer to an
- object and keeps this object alive until no SmartPtr points to this object anymore.
- In contrast to orxonox::SharedPtr, SmartPtr works only with classes that are derived
- from orxonox::OrxonoxClass, because it's an intrusive implementation, meaning the
- reference counter is stored in the object itself.
-
- It's possible to use normal pointers and smart pointers to an object simultaneously.
- You don't have to use SmartPtr all the time, you can create a SmartPtr for an object
- at any time and also convert it back to a normal pointer if you like. This is possible
- because the reference counter is stored in the object itself and not in SmartPtr (in
- contrast to SharedPtr).
-
- @b Important: If you want to delete an object, you must not use @c delete @c object but
- rather @c object->destroy(). This function will check if there are smart pointers
- pointing to the object. If yes, the object will be kept alive until all smart pointes
- are destroyed. If no, the object is deleted instantly.
-
- If all smart pointers that point to an object are destroyed, but you never called
- @c object->destroy() before, the object will not be deleted! All a SmartPtr will do
- is to really just keep an object alive, but it will not delete it automatically
- unless you tried to destroy it before.
-
- Example:
- @code
- class MyClass // class declaration
- {
- public:
- void setObject(OtherClass* object) // passes a normal pointer which will be stored in a SmartPtr
- { this->object_ = object; }
-
- OtherClass* getObject() const // converts the SmartPtr to a normal pointer and returns it
- { return this->object_; }
-
- private:
- SmartPtr<OtherClass> object_; // a pointer to an instance of OtherClass is stored in a SmartPtr
- };
- @endcode
- In this example we assume that OtherClass is a child of OrxonoxClass. We don't care
- about the inheritance of MyClass though.
-
- Now we create an instance of MyClass and assign a pointer to an instance of OtherClass:
- @code
- MyClass* myclass = new MyClass(); // create an instance of MyClass
- OtherClass* object = new OtherClass(); // create an instance of OtherClass
- myclass->setObject(object); // the object is now stored in a SmartPtr inside myclass
-
- object->destroy(); // we try to destroy object, but there's still a SmartPtr pointing at it.
-
- # object still exists at this point (because a SmartPtr points at it)
-
- delete myclass; // now we delete myclass, which also destroys the SmartPtr
-
- # object doesn't exist anymore (because the SmartPtr is now destroyed)
- @endcode
-
- Now we look at the same example, but we first delete myclass, then destroy object:
- @code
- MyClass* myclass = new MyClass(); // create an instance of MyClass
- OtherClass* object = new OtherClass(); // create an instance of OtherClass
- myclass->setObject(object); // the object is now stored in a SmartPtr inside myclass
-
- delete myclass; // we delete myclass, which also destroys the SmartPtr
-
- # object still exists at this point (because destroy() was not called yet)
-
- object->destroy(); // now we try to destroy object, which works instantly
-
- # object doesn't exist anymore (because we just destroyed it)
- @endcode
-
- Note that in any case @c object->destroy() has to be called to delete the object.
- However if a SmartPtr points at it, the destruction is delayed until all SmartPtr
- are destroyed.
-*/
-
-#ifndef _SmartPtr_H__
-#define _SmartPtr_H__
-
-#include "CorePrereqs.h"
-
-#include <cassert>
-
-#include "Identifier.h"
-#include "OrxonoxClass.h"
-#include "WeakPtr.h"
-
-namespace orxonox
-{
- /**
- @brief A smart pointer which wraps a pointer to an object and keeps this object alive as long as the smart pointer exists.
-
- @see See @ref SmartPtrExample "this description" for more information and an example.
- */
- template <class T>
- class SmartPtr
- {
- public:
- /// Constructor: Initializes the smart pointer with a null pointer.
- inline SmartPtr() : pointer_(0), base_(0)
- {
- }
-
- /// Constructor: Used to explicitly initialize the smart pointer with a null pointer
- inline SmartPtr(int) : pointer_(0), base_(0)
- {
- }
-
- /// Constructor: Initializes the smart pointer with a pointer to an object. @param pointer The pointer @param bAddRef If true, the reference counter is increased. Don't set this to false unless you know exactly what you're doing! (for example to avoid circular references if the @c this pointer of the possessing object is stored)
- inline SmartPtr(T* pointer, bool bAddRef = true) : pointer_(pointer), base_(pointer)
- {
- if (this->base_ && bAddRef)
- this->base_->incrementReferenceCount();
- }
-
- /// Copy-constructor
- inline SmartPtr(const SmartPtr& other) : pointer_(other.pointer_), base_(other.base_)
- {
- if (this->base_)
- this->base_->incrementReferenceCount();
- }
-
- /// Copy-constructor for smart pointers to objects of another class.
- template <class O>
- inline SmartPtr(const SmartPtr<O>& other) : pointer_(other.get()), base_(other.base_)
- {
- if (this->base_)
- this->base_->incrementReferenceCount();
- }
-
- /// Constructor: Initializes the smart pointer with the pointer that is stored in a WeakPtr.
- template <class O>
- inline SmartPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.getBase())
- {
- if (this->base_)
- this->base_->incrementReferenceCount();
- }
-
- /// Destructor: Decrements the reference counter.
- inline ~SmartPtr()
- {
- if (this->base_)
- this->base_->decrementReferenceCount();
- }
-
- /// Used to assign a null pointer.
- inline SmartPtr& operator=(int)
- {
- SmartPtr(0).swap(*this);
- return *this;
- }
-
- /// Assigns a new pointer.
- inline SmartPtr& operator=(T* pointer)
- {
- SmartPtr(pointer).swap(*this);
- return *this;
- }
-
- /// Assigns the wrapped pointer of another SmartPtr.
- inline SmartPtr& operator=(const SmartPtr& other)
- {
- SmartPtr(other).swap(*this);
- return *this;
- }
-
- /// Assigns the wrapped pointer of a SmartPtr of another class
- template <class O>
- inline SmartPtr& operator=(const SmartPtr<O>& other)
- {
- SmartPtr(other).swap(*this);
- return *this;
- }
-
- /// Assigns the wrapped pointer of a WeakPtr.
- template <class O>
- inline SmartPtr& operator=(const WeakPtr<O>& other)
- {
- SmartPtr(other).swap(*this);
- return *this;
- }
-
- /// Returns the wrapped pointer as @c T*
- inline T* get() const
- {
- return this->pointer_;
- }
-
- /// Returns the wrapped pointer as @c OrxonoxClass*
- inline OrxonoxClass* getBase() const
- {
- return this->base_;
- }
-
- /// Implicitly converts the SmartPtr to a pointer of type @c T*
- inline operator T*() const
- {
- return this->pointer_;
- }
-
- /// Overloaded operator, returns a pointer to the stored object.
- inline T* operator->() const
- {
- assert(this->pointer_ != 0);
- return this->pointer_;
- }
-
- /// Overloaded operator, returns a reference to the stored object.
- inline T& operator*() const
- {
- assert(this->pointer_ != 0);
- return *this->pointer_;
- }
-
- /// Returns true if the wrapped pointer is NULL.
- inline bool operator!() const
- {
- return (this->pointer_ == 0);
- }
-
- /// Swaps the contents of two smart pointers.
- inline void swap(SmartPtr& other)
- {
- {
- T* temp = this->pointer_;
- this->pointer_ = other.pointer_;
- other.pointer_ = temp;
- }
- {
- OrxonoxClass* temp = this->base_;
- this->base_ = other.base_;
- other.base_ = temp;
- }
- }
-
- /// Resets the smart pointer (equivalent to assigning a NULL pointer).
- inline void reset()
- {
- SmartPtr().swap(*this);
- }
-
- private:
- T* pointer_; ///< The wrapped pointer to an object of type @a T
- OrxonoxClass* base_; ///< The wrapped pointer, casted up to OrxonoxClass (this is needed because with just a T* pointer, SmartPtr couln't be used with forward declarations)
- };
-
- /// Swaps the contents of two smart pointers.
- template <class T>
- void swap(SmartPtr<T>& a, SmartPtr<T>& b)
- {
- a.swap(b);
- }
-
- /// Uses a static_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>.
- template <class T, class U>
- SmartPtr<T> static_pointer_cast(const SmartPtr<U>& p)
- {
- return static_cast<T*>(p.get());
- }
-
- /// Uses a const_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>.
- template <class T, class U>
- SmartPtr<T> const_pointer_cast(const SmartPtr<U>& p)
- {
- return const_cast<T*>(p.get());
- }
-
- /// Uses a dynamic_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>.
- template <class T, class U>
- SmartPtr<T> dynamic_pointer_cast(const SmartPtr<U>& p)
- {
- return orxonox_cast<T*>(p.get());
- }
-}
-
-#endif /* _SmartPtr_H__ */
Deleted: code/branches/core6/src/libraries/core/WeakPtr.h
===================================================================
--- code/branches/core6/src/libraries/core/WeakPtr.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/WeakPtr.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -1,286 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-// Inspired by boost::intrusive_ptr by Peter Dimov
-
-/**
- @file
- @ingroup Object SmartPtr
- @brief Definition of WeakPtr<T>, wraps a pointer to an object.
-
- @anchor WeakPtrExample
-
- A WeakPtr wraps a pointer to an object. If the object gets deleted, the WeakPtr becomes
- NULL. This can be used to store pointers to objects without knowing when they will be
- destroyed.
-
- WeakPtr works only with objects that are derived from orxonox::OrxonoxClass, because
- WeakPtr is intrusive and registers itself in the stored object, to get a notification if
- the object is being deleted.
-
- Example:
- @code
- MyClass* object = new MyClass(); // create an instance of MyClass
-
- WeakPtr<MyClass> pointer = object; // create a WeakPtr and assign the object
-
- if (pointer) // checks if pointer is not NULL (which is true)
- pointer->someFunction(); // calls MyClass::someFunction()
-
- object->destroy(); // calls destroy() which deletes the object
-
- if (pointer) // checks if pointer is not NULL (which is now false)
- pointer->someFunction(); // this will not be executed
- @endcode
- In this example we assumed that MyClass is derived of OrxonoxClass (otherwise it couldn't
- be used with a WeakPtr).
-
- A callback can be registerd with the WeakPtr that will be called if the object gets deleted.
- @code
- void myCallback() // definition of the callback function
- {
- orxout() << "Object destroyed" << endl;
- }
-
- MyClass* object = new MyClass(); // create an instance of MyClass
-
- WeakPtr<MyClass> pointer = object; // create a WeakPtr and assign the object
-
- pointer.setCallback(createFunctor(&myCallback)); // defines a callback
-
- object->destroy(); // calls destroy() which deletes the object. prints "Object destroyed" to the console
- @endcode
-*/
-
-#ifndef _WeakPtr_H__
-#define _WeakPtr_H__
-
-#include "CorePrereqs.h"
-
-#include <cassert>
-#include "Identifier.h"
-#include "OrxonoxClass.h"
-#include "command/Functor.h"
-
-namespace orxonox
-{
- /**
- @brief WeakPtr wraps a pointer to an object, which becomes NULL if the object is deleted.
-
- @see See @ref WeakPtrExample "this description" for more information and an example.
- */
- template <class T>
- class WeakPtr : public DestructionListener
- {
- public:
- /// Constructor: Initializes the weak pointer with a null pointer.
- inline WeakPtr() : pointer_(0), base_(0), callback_(0)
- {
- }
-
- /// Constructor: Used to explicitly initialize the weak pointer with a null pointer
- inline WeakPtr(int) : pointer_(0), base_(0), callback_(0)
- {
- }
-
- /// Constructor: Initializes the weak pointer with a pointer to an object.
- inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(0)
- {
- this->registerAsDestructionListener(this->base_);
- }
-
- /// Copy-constructor
- inline WeakPtr(const WeakPtr& other) : pointer_(other.pointer_), base_(other.base_), callback_(0)
- {
- this->registerAsDestructionListener(this->base_);
- }
-
- /// Copy-constructor for weak pointers to objects of another class.
- template <class O>
- inline WeakPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.base_), callback_(0)
- {
- this->registerAsDestructionListener(this->base_);
- }
-
- /// Destructor
- inline virtual ~WeakPtr()
- {
- this->unregisterAsDestructionListener(this->base_);
- }
-
- /// Used to assign a null pointer.
- inline WeakPtr& operator=(int)
- {
- WeakPtr(0).swap(*this);
- return *this;
- }
-
- /// Assigns a new pointer.
- inline WeakPtr& operator=(T* pointer)
- {
- WeakPtr(pointer).swap(*this);
- return *this;
- }
-
- /// Assigns the wrapped pointer of another WeakPtr.
- inline WeakPtr& operator=(const WeakPtr& other)
- {
- WeakPtr(other).swap(*this);
- return *this;
- }
-
- /// Assigns the wrapped pointer of a WeakPtr of another class
- template <class O>
- inline WeakPtr& operator=(const WeakPtr<O>& other)
- {
- WeakPtr(other).swap(*this);
- return *this;
- }
-
- /// Returns the wrapped pointer as @c T*
- inline T* get() const
- {
- return this->pointer_;
- }
-
- /// Returns the wrapped pointer as @c OrxonoxClass*
- inline OrxonoxClass* getBase() const
- {
- return this->base_;
- }
-
- /// Implicitly converts the WeakPtr to a pointer of type @c T*
- inline operator T*() const
- {
- return this->pointer_;
- }
-
- /// Overloaded operator, returns a pointer to the stored object.
- inline T* operator->() const
- {
- assert(this->pointer_ != 0);
- return this->pointer_;
- }
-
- /// Overloaded operator, returns a reference to the stored object.
- inline T& operator*() const
- {
- assert(this->pointer_ != 0);
- return *this->pointer_;
- }
-
- /// Returns true if the wrapped pointer is NULL.
- inline bool operator!() const
- {
- return (this->pointer_ == 0);
- }
-
- /// Swaps the contents of two weak pointers.
- inline void swap(WeakPtr& other)
- {
- this->unregisterAsDestructionListener(this->base_);
- other.unregisterAsDestructionListener(other.base_);
-
- {
- T* temp = this->pointer_;
- this->pointer_ = other.pointer_;
- other.pointer_ = temp;
- }
- {
- OrxonoxClass* temp = this->base_;
- this->base_ = other.base_;
- other.base_ = temp;
- }
-
- this->registerAsDestructionListener(this->base_);
- other.registerAsDestructionListener(other.base_);
- }
-
- /// Resets the weak pointer (equivalent to assigning a NULL pointer).
- inline void reset()
- {
- WeakPtr().swap(*this);
- }
-
- /// Registers a callback that will be executed if the stored object is destroyed.
- inline void setCallback(const FunctorPtr& callback)
- {
- this->callback_ = callback;
- }
-
- /// Returns the registered callback.
- inline const FunctorPtr& getCallback() const
- {
- return this->callback_;
- }
-
- private:
- /// Will be called by OrxonoxClass::~OrxonoxClass() if the stored object is deleted. Resets the wrapped pointer and executes the callback.
- inline void objectDeleted()
- {
- this->base_ = 0;
- this->pointer_ = 0;
- if (this->callback_)
- (*this->callback_)();
- }
-
- T* pointer_; ///< The wrapped pointer to an object of type @a T
- OrxonoxClass* base_; ///< The wrapped pointer, casted up to OrxonoxClass (this is needed because with just a T* pointer, WeakPtr couln't be used with forward declarations)
- FunctorPtr callback_; ///< This callback will be executed if the stored object is deleted
- };
-
- /// Swaps the contents of two weak pointers.
- template <class T>
- void swap(WeakPtr<T>& a, WeakPtr<T>& b)
- {
- a.swap(b);
- }
-
- /// Uses a static_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>.
- template <class T, class U>
- WeakPtr<T> static_pointer_cast(const WeakPtr<U>& p)
- {
- return static_cast<T*>(p.get());
- }
-
- /// Uses a const_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>.
- template <class T, class U>
- WeakPtr<T> const_pointer_cast(const WeakPtr<U>& p)
- {
- return const_cast<T*>(p.get());
- }
-
- /// Uses a dynamic_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>.
- template <class T, class U>
- WeakPtr<T> dynamic_pointer_cast(const WeakPtr<U>& p)
- {
- return orxonox_cast<T*>(p.get());
- }
-}
-
-#endif /* _WeakPtr_H__ */
Modified: code/branches/core6/src/libraries/core/input/JoyStickQuantityListener.cc
===================================================================
--- code/branches/core6/src/libraries/core/input/JoyStickQuantityListener.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/core/input/JoyStickQuantityListener.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -29,7 +29,7 @@
#include "JoyStickQuantityListener.h"
#include "core/CoreIncludes.h"
-#include "core/ObjectList.h"
+#include "core/object/ObjectList.h"
namespace orxonox
{
Added: code/branches/core6/src/libraries/core/object/CMakeLists.txt
===================================================================
--- code/branches/core6/src/libraries/core/object/CMakeLists.txt (rev 0)
+++ code/branches/core6/src/libraries/core/object/CMakeLists.txt 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,4 @@
+ADD_SOURCE_FILES(CORE_SRC_FILES
+ MetaObjectList.cc
+ ObjectListBase.cc
+)
Property changes on: code/branches/core6/src/libraries/core/object/CMakeLists.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Copied: code/branches/core6/src/libraries/core/object/ClassFactory.h (from rev 9556, code/branches/core6/src/libraries/core/ClassFactory.h)
===================================================================
--- code/branches/core6/src/libraries/core/object/ClassFactory.h (rev 0)
+++ code/branches/core6/src/libraries/core/object/ClassFactory.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,91 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @ingroup Object Factory
+ @brief Definition and implementation of the ClassFactory class
+
+ The ClassFactory is able to create new objects of a specific class which creates objects.
+*/
+
+#ifndef _ClassFactory_H__
+#define _ClassFactory_H__
+
+#include "core/CorePrereqs.h"
+
+#include <string>
+
+#include "util/Output.h"
+#include "core/Identifier.h"
+
+namespace orxonox
+{
+ // ###########################
+ // ### Factory ###
+ // ###########################
+ /// Base-class of ClassFactory.
+ class _CoreExport Factory
+ {
+ public:
+ virtual ~Factory() {};
+ virtual OrxonoxClass* fabricate(BaseObject* creator) = 0;
+ };
+
+ // ###############################
+ // ### ClassFactory ###
+ // ###############################
+ /// The ClassFactory is able to create new objects of a specific class.
+ template <class T>
+ class ClassFactory : public Factory
+ {
+ public:
+ /**
+ @brief Constructor: Adds the ClassFactory to the Identifier of the same type.
+ @param name The name of the class
+ @param bLoadable True if the class can be loaded through XML
+ */
+ ClassFactory(const std::string& name, bool bLoadable = true)
+ {
+ orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;
+ ClassIdentifier<T>::getIdentifier(name)->addFactory(this);
+ ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
+ }
+
+ /**
+ @brief Creates and returns a new object of class T.
+ @return The new object
+ */
+ inline OrxonoxClass* fabricate(BaseObject* creator)
+ {
+ return static_cast<OrxonoxClass*>(new T(creator));
+ }
+ };
+}
+
+#endif /* _ClassFactory_H__ */
Copied: code/branches/core6/src/libraries/core/object/Iterator.h (from rev 9552, code/branches/core6/src/libraries/core/Iterator.h)
===================================================================
--- code/branches/core6/src/libraries/core/object/Iterator.h (rev 0)
+++ code/branches/core6/src/libraries/core/object/Iterator.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,311 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @ingroup Object ObjectList
+ @brief Definition of the Iterator class, used to iterate through object-lists.
+
+ @anchor IteratorExample
+
+ @ref orxonox::Iterator "Iterator" allows to iterate through an @ref orxonox::ObjectListBase
+ "ObjectListBase". Objects in this list are cast to the template argument @a T of Iterator<T> using
+ @c dynamic_cast. In contrast to @ref orxonox::ObjectListIterator "ObjectListIterator<T>",
+ @ref orxonox::Iterator "Iterator<T>" can iterate through every object-list. In practice though it
+ is limited to objects of type @a T and its subclasses. Because of the @c dynamic_cast, this iterator
+ is much slower than ObjectListIterator.
+
+ Usage:
+ @code
+ for (Iterator<myClass> it = anyidentifier->getObjects()->begin(); it != anyidentifier->getObjects()->end(); ++it)
+ {
+ it->someFunction(...);
+ myClass* myObject = *it;
+ }
+ @endcode
+*/
+
+#ifndef _Iterator_H__
+#define _Iterator_H__
+
+#include "core/CorePrereqs.h"
+
+#include "core/Identifier.h"
+#include "ObjectListBase.h"
+
+namespace orxonox
+{
+ /**
+ @brief The Iterator allows to iterate through a given ObjectList.
+
+ Independent of the object-list's type, the objects in the list are always casted
+ to @a T using @c dynamic_cast.
+
+ @see See @ref IteratorExample "Iterator.h" for more information an example.
+ */
+ template <class T = OrxonoxClass>
+ class Iterator
+ {
+ public:
+ /**
+ @brief Constructor: Sets the element, whereon the iterator points, to zero.
+ */
+ inline Iterator()
+ {
+ this->element_ = 0;
+ this->list_ = 0;
+ }
+
+ /**
+ @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);
+ }
+
+ /**
+ @brief Constructor: Sets this element to a given element
+ @param element The element
+ */
+ template <class O>
+ inline Iterator(ObjectListElement<O>* element)
+ {
+ this->element_ = element;
+ this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
+ this->list_->registerIterator(this);
+ }
+
+ /**
+ @brief Constructor: Sets this element to the element an ObjectListIterator.
+ @param other The ObjectListIterator
+ */
+ template <class O>
+ inline Iterator(const ObjectListIterator<O>& other)
+ {
+ this->element_ = other.element_;
+ this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
+ this->list_->registerIterator(this);
+ }
+
+ /**
+ @brief Unregisters the Iterator from the ObjectList.
+ */
+ inline ~Iterator()
+ {
+ this->list_->unregisterIterator(this);
+ }
+
+ /**
+ @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->element_ = other.element_;
+ this->list_ = other.list_;
+ this->list_->registerIterator(this);
+
+ return (*this);
+ }
+
+ /**
+ @brief Assigns a given element.
+ @param element The element
+ */
+ template <class O>
+ inline Iterator<T>& operator=(ObjectListElement<O>* element)
+ {
+ if (this->list_)
+ this->list_->unregisterIterator(this);
+
+ this->element_ = element;
+ this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
+ this->list_->registerIterator(this);
+
+ return (*this);
+ }
+
+ /**
+ @brief Assigns the element of an ObjectListIterator.
+ @param other The ObjectListIterator
+ */
+ template <class O>
+ inline Iterator<T>& operator=(const ObjectListIterator<O>& other)
+ {
+ if (this->list_)
+ this->list_->unregisterIterator(this);
+
+ this->element_ = other.element_;
+ this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
+ this->list_->registerIterator(this);
+
+ return (*this);
+ }
+
+ /**
+ @brief Overloading of the ++it operator: Iterator points to the next object in the list.
+ @return The Iterator itself
+ */
+ inline const Iterator<T>& operator++()
+ {
+ this->element_ = this->element_->next_;
+ return *this;
+ }
+
+ /**
+ @brief Overloading of the it++ operator: Iterator points to the next object in the list.
+ @return The Iterator itself
+ */
+ inline Iterator<T> operator++(int)
+ {
+ Iterator<T> copy = *this;
+ this->element_ = this->element_->next_;
+ return copy;
+ }
+
+ /**
+ @brief Overloading of the --it operator: Iterator points to the previous object in the list.
+ @return The Iterator itself
+ */
+ inline const Iterator<T>& operator--()
+ {
+ this->element_ = this->element_->prev_;
+ return *this;
+ }
+
+ /**
+ @brief Overloading of the it-- operator: Iterator points to the previous object in the list.
+ @return The Iterator itself
+ */
+ inline Iterator<T> operator--(int i)
+ {
+ Iterator<T> copy = *this;
+ this->element_ = this->element_->prev_;
+ return copy;
+ }
+
+ /**
+ @brief Overloading of the *it operator: returns the pointer to the object.
+ @return The object the Iterator points at
+ */
+ inline T* operator*() const
+ {
+ return orxonox_cast<T*>(this->element_->objectBase_);
+ }
+
+ /**
+ @brief Overloading of the it-> operator: returns the pointer to the object.
+ @return The object the Iterator points at
+ */
+ inline T* operator->() const
+ {
+ return orxonox_cast<T*>(this->element_->objectBase_);
+ }
+
+ /**
+ @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.
+ @return True if the Iterator points to an existing object.
+ */
+ inline operator bool() const
+ {
+ return (this->element_ != 0);
+ }
+
+ /**
+ @brief Overloading of the == operator to compare with another Iterator.
+ @param compare The other Iterator
+ @return True if the iterators point to the same element
+ */
+ inline bool operator==(const Iterator<T>& compare) const
+ {
+ return (this->element_ == compare.element_);
+ }
+
+ /**
+ @brief Overloading of the != operator to compare with another Iterator.
+ @param compare The other Iterator
+ @return True if the iterators point to different elements
+ */
+ inline bool operator!=(const Iterator<T>& compare) const
+ {
+ return (this->element_ != compare.element_);
+ }
+
+ /**
+ @brief Increments the Iterator if it points at the given object.
+ @param object The object to compare with
+ */
+ inline void incrementIfEqual(OrxonoxClass* object)
+ {
+ if (this->element_ && this->element_->objectBase_ == object)
+ this->operator++();
+ }
+
+ protected:
+ ObjectListBaseElement* element_; //!< The element the Iterator points at
+ ObjectListBase* list_; //!< The list wherein the element is
+ };
+
+ typedef Iterator<OrxonoxClass> BaseIterator;
+}
+
+#endif /* _Iterator_H__ */
Copied: code/branches/core6/src/libraries/core/object/MetaObjectList.cc (from rev 9552, code/branches/core6/src/libraries/core/MetaObjectList.cc)
===================================================================
--- code/branches/core6/src/libraries/core/object/MetaObjectList.cc (rev 0)
+++ code/branches/core6/src/libraries/core/object/MetaObjectList.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,103 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @brief Implementation of the MetaObjectList class.
+*/
+
+#include "MetaObjectList.h"
+
+#include "util/Output.h"
+#include "core/Identifier.h"
+#include "ObjectListBase.h"
+
+namespace orxonox
+{
+ // ###############################
+ // ### MetaObjectListElement ###
+ // ###############################
+ /**
+ @brief Destructor: Removes the ObjectListBaseElement from the ObjectListBase by linking next_ and prev_ of the ObjectListBaseElement.
+ */
+ MetaObjectListElement::~MetaObjectListElement()
+ {
+ orxout(verbose, context::object_list) << "Removing Object from " << this->list_->getIdentifier()->getName() << "-list." << endl;
+ this->list_->notifyIterators(this->element_->objectBase_);
+
+ if (this->element_->next_)
+ this->element_->next_->prev_ = this->element_->prev_;
+ else
+ this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list
+
+ if (this->element_->prev_)
+ this->element_->prev_->next_ = this->element_->next_;
+ else
+ this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list
+
+ delete this->element_;
+ }
+
+
+ // ###############################
+ // ### MetaObjectList ###
+ // ###############################
+ /**
+ @brief Constructor: Sets first_ to zero.
+ */
+ MetaObjectList::MetaObjectList()
+ {
+ this->first_ = 0;
+ }
+
+ /**
+ @brief Destructor: Removes all elements from the list, causing them to remove the stored ObjectListElement from the ObjectList.
+ */
+ MetaObjectList::~MetaObjectList()
+ {
+ MetaObjectListElement* temp;
+ while (this->first_)
+ {
+ temp = this->first_->next_;
+ delete this->first_;
+ this->first_ = temp;
+ }
+ }
+
+ /**
+ @brief Adds an ObjectList and an element of that list to the MetaObjectList.
+ @param list The ObjectList wherein the element is
+ @param element The element wherein the object is
+ */
+ void MetaObjectList::add(ObjectListBase* list, ObjectListBaseElement* element)
+ {
+ MetaObjectListElement* temp = this->first_;
+ this->first_ = new MetaObjectListElement(list, element);
+ this->first_->next_ = temp;
+ }
+}
Copied: code/branches/core6/src/libraries/core/object/MetaObjectList.h (from rev 9552, code/branches/core6/src/libraries/core/MetaObjectList.h)
===================================================================
--- code/branches/core6/src/libraries/core/object/MetaObjectList.h (rev 0)
+++ code/branches/core6/src/libraries/core/object/MetaObjectList.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,86 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @ingroup Object ObjectList
+ @brief Declaration of the MetaObjectList class.
+
+ The MetaObjectList is a single-linked list, containing all list-elements and their
+ lists wherein the object, owning the MetaObjectList, is registered.
+ This allows much faster deletion of objects because no iteration is needed.
+*/
+
+#ifndef _MetaObjectList_H__
+#define _MetaObjectList_H__
+
+#include "core/CorePrereqs.h"
+
+namespace orxonox
+{
+ // ###############################
+ // ### MetaObjectListElement ###
+ // ###############################
+ /// The list-element of the MetaObjectList
+ class _CoreExport MetaObjectListElement
+ {
+ public:
+ /**
+ @brief Constructor: Creates the list-element with given list and element.
+ */
+ MetaObjectListElement(ObjectListBase* list, ObjectListBaseElement* element) : next_(0), element_(element), list_(list) {}
+ ~MetaObjectListElement();
+
+ MetaObjectListElement* next_; //!< The next Element in the list
+ ObjectListBaseElement* element_; //!< The list element, containing the object
+ ObjectListBase* list_; //!< The list, containing the element
+ };
+
+
+ // ###############################
+ // ### MetaObjectList ###
+ // ###############################
+ /**
+ @brief The MetaObjectList contains ObjectListBaseElements and their ObjectListBases.
+
+ The MetaObjectList is a single-linked list, containing all list-elements and their
+ lists wherein the object that owns the MetaObjectList is registered.
+ This allows much faster deletion of objects because no iteration is needed.
+ */
+ class _CoreExport MetaObjectList
+ {
+ public:
+ MetaObjectList();
+ ~MetaObjectList();
+ void add(ObjectListBase* list, ObjectListBaseElement* element);
+
+ MetaObjectListElement* first_; //!< The first element in the list
+ };
+}
+
+#endif /* _MetaObjectList_H__ */
Copied: code/branches/core6/src/libraries/core/object/ObjectList.h (from rev 9552, code/branches/core6/src/libraries/core/ObjectList.h)
===================================================================
--- code/branches/core6/src/libraries/core/object/ObjectList.h (rev 0)
+++ code/branches/core6/src/libraries/core/object/ObjectList.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,100 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @defgroup ObjectList Object-lists and iterators
+ @ingroup Object
+*/
+
+/**
+ @file
+ @ingroup Object ObjectList
+ @brief Definition of the ObjectList class, a wrapper of ObjectListBase.
+
+ @ref orxonox::ObjectList "ObjectList<T>" is a wrapper of an @ref orxonox::ObjectListBase
+ "ObjectListBase" of class @a T. Use @ref orxonox::ObjectListIterator "ObjectListIterator<T>"
+ to iterate through the list.
+*/
+
+#ifndef _ObjectList_H__
+#define _ObjectList_H__
+
+#include "core/CorePrereqs.h"
+
+#include "ObjectListBase.h"
+#include "ObjectListIterator.h"
+
+namespace orxonox
+{
+ // ###############################
+ // ### ObjectList ###
+ // ###############################
+ /**
+ @brief The ObjectList contains all objects of the given class.
+
+ Wraps the ObjectListBase which contains all objects of type @a T. Use @ref ObjectListIterator
+ "ObjectListIterator<T>" or its typedef ObjectList<T>::iterator to iterate through all objects
+ in the list.
+ */
+ template <class T>
+ class ObjectList
+ {
+ public:
+ typedef ObjectListIterator<T> iterator;
+
+ /// Returns an Iterator to the first element in the list.
+ inline static ObjectListElement<T>* begin()
+ {
+ ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
+ return static_cast<ObjectListElement<T>*>(list->begin().element_);
+ }
+
+ /// 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_);
+ }
+
+ /// 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_);
+ }
+
+ /// 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_);
+ }
+ };
+}
+
+#endif /* _ObjectList_H__ */
Copied: code/branches/core6/src/libraries/core/object/ObjectListBase.cc (from rev 9552, code/branches/core6/src/libraries/core/ObjectListBase.cc)
===================================================================
--- code/branches/core6/src/libraries/core/object/ObjectListBase.cc (rev 0)
+++ code/branches/core6/src/libraries/core/object/ObjectListBase.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,102 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @brief Implementation of the ObjectListBase class.
+*/
+
+#include "ObjectListBase.h"
+
+#include <set>
+#include "Iterator.h"
+#include "ObjectListIterator.h"
+
+namespace orxonox
+{
+ /**
+ @brief Constructor: Sets default values.
+ */
+ ObjectListBase::ObjectListBase(Identifier* identifier)
+ {
+ this->identifier_ = identifier;
+ this->first_ = 0;
+ this->last_ = 0;
+ }
+
+ /**
+ @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS.
+ */
+ ObjectListBase::~ObjectListBase()
+ {
+ ObjectListBaseElement* temp;
+ while (this->first_)
+ {
+ temp = this->first_->next_;
+ delete this->first_;
+ this->first_ = temp;
+ }
+ }
+
+ /**
+ @brief Increases all Iterators that currently point on the given element (because it gets removed).
+ @param object The object that gets removed
+ */
+ void ObjectListBase::notifyIterators(OrxonoxClass* object) const
+ {
+ for (std::vector<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)
+ ((Iterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
+ for (std::vector<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it)
+ ((ObjectListIterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
+ }
+
+ /**
+ @brief Adds a new object to the end of the list.
+ @param element The element to add
+ @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object
+ */
+ ObjectListBaseElement* ObjectListBase::add(ObjectListBaseElement* element)
+ {
+ if (!this->last_)
+ {
+ // If the list is empty
+ this->last_ = element;
+ this->first_ = this->last_; // There's only one object in the list now
+ }
+ else
+ {
+ // If the list isn't empty
+ ObjectListBaseElement* temp = this->last_;
+ this->last_ = element;
+ this->last_->prev_ = temp;
+ temp->next_ = this->last_;
+ }
+
+ return this->last_;
+ }
+}
Copied: code/branches/core6/src/libraries/core/object/ObjectListBase.h (from rev 9552, code/branches/core6/src/libraries/core/ObjectListBase.h)
===================================================================
--- code/branches/core6/src/libraries/core/object/ObjectListBase.h (rev 0)
+++ code/branches/core6/src/libraries/core/object/ObjectListBase.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,157 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @ingroup Object ObjectList
+ @brief Declaration of the ObjectListBase class which stores all objects of each class.
+
+ orxonox::ObjectListBase is a double-linked list, used by @ref orxonox::Identifier "Identifiers"
+ to store all objects of a given class. Newly created objects are added to the list through the
+ @c RegisterObject() macro in the constructor.
+*/
+
+#ifndef _ObjectListBase_H__
+#define _ObjectListBase_H__
+
+#include "core/CorePrereqs.h"
+#include <vector>
+
+namespace orxonox
+{
+ // ###############################
+ // ### ObjectListBaseElement ###
+ // ###############################
+ /// The list-element of the ObjectListBase
+ class _CoreExport ObjectListBaseElement
+ {
+ public:
+ /**
+ @brief Constructor: Creates the list-element with an object.
+ @param objectBase The object to store
+ */
+ ObjectListBaseElement(OrxonoxClass* objectBase) : next_(0), prev_(0), objectBase_(objectBase) {}
+
+ ObjectListBaseElement* next_; //!< The next element in the list
+ ObjectListBaseElement* prev_; //!< The previous element in the list
+ OrxonoxClass* objectBase_;
+ };
+
+
+ // ###############################
+ // ### ObjectListElement ###
+ // ###############################
+ /// The list-element that actually contains the object
+ template <class T>
+ class ObjectListElement : public ObjectListBaseElement
+ {
+ public:
+ ObjectListElement(T* object) : ObjectListBaseElement(static_cast<OrxonoxClass*>(object)), object_(object) {}
+ T* object_; //!< The object
+ };
+
+
+ // ###############################
+ // ### ObjectListBase ###
+ // ###############################
+ /**
+ @brief The ObjectListBase contains all objects of a given class.
+
+ The ObjectListBase is used by Identifiers to store all objects of their class.
+ You can use Identifier::getObjects() to get the object-list from an Identifier.
+ Use @ref Iterator "Iterator<T>" to iterate through them.
+
+ Alternatively you can also use the static helper class @ref orxonox::ObjectList "ObjectList<T>"
+ to get the list of all objects of type @a T. Use @ref ObjectListIterator "ObjectListIterator<T>"
+ or @ref Iterator "Iterator<T>" to iterate through them.
+ */
+ class _CoreExport ObjectListBase
+ {
+ friend class MetaObjectListElement;
+
+ public:
+ ObjectListBase(Identifier* identifier);
+ ~ObjectListBase();
+
+ ObjectListBaseElement* add(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_); }
+ /// 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); }
+ /// Returns a pointer to the last element in the list. Works only with Iterator.
+ inline Export rbegin() { return ObjectListBase::Export(this, 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 void registerIterator(void* iterator) { this->iterators_.push_back(iterator); }
+ inline void unregisterIterator(void* iterator)
+ {
+ for (unsigned int i = 0; i < this->iterators_.size(); ++i)
+ {
+ if (iterators_[i] == iterator)
+ {
+ iterators_.erase(iterators_.begin() + i);
+ break;
+ }
+ }
+ }
+ inline void registerObjectListIterator(void* iterator) { this->objectListIterators_.push_back(iterator); }
+ inline void unregisterObjectListIterator(void* iterator)
+ {
+ for (unsigned int i = 0; i < this->objectListIterators_.size(); ++i)
+ {
+ if (objectListIterators_[i] == iterator)
+ {
+ objectListIterators_.erase(objectListIterators_.begin() + i);
+ break;
+ }
+ }
+ }
+ void notifyIterators(OrxonoxClass* object) const;
+
+ inline Identifier* getIdentifier() const { return this->identifier_; }
+
+ private:
+ Identifier* identifier_; //!< The Iterator owning this list
+ ObjectListBaseElement* first_; //!< The first element in the list
+ ObjectListBaseElement* last_; //!< The last element in the list
+ std::vector<void*> iterators_; //!< A list of Iterators pointing on an element in this list
+ std::vector<void*> objectListIterators_; //!< A list of ObjectListIterators pointing on an element in this list
+ };
+}
+
+#endif /* _ObjectListBase_H__ */
Copied: code/branches/core6/src/libraries/core/object/ObjectListIterator.h (from rev 9552, code/branches/core6/src/libraries/core/ObjectListIterator.h)
===================================================================
--- code/branches/core6/src/libraries/core/object/ObjectListIterator.h (rev 0)
+++ code/branches/core6/src/libraries/core/object/ObjectListIterator.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,236 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @ingroup Object ObjectList
+ @brief Definition of the ObjectListIterator class, used to iterate through object-lists.
+
+ @anchor ObjectListIteratorExample
+
+ @ref orxonox::ObjectListIterator "ObjectListIterator<T>" allows to iterate through
+ @ref orxonox::ObjectList "ObjectList<T>", containing all objects of type @a T. In contrast to
+ @ref orxonox::Iterator "Iterator<T>", this iterator is limited to the object-list of type @a T.
+ It is, however, much faster as it doesn't need a @c dynamic_cast.
+
+ Usage:
+ @code
+ for (ObjectListIterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it)
+ {
+ it->someFunction(...);
+ myClass* myObject = *it;
+ }
+ @endcode
+
+ @note @ref orxonox::ObjectList::iterator "ObjectList<T>::iterator" is identical to
+ @ref orxonox::ObjectListIterator "ObjectListIterator<T>" (it's just a typedef).
+*/
+
+#ifndef _ObjectListIterator_H__
+#define _ObjectListIterator_H__
+
+#include "core/CorePrereqs.h"
+#include "core/Identifier.h"
+#include "ObjectList.h"
+
+namespace orxonox
+{
+ /**
+ @brief ObjectListIterator<T> allows to iterate through the ObjectList of class @a T.
+
+ @see See @ref ObjectListIteratorExample "ObjectListIterator.h" for more information an example.
+ */
+ template <class T>
+ class ObjectListIterator
+ {
+ template <class I>
+ friend class Iterator;
+
+ public:
+ /**
+ @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero.
+ */
+ inline ObjectListIterator()
+ {
+ this->element_ = 0;
+ ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
+ }
+
+ /**
+ @brief Constructor: Sets this element to a given element.
+ @param element The element to start with
+ */
+ inline ObjectListIterator(ObjectListElement<T>* element)
+ {
+ this->element_ = element;
+ ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
+ }
+
+ /**
+ @brief Constructor: Sets this element to the element of another ObjectListIterator.
+ @param other The other ObjectListIterator
+ */
+ inline ObjectListIterator(const ObjectListIterator<T>& other)
+ {
+ this->element_ = other.element_;
+ ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
+ }
+
+ /**
+ @brief Unregisters the ObjectListIterator from the ObjectList.
+ */
+ inline ~ObjectListIterator()
+ {
+ ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterObjectListIterator(this);
+ }
+
+ /**
+ @brief Assigns an ObjectListElement.
+ @param element The ObjectListElement
+ */
+ inline ObjectListIterator<T>& operator=(ObjectListElement<T>* element)
+ {
+ this->element_ = element;
+ return (*this);
+ }
+
+ /**
+ @brief Assigns the element of another ObjectListIterator.
+ @param other The other ObjectListIterator
+ */
+ inline ObjectListIterator<T>& operator=(const ObjectListIterator<T>& other)
+ {
+ this->element_ = other.element_;
+ return (*this);
+ }
+
+ /**
+ @brief Overloading of the ++it operator: ObjectListIterator points to the next object in the list.
+ @return The ObjectListIterator itself
+ */
+ inline const ObjectListIterator<T>& operator++()
+ {
+ this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
+ return *this;
+ }
+
+ /**
+ @brief Overloading of the it++ operator: ObjectListIterator points to the next object in the list.
+ @return The ObjectListIterator itself
+ */
+ inline ObjectListIterator<T> operator++(int)
+ {
+ ObjectListIterator<T> copy = *this;
+ this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
+ return copy;
+ }
+
+ /**
+ @brief Overloading of the --it operator: ObjectListIterator points to the previous object in the list.
+ @return The ObjectListIterator itself
+ */
+ inline const ObjectListIterator<T>& operator--()
+ {
+ this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
+ return *this;
+ }
+
+ /**
+ @brief Overloading of the it-- operator: ObjectListIterator points to the previous object in the list.
+ @return The ObjectListIterator itself
+ */
+ inline ObjectListIterator<T> operator--(int i)
+ {
+ ObjectListIterator<T> copy = *this;
+ this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
+ return copy;
+ }
+
+ /**
+ @brief Overloading of the *it operator: returns the pointer to the object.
+ @return The object the ObjectListIterator points at
+ */
+ inline T* operator*() const
+ {
+ return this->element_->object_;
+ }
+
+ /**
+ @brief Overloading of the it-> operator: returns the pointer to the object.
+ @return The object the ObjectListIterator points at
+ */
+ inline T* operator->() const
+ {
+ return this->element_->object_;
+ }
+
+ /**
+ @brief Overloading of the typecast-operator to bool: returns true if the ObjectListIterator points to an existing object.
+ @return True if the ObjectListIterator points to an existing object.
+ */
+ inline operator bool() const
+ {
+ return (this->element_ != 0);
+ }
+
+ /**
+ @brief Overloading of the == operator to compare with another ObjectListIterator.
+ @param compare The other ObjectListIterator
+ @return True if the ObjectListIterator point to the same element
+ */
+ inline bool operator==(const ObjectListIterator<T>& compare) const
+ {
+ return (this->element_ == compare.element_);
+ }
+
+ /**
+ @brief Overloading of the != operator to compare with another ObjectListIterator.
+ @param compare The other ObjectListIterator
+ @return True if the ObjectListIterator point to different elements
+ */
+ inline bool operator!=(const ObjectListIterator<T>& compare) const
+ {
+ return (this->element_ != compare.element_);
+ }
+
+ /**
+ @brief Increments the ObjectListIterator if it points at the given object.
+ @param object The object to compare with
+ */
+ inline void incrementIfEqual(OrxonoxClass* object)
+ {
+ if (this->element_ && this->element_->objectBase_ == object)
+ this->operator++();
+ }
+
+ private:
+ ObjectListElement<T>* element_; //!< The element the iterator points at
+ };
+}
+
+#endif /* _ObjectListIterator_H__ */
Copied: code/branches/core6/src/libraries/core/object/SmartPtr.h (from rev 9552, code/branches/core6/src/libraries/core/SmartPtr.h)
===================================================================
--- code/branches/core6/src/libraries/core/object/SmartPtr.h (rev 0)
+++ code/branches/core6/src/libraries/core/object/SmartPtr.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,316 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+// Inspired by boost::intrusive_ptr by Peter Dimov
+
+/**
+ @defgroup SmartPtr SmartPtr<T> and WeakPtr<T>
+ @ingroup Object
+*/
+
+/**
+ @file
+ @ingroup Object SmartPtr
+ @brief Definition of SmartPtr<T>, wraps a pointer to an object and keeps it alive.
+
+ @anchor SmartPtrExample
+
+ orxonox::SmartPtr is an implementation of a smart pointer - it wraps a pointer to an
+ object and keeps this object alive until no SmartPtr points to this object anymore.
+ In contrast to orxonox::SharedPtr, SmartPtr works only with classes that are derived
+ from orxonox::OrxonoxClass, because it's an intrusive implementation, meaning the
+ reference counter is stored in the object itself.
+
+ It's possible to use normal pointers and smart pointers to an object simultaneously.
+ You don't have to use SmartPtr all the time, you can create a SmartPtr for an object
+ at any time and also convert it back to a normal pointer if you like. This is possible
+ because the reference counter is stored in the object itself and not in SmartPtr (in
+ contrast to SharedPtr).
+
+ @b Important: If you want to delete an object, you must not use @c delete @c object but
+ rather @c object->destroy(). This function will check if there are smart pointers
+ pointing to the object. If yes, the object will be kept alive until all smart pointes
+ are destroyed. If no, the object is deleted instantly.
+
+ If all smart pointers that point to an object are destroyed, but you never called
+ @c object->destroy() before, the object will not be deleted! All a SmartPtr will do
+ is to really just keep an object alive, but it will not delete it automatically
+ unless you tried to destroy it before.
+
+ Example:
+ @code
+ class MyClass // class declaration
+ {
+ public:
+ void setObject(OtherClass* object) // passes a normal pointer which will be stored in a SmartPtr
+ { this->object_ = object; }
+
+ OtherClass* getObject() const // converts the SmartPtr to a normal pointer and returns it
+ { return this->object_; }
+
+ private:
+ SmartPtr<OtherClass> object_; // a pointer to an instance of OtherClass is stored in a SmartPtr
+ };
+ @endcode
+ In this example we assume that OtherClass is a child of OrxonoxClass. We don't care
+ about the inheritance of MyClass though.
+
+ Now we create an instance of MyClass and assign a pointer to an instance of OtherClass:
+ @code
+ MyClass* myclass = new MyClass(); // create an instance of MyClass
+ OtherClass* object = new OtherClass(); // create an instance of OtherClass
+ myclass->setObject(object); // the object is now stored in a SmartPtr inside myclass
+
+ object->destroy(); // we try to destroy object, but there's still a SmartPtr pointing at it.
+
+ # object still exists at this point (because a SmartPtr points at it)
+
+ delete myclass; // now we delete myclass, which also destroys the SmartPtr
+
+ # object doesn't exist anymore (because the SmartPtr is now destroyed)
+ @endcode
+
+ Now we look at the same example, but we first delete myclass, then destroy object:
+ @code
+ MyClass* myclass = new MyClass(); // create an instance of MyClass
+ OtherClass* object = new OtherClass(); // create an instance of OtherClass
+ myclass->setObject(object); // the object is now stored in a SmartPtr inside myclass
+
+ delete myclass; // we delete myclass, which also destroys the SmartPtr
+
+ # object still exists at this point (because destroy() was not called yet)
+
+ object->destroy(); // now we try to destroy object, which works instantly
+
+ # object doesn't exist anymore (because we just destroyed it)
+ @endcode
+
+ Note that in any case @c object->destroy() has to be called to delete the object.
+ However if a SmartPtr points at it, the destruction is delayed until all SmartPtr
+ are destroyed.
+*/
+
+#ifndef _SmartPtr_H__
+#define _SmartPtr_H__
+
+#include "core/CorePrereqs.h"
+
+#include <cassert>
+
+#include "core/OrxonoxClass.h"
+#include "WeakPtr.h"
+
+namespace orxonox
+{
+ /**
+ @brief A smart pointer which wraps a pointer to an object and keeps this object alive as long as the smart pointer exists.
+
+ @see See @ref SmartPtrExample "this description" for more information and an example.
+ */
+ template <class T>
+ class SmartPtr
+ {
+ public:
+ /// Constructor: Initializes the smart pointer with a null pointer.
+ inline SmartPtr() : pointer_(0), base_(0)
+ {
+ }
+
+ /// Constructor: Used to explicitly initialize the smart pointer with a null pointer
+ inline SmartPtr(int) : pointer_(0), base_(0)
+ {
+ }
+
+ /// Constructor: Initializes the smart pointer with a pointer to an object. @param pointer The pointer @param bAddRef If true, the reference counter is increased. Don't set this to false unless you know exactly what you're doing! (for example to avoid circular references if the @c this pointer of the possessing object is stored)
+ inline SmartPtr(T* pointer, bool bAddRef = true) : pointer_(pointer), base_(pointer)
+ {
+ if (this->base_ && bAddRef)
+ this->base_->incrementReferenceCount();
+ }
+
+ /// Copy-constructor
+ inline SmartPtr(const SmartPtr& other) : pointer_(other.pointer_), base_(other.base_)
+ {
+ if (this->base_)
+ this->base_->incrementReferenceCount();
+ }
+
+ /// Copy-constructor for smart pointers to objects of another class.
+ template <class O>
+ inline SmartPtr(const SmartPtr<O>& other) : pointer_(other.get()), base_(other.base_)
+ {
+ if (this->base_)
+ this->base_->incrementReferenceCount();
+ }
+
+ /// Constructor: Initializes the smart pointer with the pointer that is stored in a WeakPtr.
+ template <class O>
+ inline SmartPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.getBase())
+ {
+ if (this->base_)
+ this->base_->incrementReferenceCount();
+ }
+
+ /// Destructor: Decrements the reference counter.
+ inline ~SmartPtr()
+ {
+ if (this->base_)
+ this->base_->decrementReferenceCount();
+ }
+
+ /// Used to assign a null pointer.
+ inline SmartPtr& operator=(int)
+ {
+ SmartPtr(0).swap(*this);
+ return *this;
+ }
+
+ /// Assigns a new pointer.
+ inline SmartPtr& operator=(T* pointer)
+ {
+ SmartPtr(pointer).swap(*this);
+ return *this;
+ }
+
+ /// Assigns the wrapped pointer of another SmartPtr.
+ inline SmartPtr& operator=(const SmartPtr& other)
+ {
+ SmartPtr(other).swap(*this);
+ return *this;
+ }
+
+ /// Assigns the wrapped pointer of a SmartPtr of another class
+ template <class O>
+ inline SmartPtr& operator=(const SmartPtr<O>& other)
+ {
+ SmartPtr(other).swap(*this);
+ return *this;
+ }
+
+ /// Assigns the wrapped pointer of a WeakPtr.
+ template <class O>
+ inline SmartPtr& operator=(const WeakPtr<O>& other)
+ {
+ SmartPtr(other).swap(*this);
+ return *this;
+ }
+
+ /// Returns the wrapped pointer as @c T*
+ inline T* get() const
+ {
+ return this->pointer_;
+ }
+
+ /// Returns the wrapped pointer as @c OrxonoxClass*
+ inline OrxonoxClass* getBase() const
+ {
+ return this->base_;
+ }
+
+ /// Implicitly converts the SmartPtr to a pointer of type @c T*
+ inline operator T*() const
+ {
+ return this->pointer_;
+ }
+
+ /// Overloaded operator, returns a pointer to the stored object.
+ inline T* operator->() const
+ {
+ assert(this->pointer_ != 0);
+ return this->pointer_;
+ }
+
+ /// Overloaded operator, returns a reference to the stored object.
+ inline T& operator*() const
+ {
+ assert(this->pointer_ != 0);
+ return *this->pointer_;
+ }
+
+ /// Returns true if the wrapped pointer is NULL.
+ inline bool operator!() const
+ {
+ return (this->pointer_ == 0);
+ }
+
+ /// Swaps the contents of two smart pointers.
+ inline void swap(SmartPtr& other)
+ {
+ {
+ T* temp = this->pointer_;
+ this->pointer_ = other.pointer_;
+ other.pointer_ = temp;
+ }
+ {
+ OrxonoxClass* temp = this->base_;
+ this->base_ = other.base_;
+ other.base_ = temp;
+ }
+ }
+
+ /// Resets the smart pointer (equivalent to assigning a NULL pointer).
+ inline void reset()
+ {
+ SmartPtr().swap(*this);
+ }
+
+ private:
+ T* pointer_; ///< The wrapped pointer to an object of type @a T
+ OrxonoxClass* base_; ///< The wrapped pointer, casted up to OrxonoxClass (this is needed because with just a T* pointer, SmartPtr couln't be used with forward declarations)
+ };
+
+ /// Swaps the contents of two smart pointers.
+ template <class T>
+ void swap(SmartPtr<T>& a, SmartPtr<T>& b)
+ {
+ a.swap(b);
+ }
+
+ /// Uses a static_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>.
+ template <class T, class U>
+ SmartPtr<T> static_pointer_cast(const SmartPtr<U>& p)
+ {
+ return static_cast<T*>(p.get());
+ }
+
+ /// Uses a const_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>.
+ template <class T, class U>
+ SmartPtr<T> const_pointer_cast(const SmartPtr<U>& p)
+ {
+ return const_cast<T*>(p.get());
+ }
+
+ /// Uses a dynamic_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>.
+ template <class T, class U>
+ SmartPtr<T> dynamic_pointer_cast(const SmartPtr<U>& p)
+ {
+ return orxonox_cast<T*>(p.get());
+ }
+}
+
+#endif /* _SmartPtr_H__ */
Copied: code/branches/core6/src/libraries/core/object/WeakPtr.h (from rev 9552, code/branches/core6/src/libraries/core/WeakPtr.h)
===================================================================
--- code/branches/core6/src/libraries/core/object/WeakPtr.h (rev 0)
+++ code/branches/core6/src/libraries/core/object/WeakPtr.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -0,0 +1,286 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+// Inspired by boost::intrusive_ptr by Peter Dimov
+
+/**
+ @file
+ @ingroup Object SmartPtr
+ @brief Definition of WeakPtr<T>, wraps a pointer to an object.
+
+ @anchor WeakPtrExample
+
+ A WeakPtr wraps a pointer to an object. If the object gets deleted, the WeakPtr becomes
+ NULL. This can be used to store pointers to objects without knowing when they will be
+ destroyed.
+
+ WeakPtr works only with objects that are derived from orxonox::OrxonoxClass, because
+ WeakPtr is intrusive and registers itself in the stored object, to get a notification if
+ the object is being deleted.
+
+ Example:
+ @code
+ MyClass* object = new MyClass(); // create an instance of MyClass
+
+ WeakPtr<MyClass> pointer = object; // create a WeakPtr and assign the object
+
+ if (pointer) // checks if pointer is not NULL (which is true)
+ pointer->someFunction(); // calls MyClass::someFunction()
+
+ object->destroy(); // calls destroy() which deletes the object
+
+ if (pointer) // checks if pointer is not NULL (which is now false)
+ pointer->someFunction(); // this will not be executed
+ @endcode
+ In this example we assumed that MyClass is derived of OrxonoxClass (otherwise it couldn't
+ be used with a WeakPtr).
+
+ A callback can be registerd with the WeakPtr that will be called if the object gets deleted.
+ @code
+ void myCallback() // definition of the callback function
+ {
+ orxout() << "Object destroyed" << endl;
+ }
+
+ MyClass* object = new MyClass(); // create an instance of MyClass
+
+ WeakPtr<MyClass> pointer = object; // create a WeakPtr and assign the object
+
+ pointer.setCallback(createFunctor(&myCallback)); // defines a callback
+
+ object->destroy(); // calls destroy() which deletes the object. prints "Object destroyed" to the console
+ @endcode
+*/
+
+#ifndef _WeakPtr_H__
+#define _WeakPtr_H__
+
+#include "core/CorePrereqs.h"
+
+#include <cassert>
+
+#include "core/OrxonoxClass.h"
+#include "core/command/Functor.h"
+
+namespace orxonox
+{
+ /**
+ @brief WeakPtr wraps a pointer to an object, which becomes NULL if the object is deleted.
+
+ @see See @ref WeakPtrExample "this description" for more information and an example.
+ */
+ template <class T>
+ class WeakPtr : public DestructionListener
+ {
+ public:
+ /// Constructor: Initializes the weak pointer with a null pointer.
+ inline WeakPtr() : pointer_(0), base_(0), callback_(0)
+ {
+ }
+
+ /// Constructor: Used to explicitly initialize the weak pointer with a null pointer
+ inline WeakPtr(int) : pointer_(0), base_(0), callback_(0)
+ {
+ }
+
+ /// Constructor: Initializes the weak pointer with a pointer to an object.
+ inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(0)
+ {
+ this->registerAsDestructionListener(this->base_);
+ }
+
+ /// Copy-constructor
+ inline WeakPtr(const WeakPtr& other) : pointer_(other.pointer_), base_(other.base_), callback_(0)
+ {
+ this->registerAsDestructionListener(this->base_);
+ }
+
+ /// Copy-constructor for weak pointers to objects of another class.
+ template <class O>
+ inline WeakPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.base_), callback_(0)
+ {
+ this->registerAsDestructionListener(this->base_);
+ }
+
+ /// Destructor
+ inline virtual ~WeakPtr()
+ {
+ this->unregisterAsDestructionListener(this->base_);
+ }
+
+ /// Used to assign a null pointer.
+ inline WeakPtr& operator=(int)
+ {
+ WeakPtr(0).swap(*this);
+ return *this;
+ }
+
+ /// Assigns a new pointer.
+ inline WeakPtr& operator=(T* pointer)
+ {
+ WeakPtr(pointer).swap(*this);
+ return *this;
+ }
+
+ /// Assigns the wrapped pointer of another WeakPtr.
+ inline WeakPtr& operator=(const WeakPtr& other)
+ {
+ WeakPtr(other).swap(*this);
+ return *this;
+ }
+
+ /// Assigns the wrapped pointer of a WeakPtr of another class
+ template <class O>
+ inline WeakPtr& operator=(const WeakPtr<O>& other)
+ {
+ WeakPtr(other).swap(*this);
+ return *this;
+ }
+
+ /// Returns the wrapped pointer as @c T*
+ inline T* get() const
+ {
+ return this->pointer_;
+ }
+
+ /// Returns the wrapped pointer as @c OrxonoxClass*
+ inline OrxonoxClass* getBase() const
+ {
+ return this->base_;
+ }
+
+ /// Implicitly converts the WeakPtr to a pointer of type @c T*
+ inline operator T*() const
+ {
+ return this->pointer_;
+ }
+
+ /// Overloaded operator, returns a pointer to the stored object.
+ inline T* operator->() const
+ {
+ assert(this->pointer_ != 0);
+ return this->pointer_;
+ }
+
+ /// Overloaded operator, returns a reference to the stored object.
+ inline T& operator*() const
+ {
+ assert(this->pointer_ != 0);
+ return *this->pointer_;
+ }
+
+ /// Returns true if the wrapped pointer is NULL.
+ inline bool operator!() const
+ {
+ return (this->pointer_ == 0);
+ }
+
+ /// Swaps the contents of two weak pointers.
+ inline void swap(WeakPtr& other)
+ {
+ this->unregisterAsDestructionListener(this->base_);
+ other.unregisterAsDestructionListener(other.base_);
+
+ {
+ T* temp = this->pointer_;
+ this->pointer_ = other.pointer_;
+ other.pointer_ = temp;
+ }
+ {
+ OrxonoxClass* temp = this->base_;
+ this->base_ = other.base_;
+ other.base_ = temp;
+ }
+
+ this->registerAsDestructionListener(this->base_);
+ other.registerAsDestructionListener(other.base_);
+ }
+
+ /// Resets the weak pointer (equivalent to assigning a NULL pointer).
+ inline void reset()
+ {
+ WeakPtr().swap(*this);
+ }
+
+ /// Registers a callback that will be executed if the stored object is destroyed.
+ inline void setCallback(const FunctorPtr& callback)
+ {
+ this->callback_ = callback;
+ }
+
+ /// Returns the registered callback.
+ inline const FunctorPtr& getCallback() const
+ {
+ return this->callback_;
+ }
+
+ private:
+ /// Will be called by OrxonoxClass::~OrxonoxClass() if the stored object is deleted. Resets the wrapped pointer and executes the callback.
+ inline void objectDeleted()
+ {
+ this->base_ = 0;
+ this->pointer_ = 0;
+ if (this->callback_)
+ (*this->callback_)();
+ }
+
+ T* pointer_; ///< The wrapped pointer to an object of type @a T
+ OrxonoxClass* base_; ///< The wrapped pointer, casted up to OrxonoxClass (this is needed because with just a T* pointer, WeakPtr couln't be used with forward declarations)
+ FunctorPtr callback_; ///< This callback will be executed if the stored object is deleted
+ };
+
+ /// Swaps the contents of two weak pointers.
+ template <class T>
+ void swap(WeakPtr<T>& a, WeakPtr<T>& b)
+ {
+ a.swap(b);
+ }
+
+ /// Uses a static_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>.
+ template <class T, class U>
+ WeakPtr<T> static_pointer_cast(const WeakPtr<U>& p)
+ {
+ return static_cast<T*>(p.get());
+ }
+
+ /// Uses a const_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>.
+ template <class T, class U>
+ WeakPtr<T> const_pointer_cast(const WeakPtr<U>& p)
+ {
+ return const_cast<T*>(p.get());
+ }
+
+ /// Uses a dynamic_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>.
+ template <class T, class U>
+ WeakPtr<T> dynamic_pointer_cast(const WeakPtr<U>& p)
+ {
+ return orxonox_cast<T*>(p.get());
+ }
+}
+
+#endif /* _WeakPtr_H__ */
Modified: code/branches/core6/src/libraries/network/Host.cc
===================================================================
--- code/branches/core6/src/libraries/network/Host.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/network/Host.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -32,7 +32,7 @@
#include <string>
#include "core/CoreIncludes.h"
-#include "core/ObjectList.h"
+#include "core/object/ObjectList.h"
#include "core/command/ConsoleCommand.h"
#include "NetworkChatListener.h"
Modified: code/branches/core6/src/libraries/network/Server.cc
===================================================================
--- code/branches/core6/src/libraries/network/Server.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/network/Server.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -47,7 +47,6 @@
#include "util/Clock.h"
#include "util/Output.h"
-#include "core/ObjectList.h"
#include "core/command/Executor.h"
#include "packet/Chat.h"
#include "packet/ClassID.h"
Modified: code/branches/core6/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- code/branches/core6/src/libraries/network/packet/FunctionIDs.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/network/packet/FunctionIDs.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -34,7 +34,7 @@
#include <string>
#include "util/Output.h"
-#include "core/ObjectList.h"
+#include "core/object/ObjectList.h"
#include "network/NetworkFunction.h"
namespace orxonox {
Modified: code/branches/core6/src/libraries/network/packet/Gamestate.cc
===================================================================
--- code/branches/core6/src/libraries/network/packet/Gamestate.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/libraries/network/packet/Gamestate.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -33,7 +33,7 @@
#include "util/Output.h"
#include "util/OrxAssert.h"
#include "core/GameMode.h"
-#include "core/ObjectList.h"
+#include "core/object/ObjectList.h"
#include "network/synchronisable/Synchronisable.h"
#include "network/GamestateHandler.h"
#include "network/Host.h"
Modified: code/branches/core6/src/modules/objects/SpaceBoundaries.cc
===================================================================
--- code/branches/core6/src/modules/objects/SpaceBoundaries.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/modules/objects/SpaceBoundaries.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -31,7 +31,7 @@
#include <OgreBillboardSet.h>
#include "core/CoreIncludes.h"
-#include "core/ObjectListIterator.h"
+#include "core/object/ObjectListIterator.h"
#include "core/XMLPort.h"
#include "graphics/Billboard.h"
Modified: code/branches/core6/src/modules/objects/SpaceBoundaries.h
===================================================================
--- code/branches/core6/src/modules/objects/SpaceBoundaries.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/modules/objects/SpaceBoundaries.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -36,7 +36,7 @@
#include <vector>
#include "core/CoreIncludes.h"
-#include "core/WeakPtr.h"
+#include "core/object/WeakPtr.h"
#include "tools/interfaces/Tickable.h"
#include "worldentities/StaticEntity.h"
Modified: code/branches/core6/src/modules/objects/triggers/DistanceMultiTrigger.h
===================================================================
--- code/branches/core6/src/modules/objects/triggers/DistanceMultiTrigger.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/modules/objects/triggers/DistanceMultiTrigger.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -39,7 +39,7 @@
#include <map>
-#include "core/WeakPtr.h"
+#include "core/object/WeakPtr.h"
#include "worldentities/WorldEntity.h"
Modified: code/branches/core6/src/modules/pickup/PickupManager.h
===================================================================
--- code/branches/core6/src/modules/pickup/PickupManager.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/modules/pickup/PickupManager.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -38,7 +38,7 @@
#include "PickupPrereqs.h"
#include <map>
-#include "core/WeakPtr.h"
+#include "core/object/WeakPtr.h"
#include "PickupRepresentation.h"
Modified: code/branches/core6/src/orxonox/CameraManager.cc
===================================================================
--- code/branches/core6/src/orxonox/CameraManager.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/orxonox/CameraManager.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -37,7 +37,7 @@
#include "util/ScopedSingletonManager.h"
#include "core/GameMode.h"
#include "core/GraphicsManager.h"
-#include "core/ObjectList.h"
+#include "core/object/ObjectList.h"
#include "tools/Shader.h"
#include "graphics/Camera.h"
Modified: code/branches/core6/src/orxonox/Radar.cc
===================================================================
--- code/branches/core6/src/orxonox/Radar.cc 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/orxonox/Radar.cc 2013-03-23 17:49:52 UTC (rev 9557)
@@ -36,7 +36,7 @@
#include <cassert>
//#include "util/Math.h"
-#include "core/ObjectList.h"
+#include "core/object/ObjectList.h"
#include "core/command/ConsoleCommand.h"
#include "interfaces/RadarListener.h"
#include "controllers/HumanController.h"
Modified: code/branches/core6/src/orxonox/Radar.h
===================================================================
--- code/branches/core6/src/orxonox/Radar.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/orxonox/Radar.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -40,7 +40,7 @@
#include <set>
#include <string>
-#include "core/ObjectListIterator.h"
+#include "core/object/ObjectListIterator.h"
#include "interfaces/RadarViewable.h"
#include "tools/interfaces/Tickable.h"
Modified: code/branches/core6/src/orxonox/controllers/DroneController.h
===================================================================
--- code/branches/core6/src/orxonox/controllers/DroneController.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/orxonox/controllers/DroneController.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -32,7 +32,7 @@
#include "OrxonoxPrereqs.h"
#include "AIController.h"
-#include "core/WeakPtr.h"
+#include "core/object/WeakPtr.h"
#include "tools/interfaces/Tickable.h"
#include "tools/Timer.h"
Modified: code/branches/core6/src/orxonox/interfaces/PlayerTrigger.h
===================================================================
--- code/branches/core6/src/orxonox/interfaces/PlayerTrigger.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/orxonox/interfaces/PlayerTrigger.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -38,7 +38,7 @@
#include "OrxonoxPrereqs.h"
#include "core/OrxonoxClass.h"
-#include "core/WeakPtr.h"
+#include "core/object/WeakPtr.h"
namespace orxonox
{
Modified: code/branches/core6/src/orxonox/interfaces/RadarViewable.h
===================================================================
--- code/branches/core6/src/orxonox/interfaces/RadarViewable.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/orxonox/interfaces/RadarViewable.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -36,7 +36,7 @@
#include "util/Math.h"
#include "core/OrxonoxClass.h"
-#include "core/SmartPtr.h"
+#include "core/object/SmartPtr.h"
namespace orxonox
{
Modified: code/branches/core6/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/core6/src/orxonox/sound/SoundManager.h 2013-03-23 15:34:14 UTC (rev 9556)
+++ code/branches/core6/src/orxonox/sound/SoundManager.h 2013-03-23 17:49:52 UTC (rev 9557)
@@ -39,7 +39,7 @@
#include "util/Singleton.h"
#include "core/OrxonoxClass.h"
-#include "core/SmartPtr.h"
+#include "core/object/SmartPtr.h"
// tolua_begin
namespace orxonox
More information about the Orxonox-commit
mailing list