Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1682


Ignore:
Timestamp:
Aug 30, 2008, 12:40:27 AM (16 years ago)
Author:
landauf
Message:
  • added several "delete"s to the destructors of some core classes.
  • added Identifier::destroyAllIdentifiers() function, maybe this comes in handy in the future
  • moved XMLPort param and object containers from ClassIdentifier to Identifier
Location:
code/branches/core3/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/core/Identifier.cc

    r1676 r1682  
    3737
    3838#include "Factory.h"
     39#include "ConfigValueContainer.h"
    3940#include "ConsoleCommand.h"
    4041#include "CommandExecutor.h"
     
    7778        delete this->children_;
    7879        delete this->directChildren_;
     80        delete this->objects_;
     81
     82        if (this->factory_)
     83            delete this->factory_;
     84
     85        for (std::map<std::string, ConsoleCommand*>::iterator it = this->consoleCommands_.begin(); it != this->consoleCommands_.end(); ++it)
     86            delete (it->second);
     87        for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it)
     88            delete (it->second);
     89        for (std::map<std::string, XMLPortParamContainer*>::iterator it = this->xmlportParamContainers_.begin(); it != this->xmlportParamContainers_.end(); ++it)
     90            delete (it->second);
     91        for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it)
     92            delete (it->second);
    7993    }
    8094
     
    153167
    154168    /**
     169        @brief Destroys all Identifiers. Called when exiting the program.
     170    */
     171    void Identifier::destroyAllIdentifiers()
     172    {
     173        for (std::map<std::string, Identifier*>::iterator it = Identifier::getIdentifierMapIntern().begin(); it != Identifier::getIdentifierMapIntern().end(); ++it)
     174            delete (it->second);
     175    }
     176
     177    /**
    155178        @brief Sets the name of the class.
    156179        @param name The name
     
    282305        {
    283306            COUT(2) << "Warning: Overwriting config-value with name " << varname << " in class " << this->getName() << "." << std::endl;
     307            delete (it->second);
    284308        }
    285309
     
    329353        {
    330354            COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << "." << std::endl;
     355            delete (it->second);
    331356        }
    332357
     
    367392        else
    368393            return 0;
     394    }
     395
     396    /**
     397        @brief Returns a XMLPortParamContainer that loads a parameter of this class.
     398        @param paramname The name of the parameter
     399        @return The container
     400    */
     401    XMLPortParamContainer* Identifier::getXMLPortParamContainer(const std::string& paramname)
     402    {
     403        std::map<std::string, XMLPortParamContainer*>::const_iterator it = xmlportParamContainers_.find(paramname);
     404        if (it != xmlportParamContainers_.end())
     405            return ((*it).second);
     406        else
     407            return 0;
     408    }
     409
     410    /**
     411        @brief Adds a new XMLPortParamContainer that loads a parameter of this class.
     412        @param paramname The name of the parameter
     413        @param container The container
     414    */
     415    void Identifier::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container)
     416    {
     417        this->xmlportParamContainers_[paramname] = container;
     418    }
     419
     420    /**
     421        @brief Returns a XMLPortObjectContainer that attaches an object to this class.
     422        @param sectionname The name of the section that contains the attachable objects
     423        @return The container
     424    */
     425    XMLPortObjectContainer* Identifier::getXMLPortObjectContainer(const std::string& sectionname)
     426    {
     427        std::map<std::string, XMLPortObjectContainer*>::const_iterator it = xmlportObjectContainers_.find(sectionname);
     428        if (it != xmlportObjectContainers_.end())
     429            return ((*it).second);
     430        else
     431            return 0;
     432    }
     433
     434    /**
     435        @brief Adds a new XMLPortObjectContainer that attaches an object to this class.
     436        @param sectionname The name of the section that contains the attachable objects
     437        @param container The container
     438    */
     439    void Identifier::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container)
     440    {
     441        this->xmlportObjectContainers_[sectionname] = container;
    369442    }
    370443
  • code/branches/core3/src/core/Identifier.h

    r1676 r1682  
    208208            ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
    209209
    210             virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0;
    211             virtual XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname) = 0;
    212 
    213             virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0;
    214             virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0;
     210            void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container);
     211            XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
     212
     213            void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container);
     214            XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
    215215
    216216            ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);
     
    259259                COUT(4) << "*** Identifier: Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
    260260            }
     261
     262            static void destroyAllIdentifiers();
    261263
    262264            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
     
    279281            std::map<std::string, ConsoleCommand*> consoleCommands_;       //!< All console commands of this class
    280282            std::map<std::string, ConsoleCommand*> consoleCommands_LC_;    //!< All console commands of this class with their names in lowercase
     283
     284            std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_;     //!< All loadable parameters
     285            std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_;   //!< All attachable objects
    281286    };
    282287
     
    310315
    311316            void updateConfigValues(bool updateChildren = true) const;
    312 
     317/*
    313318            XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
    314319            void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container);
     
    316321            XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
    317322            void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container);
    318 
     323*/
    319324        private:
     325            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    320326            ClassIdentifier()
    321327            {
     
    323329                #include "Super.h"
    324330            }
    325             ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    326             ~ClassIdentifier() {}                                       // don't delete
    327 
     331            ~ClassIdentifier()
     332            {
     333                #define SUPER_INTRUSIVE_DESTRUCTOR
     334                #include "Super.h"
     335/*
     336                for (std::map<std::string, XMLPortParamContainer*>::iterator it = this->xmlportParamContainers_.begin(); it != this->xmlportParamContainers_.end(); ++it)
     337                    delete (it->second);
     338                for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it)
     339                    delete (it->second);
     340*/
     341            }
     342/*
    328343            std::map<std::string, XMLPortClassParamContainer<class O>*> xmlportParamContainers_;              //!< All loadable parameters
    329344            std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_;   //!< All attachable objects
    330 
     345*/
    331346            static ClassIdentifier<T> *classIdentifier_s;
    332347    };
     
    453468        @param paramname The name of the parameter
    454469        @return The container
    455     */
     470    *//*
    456471    template <class T>
    457472    XMLPortParamContainer* ClassIdentifier<T>::getXMLPortParamContainer(const std::string& paramname)
     
    462477        else
    463478            return 0;
    464     }
     479    }*/
    465480
    466481    /**
     
    468483        @param paramname The name of the parameter
    469484        @param container The container
    470     */
     485    *//*
    471486    template <class T>
    472487    void ClassIdentifier<T>::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container)
    473488    {
    474489        this->xmlportParamContainers_[paramname] = (XMLPortClassParamContainer<class O>*)container;
    475     }
     490    }*/
    476491
    477492    /**
     
    479494        @param sectionname The name of the section that contains the attachable objects
    480495        @return The container
    481     */
     496    *//*
    482497    template <class T>
    483498    XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname)
     
    488503        else
    489504            return 0;
    490     }
     505    }*/
    491506
    492507    /**
     
    494509        @param sectionname The name of the section that contains the attachable objects
    495510        @param container The container
    496     */
     511    *//*
    497512    template <class T>
    498513    void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container)
    499514    {
    500515        this->xmlportObjectContainers_[sectionname] = (XMLPortClassObjectContainer<T, class O>*)container;
    501     }
     516    }*/
    502517
    503518
  • code/branches/core3/src/core/Language.cc

    r1586 r1682  
    9797        // Read the default language file to create all known LanguageEntry objects
    9898        this->readDefaultLanguageFile();
     99    }
     100
     101    /**
     102        @brief Destructor: Deletes all language entries.
     103    */
     104    Language::~Language()
     105    {
     106        for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
     107            delete (it->second);
    99108    }
    100109
  • code/branches/core3/src/core/Language.h

    r1535 r1682  
    123123            Language();
    124124            Language(const Language& language);     // don't copy
    125             virtual ~Language() {};                 // don't delete
     125            virtual ~Language();
    126126
    127127            void readDefaultLanguageFile();
  • code/branches/core3/src/core/Super.h

    r1679 r1682  
    127127    #undef SUPER_INTRUSIVE_CONSTRUCTOR
    128128  #endif /* SUPER_INTRUSIVE_CONSTRUCTOR */
     129
     130  #ifdef SUPER_INTRUSIVE_DESTRUCTOR
     131
     132////////////////////////////
     133// Function-specific code //
     134////////////////////////////
     135
     136if (this->superFunctionCaller_testfunction_)
     137    delete this->superFunctionCaller_testfunction_;
     138
     139    #undef SUPER_INTRUSIVE_DESTRUCTOR
     140  #endif /* SUPER_INTRUSIVE_DESTRUCTOR */
    129141#endif /* _Super_H__ */
  • code/branches/core3/src/core/TclThreadManager.cc

    r1594 r1682  
    7272    }
    7373
     74    TclThreadManager::~TclThreadManager()
     75    {
     76        unsigned int threadID;
     77        {
     78            boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
     79            if (this->interpreterBundles_.begin() == this->interpreterBundles_.end())
     80                return;
     81            else
     82                threadID = this->interpreterBundles_.begin()->first;
     83        }
     84        this->destroy(threadID);
     85    }
     86
    7487    TclThreadManager& TclThreadManager::getInstance()
    7588    {
  • code/branches/core3/src/core/TclThreadManager.h

    r1535 r1682  
    7171    class _CoreExport TclThreadManager : public OrxonoxClass
    7272    {
     73        friend class IRC;
     74        friend class TclBind;
     75
    7376        public:
    7477            static TclThreadManager& getInstance();
     
    8386            static void flush(unsigned int threadID);
    8487
     88            void error(const std::string& error);
     89            void debug(const std::string& error);
     90
     91            virtual void tick(float dt);
     92
     93            std::list<unsigned int> getThreadList() const;
     94
     95        private:
     96            TclThreadManager();
     97            TclThreadManager(const TclThreadManager& other);
     98            ~TclThreadManager();
     99
    85100            static void tcl_execute(Tcl::object const &args);
    86101            static std::string tcl_query(int querierID, Tcl::object const &args);
     
    91106            TclInterpreterBundle* getInterpreterBundle(unsigned int threadID);
    92107            std::string dumpList(const std::list<unsigned int>& list);
    93             void error(const std::string& error);
    94             void debug(const std::string& error);
    95108
    96109            void pushCommandToQueue(const std::string& command);
     
    107120            std::string evalQuery(unsigned int querierID, const std::string& command);
    108121            std::string evalQuery(unsigned int querierID, unsigned int threadID, const std::string& command);
    109 
    110             virtual void tick(float dt);
    111 
    112             std::list<unsigned int> getThreadList() const;
    113 
    114         private:
    115             TclThreadManager();
    116             TclThreadManager(const TclThreadManager& other);
    117             ~TclThreadManager() {}
    118122
    119123            unsigned int threadCounter_;
  • code/branches/core3/src/orxonox/objects/Projectile.h

    r1681 r1682  
    9797            ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
    9898
     99/*
    99100            SuperFunctionCaller_testfunction* superFunctionCaller = 0;
    100101            // Search for an existing caller within all direct children
     
    105106            if (!superFunctionCaller)
    106107                superFunctionCaller = new SuperFunctionClassCaller_testfunction<T>;
     108*/
    107109            // Iterate through all children and assign the caller
    108110            for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)
     
    111113                {
    112114                    std::cout << "adding functionpointer to " << ((ClassIdentifier<T>*)(*it))->getName() << std::endl;
    113                     ((ClassIdentifier<T>*)(*it))->superFunctionCaller_testfunction_ = superFunctionCaller;
     115//                    ((ClassIdentifier<T>*)(*it))->superFunctionCaller_testfunction_ = superFunctionCaller;
     116                    ((ClassIdentifier<T>*)(*it))->superFunctionCaller_testfunction_ = new SuperFunctionClassCaller_testfunction<T>;
    114117                }
    115118            }
Note: See TracChangeset for help on using the changeset viewer.