Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2015, 9:12:21 PM (9 years ago)
Author:
landauf
Message:

merged branch core7 back to trunk

Location:
code/trunk
Files:
1 deleted
12 edited
3 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/object/CMakeLists.txt

    r9667 r10624  
    22  Context.cc
    33  Destroyable.cc
     4  DestroyLaterManager.cc
    45  Listable.cc
    56  ObjectListBase.cc
  • code/trunk/src/libraries/core/object/Context.cc

    r9667 r10624  
    7676    /*static*/ void Context::setRootContext(Context* context)
    7777    {
    78         if (Context::rootContext_s)
    79             delete Context::rootContext_s;
    8078        Context::rootContext_s = context;
     79    }
     80
     81    /*static*/ void Context::destroyRootContext()
     82    {
     83        delete Context::rootContext_s;
     84        Context::rootContext_s = NULL;
    8185    }
    8286
    8387    /*static*/ Context* Context::getRootContext()
    8488    {
    85         if (!Context::rootContext_s)
    86             Context::rootContext_s = new Context(NULL);
     89        OrxVerify(Context::rootContext_s != NULL, "Root Context is undefined");
    8790        return Context::rootContext_s;
    8891    }
     
    97100        return this->objectLists_[classID];
    98101    }
     102
     103    void Context::destroyObjectList(const Identifier* identifier)
     104    {
     105        ObjectListBase* objectList = this->getObjectList(identifier);
     106        delete objectList;
     107        this->objectLists_[identifier->getClassID()] = NULL;
     108    }
    99109}
  • code/trunk/src/libraries/core/object/Context.h

    r9667 r10624  
    4747        public:
    4848            static void setRootContext(Context* context);
     49            static void destroyRootContext();
    4950            static Context* getRootContext();
    5051
     
    7172            }
    7273
     74            void destroyObjectList(const Identifier* identifier);
     75
    7376        private:
    7477            Context* parentContext_;
  • code/trunk/src/libraries/core/object/Destroyable.cc

    r9944 r10624  
    3333
    3434#include "Destroyable.h"
     35#include "DestroyLaterManager.h"
    3536
    3637#include <cassert>
     
    6061
    6162    /**
    62         @brief Deletes the object if no @ref orxonox::SmartPtr "smart pointers" point to this object. Otherwise schedules the object to be deleted as soon as possible.
    63         Always call destroy() instead of using 'delete' directly, otherwise smart pointers won't work.
     63        @brief Deletes the object if no @ref orxonox::StrongPtr "strong pointers" point to this object. Otherwise schedules the object to be deleted as soon as possible.
     64        Always call destroy() instead of using 'delete' directly, otherwise strong pointers won't work.
    6465    */
    6566    void Destroyable::destroy()
     
    7475        }
    7576    }
     77
     78    /**
     79     * Works like @ref destroy() but doesn't destroy the object until the current tick has ended.
     80     */
     81    void Destroyable::destroyLater()
     82    {
     83        // register in DestroyLaterManager - this ensures that a strongPtr points to this object and keeps it alive for a while
     84        DestroyLaterManager::getInstance().retain(this);
     85
     86        // request destruction -> object will be deleted after all strongPtrs (including the one in DestroyLaterManager) were destroyed.
     87        this->destroy();
     88    }
    7689}
  • code/trunk/src/libraries/core/object/Destroyable.h

    r9944 r10624  
    3030    @file
    3131    @ingroup Object
    32     @brief Declaration of Destroyable, the base class of all objects which can be used with SmartPtr and WeakPtr.
     32    @brief Declaration of Destroyable, the base class of all objects which can be used with StrongPtr and WeakPtr.
    3333*/
    3434
     
    4343{
    4444    /**
    45         @brief Classes must inherit from this class if they should be used with SmartPtr or WeakPtr.
     45        @brief Classes must inherit from this class if they should be used with StrongPtr or WeakPtr.
    4646    */
    4747    class _CoreExport Destroyable
    4848    {
    4949        template <class T>
    50         friend class SmartPtr;
     50        friend class StrongPtr;
    5151
    5252        friend class DestructionListener;
     
    5757
    5858            void destroy();
     59            void destroyLater();
    5960
    60             /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object.
     61            /// Returns the number of @ref orxonox::StrongPtr "strong pointers" that point to this object.
    6162            inline unsigned int getReferenceCount() const
    6263                { return this->referenceCount_; }
    6364
    6465        protected:
    65             /// This virtual function is called if destroy() is called and no SmartPtr points to this object. Used in some cases to create a new SmartPtr to
     66            /// This virtual function is called if destroy() is called and no StrongPtr points to this object. Used in some cases to create a new StrongPtr to
    6667            /// prevent destruction. Don't call this function directly - use destroy() instead.
    6768            virtual void preDestroy() {}
    6869
    6970        private:
    70             /// Increments the reference counter (for smart pointers).
     71            /// Increments the reference counter (for strong pointers).
    7172            inline void incrementReferenceCount()
    7273                { ++this->referenceCount_; }
    73             /// Decrements the reference counter (for smart pointers).
     74            /// Decrements the reference counter (for strong pointers).
    7475            inline void decrementReferenceCount()
    7576            {
     
    8687                { this->destructionListeners_.erase(pointer); }
    8788
    88             int referenceCount_;                                    //!< Counts the references from smart pointers to this object
     89            int referenceCount_;                                    //!< Counts the references from strong pointers to this object
    8990            bool requestedDestruction_;                             //!< Becomes true after someone called delete on this object
    9091            std::set<DestructionListener*> destructionListeners_;   //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies)
  • code/trunk/src/libraries/core/object/Iterator.h

    r9667 r10624  
    7676                @brief Constructor: Sets the element, whereon the iterator points, to zero.
    7777            */
    78             inline Iterator() : IteratorBase<T, Iterator<T> >(NULL) {}
     78            inline Iterator() : IteratorBase<T, Iterator<T> >() {}
    7979
    8080            /**
     
    8888                @param other The other Iterator
    8989            */
    90             inline Iterator(const Iterator<T>& other) : IteratorBase<T, Iterator<T> >(other) {}
     90            inline Iterator(const IteratorBase<T, Iterator<T> >& other) : IteratorBase<T, Iterator<T> >(other) {}
    9191
    9292            /**
  • code/trunk/src/libraries/core/object/IteratorBase.h

    r9667 r10624  
    3737
    3838#include "core/CorePrereqs.h"
     39
     40#include <boost/static_assert.hpp>
     41#include <boost/type_traits/is_base_of.hpp>
    3942
    4043#include "ObjectListBase.h"
     
    4952    class IteratorBase : public ObjectListElementRemovalListener
    5053    {
     54        BOOST_STATIC_ASSERT((boost::is_base_of<Listable, T>::value));
     55
     56        protected:
     57            /**
     58                @brief Constructor: Sets the element, whereon the iterator points, to the given element.
     59                This constructor is protected and only for internal usage (don't mess with the BaseElements directly).
     60            */
     61            inline IteratorBase(ObjectListBaseElement* element = NULL)
     62            {
     63                this->element_ = element;
     64                this->registerIterator();
     65            }
     66
     67
    5168        public:
    5269            /**
    53                 @brief Constructor: Sets the element, whereon the iterator points, to zero.
    54             */
    55             inline IteratorBase(ObjectListBaseElement* element)
    56             {
     70                @brief Constructor: Sets the element, whereon the iterator points, to the given element.
     71            */
     72            inline IteratorBase(ObjectListElement<T>* element)
     73            {
     74                this->element_ = element;
     75                this->registerIterator();
     76            }
     77
     78            /**
     79                @brief Constructor: Sets the element, whereon the iterator points, to the given element of another type.
     80                The element's type O must be a derivative of the Iterator's type T.
     81            */
     82            template <class O>
     83            inline IteratorBase(ObjectListElement<O>* element)
     84            {
     85                (void)static_cast<T*>((O*)NULL); // Check type: The element's type O must be a derivative of the Iterator's type T.
    5786                this->element_ = element;
    5887                this->registerIterator();
  • code/trunk/src/libraries/core/object/Listable.cc

    r9667 r10624  
    3939namespace orxonox
    4040{
    41     RegisterClass(Listable);
     41    RegisterClass(Listable).virtualBase();
    4242
    4343    /**
  • code/trunk/src/libraries/core/object/ObjectList.h

    r9667 r10624  
    4747#include "core/CorePrereqs.h"
    4848
     49#include <boost/static_assert.hpp>
     50#include <boost/type_traits/is_base_of.hpp>
     51
    4952#include "ObjectListBase.h"
    5053#include "ObjectListIterator.h"
     
    6669    class ObjectList
    6770    {
     71        BOOST_STATIC_ASSERT((boost::is_base_of<Listable, T>::value));
     72
    6873        public:
    6974            typedef ObjectListIterator<T> iterator;
    7075
     76            /// Returns the size of the list (for the root context)
     77            inline static size_t size()
     78            {   return size(Context::getRootContext());   }
    7179            /// Returns the size of the list
    72             inline static size_t size()
     80            inline static size_t size(Context* context)
    7381            {
    74                 return Context::getRootContext()->getObjectList<T>()->size();
     82                return context->getObjectList<T>()->size();
    7583            }
    7684
     85            /// Returns an Iterator to the first element in the list (for the root context).
     86            inline static ObjectListElement<T>* begin()
     87            {   return begin(Context::getRootContext());   }
    7788            /// Returns an Iterator to the first element in the list.
    78             inline static ObjectListElement<T>* begin()
     89            inline static ObjectListElement<T>* begin(Context* context)
    7990            {
    80                 ObjectListBase* list = Context::getRootContext()->getObjectList<T>();
     91                ObjectListBase* list = context->getObjectList<T>();
    8192                return static_cast<ObjectListElement<T>*>(list->begin());
    8293            }
    8394
     95            /// Returns an Iterator to the element after the last element in the list (for the root context).
     96            inline static ObjectListElement<T>* end()
     97            {   return end(Context::getRootContext());   }
    8498            /// Returns an Iterator to the element after the last element in the list.
    85             inline static ObjectListElement<T>* end()
     99            inline static ObjectListElement<T>* end(Context* context)
    86100            {
    87                 ObjectListBase* list = Context::getRootContext()->getObjectList<T>();
     101                ObjectListBase* list = context->getObjectList<T>();
    88102                return static_cast<ObjectListElement<T>*>(list->end());
    89103            }
    90104
     105            /// Returns an Iterator to the last element in the list (for the root context).
     106            inline static ObjectListElement<T>* rbegin()
     107            {   return rbegin(Context::getRootContext());   }
    91108            /// Returns an Iterator to the last element in the list.
    92             inline static ObjectListElement<T>* rbegin()
     109            inline static ObjectListElement<T>* rbegin(Context* context)
    93110            {
    94                 ObjectListBase* list = Context::getRootContext()->getObjectList<T>();
     111                ObjectListBase* list = context->getObjectList<T>();
    95112                return static_cast<ObjectListElement<T>*>(list->rbegin());
    96113            }
    97114
     115            /// Returns an Iterator to the element before the first element in the list (for the root context).
     116            inline static ObjectListElement<T>* rend()
     117            {   return rend(Context::getRootContext());   }
    98118            /// Returns an Iterator to the element before the first element in the list.
    99             inline static ObjectListElement<T>* rend()
     119            inline static ObjectListElement<T>* rend(Context* context)
    100120            {
    101                 ObjectListBase* list = Context::getRootContext()->getObjectList<T>();
     121                ObjectListBase* list = context->getObjectList<T>();
    102122                return static_cast<ObjectListElement<T>*>(list->rend());
    103123            }
  • code/trunk/src/libraries/core/object/ObjectListIterator.h

    r9667 r10624  
    7474                @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero.
    7575            */
    76             inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >(NULL) {}
     76            inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >() {}
    7777
    7878            /**
  • code/trunk/src/libraries/core/object/WeakPtr.h

    r9571 r10624  
    104104            }
    105105
    106             /// Constructor: Used to explicitly initialize the weak pointer with a null pointer
    107             inline WeakPtr(int) : pointer_(0), base_(0), callback_(0)
    108             {
    109             }
    110 
    111106            /// Constructor: Initializes the weak pointer with a pointer to an object.
    112107            inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(0)
     
    132127            {
    133128                this->unregisterAsDestructionListener(this->base_);
    134             }
    135 
    136             /// Used to assign a null pointer.
    137             inline WeakPtr& operator=(int)
    138             {
    139                 WeakPtr(0).swap(*this);
    140                 return *this;
    141129            }
    142130
Note: See TracChangeset for help on using the changeset viewer.