Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 7, 2015, 12:10:24 PM (9 years ago)
Author:
landauf
Message:

destroy objects before deleting identifiers (when unloading a module)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/class/Identifier.h

    r10537 r10539  
    152152            inline bool isInitialized() const { return this->bInitialized_; }
    153153
     154            virtual void destroyObjects() = 0;
     155
     156            virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const = 0;
     157
     158            static bool initConfigValues_s; // TODO: this is a hack - remove it as soon as possible
     159
    154160
    155161            /////////////////////////////
     
    215221            XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
    216222
    217             virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const = 0;
    218 
    219             static bool initConfigValues_s; // TODO: this is a hack - remove it as soon as possible
    220 
    221223        protected:
    222224            virtual void createSuperFunctionCaller() const = 0;
     
    297299                { return dynamic_cast<T*>(object) != 0; }
    298300
     301            virtual void destroyObjects();
     302
    299303            static ClassIdentifier<T>* getIdentifier();
    300304
     
    307311            void addObjectToList(T* object, Listable*);
    308312            void addObjectToList(T* object, Identifiable*);
     313
     314            void destroyObjects(Listable*);
     315            void destroyObjects(void*);
     316
     317            void destroyObject(Destroyable* object);
     318            void destroyObject(void* object);
    309319
    310320            void updateConfigValues(bool updateChildren, Listable*) const;
     
    389399    {
    390400        // no action
     401    }
     402
     403    /**
     404     * @brief Destroy all objects of this class (must be Listable).
     405     * Destroyables are destroyed with destroy(), all other classes with delete.
     406     */
     407    template <class T>
     408    void ClassIdentifier<T>::destroyObjects()
     409    {
     410        this->destroyObjects((T*)0);
     411    }
     412
     413    /**
     414     * @brief Only searches and destroys objects if is a @ref Listable
     415     */
     416    template <class T>
     417    void ClassIdentifier<T>::destroyObjects(Listable*)
     418    {
     419        ObjectListBase* objectList = Context::getRootContext()->getObjectList(this);
     420        ObjectListElement<T>* begin = static_cast<ObjectListElement<T>*>(objectList->begin());
     421        ObjectListElement<T>* end = static_cast<ObjectListElement<T>*>(objectList->end());
     422        for (typename ObjectList<T>::iterator it = begin; it != end; )
     423            this->destroyObject(*(it++));
     424    }
     425
     426    template <class T>
     427    void ClassIdentifier<T>::destroyObjects(void*)
     428    {
     429        // no action
     430    }
     431
     432    /**
     433     * @brief Call 'object->destroy()' for Destroyables and 'delete object' for all other types.
     434     */
     435    template <class T>
     436    void ClassIdentifier<T>::destroyObject(Destroyable* object)
     437    {
     438        object->destroy();
     439    }
     440
     441    template <class T>
     442    void ClassIdentifier<T>::destroyObject(void* object)
     443    {
     444        delete static_cast<Identifiable*>(object);
    391445    }
    392446
Note: See TracChangeset for help on using the changeset viewer.