Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (9 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/class/Identifiable.cc

    r10624 r11071  
    4848    Identifiable::Identifiable()
    4949    {
    50         this->identifier_ = 0;
     50        this->identifier_ = nullptr;
    5151        this->objectPointers_.reserve(6); // Optimisation
    5252
  • code/trunk/src/libraries/core/class/Identifiable.h

    r9667 r11071  
    9898                registered in the class hierarchy.
    9999            @return
    100                 Returns NULL if the no pointer was found.
     100                Returns nullptr if the no pointer was found.
    101101            */
    102102            ORX_FORCEINLINE void* getDerivedPointer(unsigned int classID)
     
    107107                        return this->objectPointers_[i].second;
    108108                }
    109                 return NULL;
     109                return nullptr;
    110110            }
    111111
     
    121121
    122122            /// 'Fast map' that holds this-pointers of all derived types
    123             std::vector<std::pair<unsigned int, void*> > objectPointers_;
     123            std::vector<std::pair<unsigned int, void*>> objectPointers_;
    124124    };
    125125}
  • code/trunk/src/libraries/core/class/Identifier.cc

    r10624 r11071  
    7979            delete this->factory_;
    8080
    81         for (std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it)
    82             delete (*it);
     81        for (const InheritsFrom* manualDirectParent : this->manualDirectParents_)
     82            delete manualDirectParent;
    8383
    8484        // erase this Identifier from all related identifiers
    85         for (std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
    86             const_cast<Identifier*>(*it)->children_.erase(this);
    87         for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
    88             const_cast<Identifier*>(*it)->directChildren_.erase(this);
    89         for (std::set<const Identifier*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it)
    90             const_cast<Identifier*>(*it)->parents_.remove(this);
    91         for (std::set<const Identifier*>::const_iterator it = this->directChildren_.begin(); it != this->directChildren_.end(); ++it)
    92             const_cast<Identifier*>(*it)->directParents_.remove(this);
    93 
    94         for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it)
    95             delete (it->second);
    96         for (std::map<std::string, XMLPortParamContainer*>::iterator it = this->xmlportParamContainers_.begin(); it != this->xmlportParamContainers_.end(); ++it)
    97             delete (it->second);
    98         for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it)
    99             delete (it->second);
     85        for (const Identifier* parent : this->parents_)
     86            const_cast<Identifier*>(parent)->children_.erase(this);
     87        for (const Identifier* directParent : this->directParents_)
     88            const_cast<Identifier*>(directParent)->directChildren_.erase(this);
     89        for (const Identifier* child : this->children_)
     90            const_cast<Identifier*>(child)->parents_.remove(this);
     91        for (const Identifier* directChild : this->directChildren_)
     92            const_cast<Identifier*>(directChild)->directParents_.remove(this);
     93
     94        for (const auto& mapEntry : this->configValues_)
     95            delete (mapEntry.second);
     96        for (const auto& mapEntry : this->xmlportParamContainers_)
     97            delete (mapEntry.second);
     98        for (const auto& mapEntry : this->xmlportObjectContainers_)
     99            delete (mapEntry.second);
    100100    }
    101101
     
    117117            orxout(user_error) << "Aborting..." << endl;
    118118            abort();
    119             return 0;
     119            return nullptr;
    120120        }
    121121    }
     
    157157        if (this->directParents_.empty())
    158158        {
    159             for (std::list<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it)
    160                 if (*it != this)
    161                     this->parents_.push_back(*it);
     159            for (const Identifier* identifier : initializationTrace)
     160                if (identifier != this)
     161                    this->parents_.push_back(identifier);
    162162        }
    163163        else
     
    184184
    185185            // initialize all parents
    186             for (std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
    187                 const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent
     186            for (const Identifier* parent : this->parents_)
     187                const_cast<Identifier*>(parent)->finishInitialization(); // initialize parent
    188188
    189189            // parents of parents are no direct parents of this identifier
    190190            this->directParents_ = this->parents_;
    191             for (std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)
    192                 for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)
    193                     this->directParents_.remove(*it_parent_parent);
     191            for (const Identifier* parent : this->parents_)
     192                for (const Identifier* parent_parent : const_cast<Identifier*>(parent)->parents_)
     193                    this->directParents_.remove(parent_parent);
    194194
    195195            this->verifyIdentifierTrace();
     
    200200
    201201            // initialize all direct parents
    202             for (std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it)
     202            for (const InheritsFrom* manualDirectParent : this->manualDirectParents_)
    203203            {
    204                 Identifier* directParent = (*it)->getParent();
     204                Identifier* directParent = manualDirectParent->getParent();
    205205                this->directParents_.push_back(directParent);
    206206                directParent->finishInitialization(); // initialize parent
     
    208208
    209209            // direct parents and their parents are also parents of this identifier (but only add them once)
    210             for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)
     210            for (const Identifier* parent : this->directParents_)
    211211            {
    212                 for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)
    213                     this->addIfNotExists(this->parents_, *it_parent_parent);
    214                 this->addIfNotExists(this->parents_, *it_parent);
     212                for (const Identifier* parent_parent : const_cast<Identifier*>(parent)->parents_)
     213                    this->addIfNotExists(this->parents_, parent_parent);
     214                this->addIfNotExists(this->parents_, parent);
    215215            }
    216216        }
     
    224224
    225225        // tell all parents that this identifier is a child
    226         for (std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
    227             const_cast<Identifier*>(*it)->children_.insert(this);
     226        for (const Identifier* parent : this->parents_)
     227            const_cast<Identifier*>(parent)->children_.insert(this);
    228228
    229229        // tell all direct parents that this identifier is a direct child
    230         for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
    231         {
    232             const_cast<Identifier*>(*it)->directChildren_.insert(this);
     230        for (const Identifier* directChild : this->directParents_)
     231        {
     232            const_cast<Identifier*>(directChild)->directChildren_.insert(this);
    233233
    234234            // Create the super-function dependencies
    235             (*it)->createSuperFunctionCaller();
     235            directChild->createSuperFunctionCaller();
    236236        }
    237237
     
    261261
    262262        // if any parent class is virtual, it will be instantiated first, so we need to add them first.
    263         for (std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)
    264         {
    265             if ((*it_parent)->isVirtualBase())
     263        for (const Identifier* parent : this->parents_)
     264        {
     265            if (parent->isVirtualBase())
    266266            {
    267                 for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)
    268                     this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent);
    269                 this->addIfNotExists(expectedIdentifierTrace, *it_parent);
     267                for (const Identifier* parent_parent : const_cast<Identifier*>(parent)->parents_)
     268                    this->addIfNotExists(expectedIdentifierTrace, parent_parent);
     269                this->addIfNotExists(expectedIdentifierTrace, parent);
    270270            }
    271271        }
    272272
    273273        // now all direct parents get created recursively. already added identifiers (e.g. virtual base classes) are not added again.
    274         for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)
    275         {
    276             for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)
    277                 this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent);
    278             this->addIfNotExists(expectedIdentifierTrace, *it_parent);
     274        for (const Identifier* directParent : this->directParents_)
     275        {
     276            for (const Identifier* parent_parent : const_cast<Identifier*>(directParent)->parents_)
     277                this->addIfNotExists(expectedIdentifierTrace, parent_parent);
     278            this->addIfNotExists(expectedIdentifierTrace, directParent);
    279279        }
    280280
     
    285285
    286286            orxout(internal_warning) << "  Actual trace (after creating a sample instance):" << endl << "    ";
    287             for (std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)
    288                 orxout(internal_warning) << " " << (*it_parent)->getName();
     287            for (const Identifier* parent : this->parents_)
     288                orxout(internal_warning) << " " << parent->getName();
    289289            orxout(internal_warning) << endl;
    290290
    291291            orxout(internal_warning) << "  Expected trace (according to class hierarchy definitions):" << endl << "    ";
    292             for (std::list<const Identifier*>::const_iterator it_parent = expectedIdentifierTrace.begin(); it_parent != expectedIdentifierTrace.end(); ++it_parent)
    293                 orxout(internal_warning) << " " << (*it_parent)->getName();
     292            for (const Identifier* parent : expectedIdentifierTrace)
     293                orxout(internal_warning) << " " << parent->getName();
    294294            orxout(internal_warning) << endl;
    295295
    296296            orxout(internal_warning) << "  Direct parents (according to class hierarchy definitions):" << endl << "    ";
    297             for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)
    298                 orxout(internal_warning) << " " << (*it_parent)->getName();
     297            for (const Identifier* directParent : this->directParents_)
     298                orxout(internal_warning) << " " << directParent->getName();
    299299            orxout(internal_warning) << endl;
    300300        }
     
    393393            return it->second;
    394394        else
    395             return 0;
     395            return nullptr;
    396396    }
    397397
     
    407407            return it->second;
    408408        else
    409             return 0;
     409            return nullptr;
    410410    }
    411411
     
    438438            return it->second;
    439439        else
    440             return 0;
     440            return nullptr;
    441441    }
    442442
  • code/trunk/src/libraries/core/class/Identifier.h

    r10624 r11071  
    5656    object->getIdentifier()->getName();                                         // returns "MyClass"
    5757
    58     Identifiable* other = object->getIdentifier()->fabricate(0);                // fabricates a new instance of MyClass
     58    Identifiable* other = object->getIdentifier()->fabricate(nullptr);                // fabricates a new instance of MyClass
    5959
    6060
     
    8080#include <typeinfo>
    8181#include <loki/TypeTraits.h>
    82 #include <boost/static_assert.hpp>
    83 #include <boost/type_traits/is_base_of.hpp>
    8482
    8583#include "util/Output.h"
     
    120118        public:
    121119            Identifier(const std::string& name, Factory* factory, bool bLoadable);
    122             Identifier(const Identifier& identifier); // don't copy
    123120            virtual ~Identifier();
     121
     122            // non-copyable:
     123            Identifier(const Identifier&) = delete;
     124            Identifier& operator=(const Identifier&) = delete;
    124125
    125126            /// Returns the name of the class the Identifier belongs to.
     
    137138
    138139            /// Returns true if the Identifier has a Factory.
    139             inline bool hasFactory() const { return (this->factory_ != 0); }
     140            inline bool hasFactory() const { return (this->factory_ != nullptr); }
    140141
    141142            Identifiable* fabricate(Context* context);
     
    203204            /// Returns the map that stores all XMLPort params.
    204205            inline const std::map<std::string, XMLPortParamContainer*>& getXMLPortParamMap() const { return this->xmlportParamContainers_; }
    205             /// Returns a const_iterator to the beginning of the map that stores all XMLPort params.
    206             inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapBegin() const { return this->xmlportParamContainers_.begin(); }
    207             /// Returns a const_iterator to the end of the map that stores all XMLPort params.
    208             inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapEnd() const { return this->xmlportParamContainers_.end(); }
    209206
    210207            /// Returns the map that stores all XMLPort objects.
    211208            inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortObjectMap() const { return this->xmlportObjectContainers_; }
    212             /// Returns a const_iterator to the beginning of the map that stores all XMLPort objects.
    213             inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapBegin() const { return this->xmlportObjectContainers_.begin(); }
    214             /// Returns a const_iterator to the end of the map that stores all XMLPort objects.
    215             inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); }
    216209
    217210            void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container);
     
    269262    class ClassIdentifier : public Identifier
    270263    {
    271         BOOST_STATIC_ASSERT((boost::is_base_of<Identifiable, T>::value));
     264        static_assert(std::is_base_of<Identifiable, T>::value, "ClassIdentifier can only be used with Identifiables");
    272265
    273266        #ifndef DOXYGEN_SHOULD_SKIP_THIS
     
    279272            ClassIdentifier(const std::string& name, Factory* factory, bool bLoadable) : Identifier(name, factory, bLoadable)
    280273            {
    281                 OrxVerify(ClassIdentifier<T>::classIdentifier_s == NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name());
     274                OrxVerify(ClassIdentifier<T>::classIdentifier_s == nullptr, "Assertion failed in ClassIdentifier of type " << typeid(T).name());
    282275                ClassIdentifier<T>::classIdentifier_s = this;
    283276
     
    291284            bool initializeObject(T* object);
    292285
    293             virtual void updateConfigValues(bool updateChildren = true) const;
    294 
    295             virtual const std::type_info& getTypeInfo()
     286            virtual void updateConfigValues(bool updateChildren = true) const override;
     287
     288            virtual const std::type_info& getTypeInfo() override
    296289                { return typeid(T); }
    297290
    298             virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const
    299                 { return dynamic_cast<T*>(object) != 0; }
    300 
    301             virtual void destroyObjects();
     291            virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const override
     292                { return dynamic_cast<T*>(object) != nullptr; }
     293
     294            virtual void destroyObjects() override;
    302295
    303296            static ClassIdentifier<T>* getIdentifier();
    304297
    305298        private:
    306             ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
     299            // non-copyable:
     300            ClassIdentifier(const ClassIdentifier<T>&) = delete;
     301            ClassIdentifier& operator=(const ClassIdentifier<T>&) = delete;
    307302
    308303            void setConfigValues(T* object, Configurable*) const;
     
    321316            void updateConfigValues(bool updateChildren, Identifiable*) const;
    322317
    323             static WeakPtr<ClassIdentifier<T> > classIdentifier_s;
     318            static WeakPtr<ClassIdentifier<T>> classIdentifier_s;
    324319    };
    325320
    326321    template <class T>
    327     WeakPtr<ClassIdentifier<T> > ClassIdentifier<T>::classIdentifier_s;
     322    WeakPtr<ClassIdentifier<T>> ClassIdentifier<T>::classIdentifier_s;
    328323
    329324    /**
     
    334329    /*static*/ inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
    335330    {
    336         if (ClassIdentifier<T>::classIdentifier_s == NULL)
     331        if (ClassIdentifier<T>::classIdentifier_s == nullptr)
    337332            ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*) IdentifierManager::getInstance().getIdentifierByTypeInfo(typeid(T));
    338333
    339         OrxVerify(ClassIdentifier<T>::classIdentifier_s != NULL, "Did you forget to register the class of type " << typeid(T).name() << "?");
     334        OrxVerify(ClassIdentifier<T>::classIdentifier_s != nullptr, "Did you forget to register the class of type " << typeid(T).name() << "?");
    340335        return ClassIdentifier<T>::classIdentifier_s;
    341336    }
     
    365360
    366361            // Add pointer of type T to the map in the Identifiable instance that enables "dynamic_casts"
    367             object->objectPointers_.push_back(std::make_pair(this->getClassID(), static_cast<void*>(object)));
     362            object->objectPointers_.emplace_back(this->getClassID(), static_cast<void*>(object));
    368363            return false;
    369364        }
     
    408403    void ClassIdentifier<T>::destroyObjects()
    409404    {
    410         this->destroyObjects((T*)0);
     405        this->destroyObjects((T*)nullptr);
    411406    }
    412407
     
    417412    void ClassIdentifier<T>::destroyObjects(Listable*)
    418413    {
    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; )
     414        ObjectList<T> list(Context::getRootContext()->getObjectList(this));
     415        for (typename ObjectList<T>::iterator it = list.begin(); it != list.end(); )
    423416            this->destroyObject(*(it++));
    424417    }
     
    451444    void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const
    452445    {
    453         this->updateConfigValues(updateChildren, static_cast<T*>(NULL));
     446        this->updateConfigValues(updateChildren, static_cast<T*>(nullptr));
    454447    }
    455448
     
    460453            return;
    461454
    462         for (ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it)
    463             this->setConfigValues(*it, *it);
     455        for (T* object : ObjectList<T>())
     456            this->setConfigValues(object, object);
    464457
    465458        if (updateChildren)
    466             for (std::set<const Identifier*>::const_iterator it = this->getChildren().begin(); it != this->getChildren().end(); ++it)
    467                 (*it)->updateConfigValues(false);
     459            for (const Identifier* child : this->getChildren())
     460                child->updateConfigValues(false);
    468461    }
    469462
     
    483476        registered in the class hierarchy.
    484477    @return
    485         Returns NULL if the cast is not possible
     478        Returns nullptr if the cast is not possible
    486479    @note
    487         In case of NULL return (and using MSVC), a dynamic_cast might still be possible if
     480        In case of nullptr return (and using MSVC), a dynamic_cast might still be possible if
    488481        a class forgot to register its objects.
    489482        Also note that the function is implemented differently for GCC/MSVC.
     
    494487#ifdef ORXONOX_COMPILER_MSVC
    495488        typedef Loki::TypeTraits<typename Loki::TypeTraits<T>::PointeeType>::NonConstType ClassType;
    496         if (source != NULL)
     489        if (source != nullptr)
    497490            return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID());
    498491        else
    499             return NULL;
     492            return nullptr;
    500493#else
    501494        return dynamic_cast<T>(source);
  • code/trunk/src/libraries/core/class/IdentifierManager.cc

    r10624 r11071  
    4444namespace orxonox
    4545{
    46     IdentifierManager* IdentifierManager::singletonPtr_s = 0;
     46    IdentifierManager* IdentifierManager::singletonPtr_s = nullptr;
    4747
    4848    IdentifierManager::IdentifierManager()
    4949    {
    5050        this->hierarchyCreatingCounter_s = 0;
    51         this->recordTraceForIdentifier_ = NULL;
     51        this->recordTraceForIdentifier_ = nullptr;
    5252    }
    5353
     
    6060
    6161        this->identifiers_.insert(identifier);
     62        this->identifierByTypeIndex_[identifier->getTypeInfo()] = identifier;
    6263        this->identifierByString_[identifier->getName()] = identifier;
    6364        this->identifierByLowercaseString_[getLowercase(identifier->getName())] = identifier;
     
    7172    {
    7273        this->identifiers_.erase(identifier);
     74        this->identifierByTypeIndex_.erase(identifier->getTypeInfo());
    7375        this->identifierByString_.erase(identifier->getName());
    7476        this->identifierByLowercaseString_.erase(getLowercase(identifier->getName()));
     
    9294        // iterate over all identifiers, create one instance of each class and initialize the identifiers
    9395        {
    94             Context temporaryContext(NULL);
    95             for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
     96            Context temporaryContext(nullptr);
     97            for (Identifier* identifier : this->identifiers_)
    9698            {
    97                 Identifier* identifier = (*it);
    9899                if (identifier->isInitialized())
    99100                    continue;
     
    108109                    Identifiable* temp = identifier->fabricate(&temporaryContext);
    109110
    110                     this->recordTraceForIdentifier_ = NULL;
     111                    this->recordTraceForIdentifier_ = nullptr;
    111112
    112113                    if (temp->getIdentifier() != identifier)
     
    127128
    128129        // finish the initialization of all identifiers
    129         for (std::set<Identifier*>::const_iterator it = initializedIdentifiers.begin(); it != initializedIdentifiers.end(); ++it)
    130             (*it)->finishInitialization();
     130        for (Identifier* initializedIdentifier : initializedIdentifiers)
     131            initializedIdentifier->finishInitialization();
    131132
    132133        // only check class hierarchy in dev mode because it's an expensive operation and it requires a developer to fix detected problems anyway.
     
    144145    {
    145146        // check if there are any uninitialized identifiers remaining
    146         for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
    147             if (!(*it)->isInitialized())
    148                 orxout(internal_error) << "Identifier was registered late and is not initialized: " << (*it)->getName() << " / " << (*it)->getTypeInfo().name() << endl;
     147        for (Identifier* identifier : this->identifiers_)
     148            if (!identifier->isInitialized())
     149                orxout(internal_error) << "Identifier was registered late and is not initialized: " << identifier->getName() << " / " << identifier->getTypeInfo().name() << endl;
    149150
    150151        // for all initialized identifiers, check if a sample instance behaves as expected according to the class hierarchy
    151         Context temporaryContext(NULL);
    152         for (std::set<Identifier*>::const_iterator it1 = initializedIdentifiers.begin(); it1 != initializedIdentifiers.end(); ++it1)
     152        Context temporaryContext(nullptr);
     153        for (Identifier* initializedIdentifier : initializedIdentifiers)
    153154        {
    154             if (!(*it1)->hasFactory())
     155            if (!initializedIdentifier->hasFactory())
    155156                continue;
    156157
    157             Identifiable* temp = (*it1)->fabricate(&temporaryContext);
    158 
    159             for (std::set<Identifier*>::const_iterator it2 = this->identifiers_.begin(); it2 != this->identifiers_.end(); ++it2)
     158            Identifiable* temp = initializedIdentifier->fabricate(&temporaryContext);
     159
     160            for (Identifier* identifier : this->identifiers_)
    160161            {
    161                 bool isA_AccordingToRtti = (*it2)->canDynamicCastObjectToIdentifierClass(temp);
    162                 bool isA_AccordingToClassHierarchy = temp->isA((*it2));
     162                bool isA_AccordingToRtti = identifier->canDynamicCastObjectToIdentifierClass(temp);
     163                bool isA_AccordingToClassHierarchy = temp->isA(identifier);
    163164
    164165                if (isA_AccordingToRtti != isA_AccordingToClassHierarchy)
    165166                {
    166                     orxout(internal_error) << "Class hierarchy does not match RTTI: Class hierarchy claims that " << (*it1)->getName() <<
    167                         (isA_AccordingToClassHierarchy ? " is a " : " is not a ") << (*it2)->getName() << " but RTTI says the opposite." << endl;
     167                    orxout(internal_error) << "Class hierarchy does not match RTTI: Class hierarchy claims that " << initializedIdentifier->getName() <<
     168                        (isA_AccordingToClassHierarchy ? " is a " : " is not a ") << identifier->getName() << " but RTTI says the opposite." << endl;
    168169                }
    169170            }
     
    184185    {
    185186        orxout(internal_status) << "Destroy class-hierarchy" << endl;
    186         for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
    187             (*it)->reset();
     187        for (Identifier* identifier : this->identifiers_)
     188            identifier->reset();
    188189    }
    189190
     
    221222            return it->second;
    222223        else
    223             return 0;
     224            return nullptr;
    224225    }
    225226
     
    235236            return it->second;
    236237        else
    237             return 0;
     238            return nullptr;
    238239    }
    239240
     
    249250            return it->second;
    250251        else
    251             return 0;
     252            return nullptr;
    252253    }
    253254
     
    259260    Identifier* IdentifierManager::getIdentifierByTypeInfo(const std::type_info& typeInfo)
    260261    {
    261         // TODO: use std::type_index and a map to find identifiers by type_info (only with c++11)
    262         for (std::set<Identifier*>::iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
    263             if ((*it)->getTypeInfo() == typeInfo)
    264                 return (*it);
    265         return 0;
     262        auto it = this->identifierByTypeIndex_.find(typeInfo);
     263        if (it != this->identifierByTypeIndex_.end())
     264            return it->second;
     265        else
     266            return nullptr;
    266267    }
    267268
  • code/trunk/src/libraries/core/class/IdentifierManager.h

    r10624 r11071  
    3737#include "core/CorePrereqs.h"
    3838
     39#include <typeindex>
    3940#include <map>
     41#include <unordered_map>
    4042#include <set>
    4143#include <list>
     
    5254        public:
    5355            IdentifierManager();
    54             ~IdentifierManager() {}
     56            ~IdentifierManager() = default;
    5557
    5658            void addIdentifier(Identifier* identifier);
     
    9395
    9496        private:
    95             IdentifierManager(const IdentifierManager&); // not implemented
     97            // non-copyable:
     98            IdentifierManager(const IdentifierManager&) = delete;
     99            IdentifierManager& operator=(const IdentifierManager&) = delete;
    96100
    97101            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
     
    102106                { hierarchyCreatingCounter_s--; }
    103107
    104             std::set<Identifier*> identifiers_;                              //!< All identifiers. This is only used internally.
    105             std::map<std::string, Identifier*> identifierByString_;          //!< Map that stores all Identifiers with their names.
    106             std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase.
    107             std::map<uint32_t, Identifier*> identifierByNetworkId_;          //!< Returns the map that stores all Identifiers with their network IDs.
     108            std::set<Identifier*> identifiers_;                                      //!< All identifiers. This is only used internally.
     109            std::unordered_map<std::type_index, Identifier*> identifierByTypeIndex_; //!< Map that stores all Identifiers with their type_index.
     110            std::map<std::string, Identifier*> identifierByString_;                  //!< Map that stores all Identifiers with their names.
     111            std::map<std::string, Identifier*> identifierByLowercaseString_;         //!< Map that stores all Identifiers with their names in lowercase.
     112            std::map<uint32_t, Identifier*> identifierByNetworkId_;                  //!< Returns the map that stores all Identifiers with their network IDs.
    108113
    109114            int hierarchyCreatingCounter_s;                         //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
     
    111116            /// Used while creating the object hierarchy to keep track of the identifiers of a newly created object (and all other objects that get created as
    112117            /// a consequence of this, e.g. nested member objects).
    113             std::map<Identifiable*, std::list<const Identifier*> > identifierTraceOfNewObject_;
     118            std::map<Identifiable*, std::list<const Identifier*>> identifierTraceOfNewObject_;
    114119            Identifier* recordTraceForIdentifier_; //!< The identifier for which we want to record the trace of identifiers during object creation. If null, no trace is recorded.
    115120
  • code/trunk/src/libraries/core/class/SubclassIdentifier.h

    r9667 r11071  
    127127                    else
    128128                    {
    129                         orxout(internal_error) << "Can't assign NULL identifier" << endl;
     129                        orxout(internal_error) << "Can't assign nullptr identifier" << endl;
    130130                    }
    131131                }
     
    189189                    orxout(user_error) << "Aborting..." << endl;
    190190                    abort();
    191                     return 0;
     191                    return nullptr;
    192192                }
    193193            }
  • code/trunk/src/libraries/core/class/Super.h

    r10624 r11071  
    9494            static void superCheck() \
    9595            { \
    96                 SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>(0)); \
     96                SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>(nullptr)); \
    9797                SuperFunctionCondition<functionnumber + 1, T, 0, templatehack2>::superCheck(); \
    9898            } \
     
    103103            { \
    104104                ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier(); \
    105                 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildren().begin(); it != identifier->getDirectChildren().end(); ++it) \
     105                for (const Identifier* child : identifier->getDirectChildren()) \
    106106                { \
    107                     if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
     107                    if (((ClassIdentifier<T>*)child)->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_) \
    108108                    { \
    109                         delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_; \
    110                         ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0; \
    111                         ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false; \
     109                        delete ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_; \
     110                        ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_ = nullptr; \
     111                        ((ClassIdentifier<T>*)child)->bSuperFunctionCaller_##functionname##_isFallback_ = false; \
    112112                    } \
    113113                    \
    114                     if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
     114                    if (!((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_) \
    115115                    { \
    116                         orxout(verbose, context::super) << "Added SuperFunctionCaller for " << #functionname << ": " << ClassIdentifier<T>::getIdentifier()->getName() << " <- " << ((ClassIdentifier<T>*)(*it))->getName() << endl; \
    117                         ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>; \
     116                        orxout(verbose, context::super) << "Added SuperFunctionCaller for " << #functionname << ": " << ClassIdentifier<T>::getIdentifier()->getName() << " <- " << ((ClassIdentifier<T>*)child)->getName() << endl; \
     117                        ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>; \
    118118                    } \
    119                     else if (((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_->getParentIdentifier() != ClassIdentifier<T>::getIdentifier()) \
    120                         orxout(internal_warning, context::super) << "SuperFunctionCaller for " << #functionname << " in " << ((ClassIdentifier<T>*)(*it))->getName() << " calls function of " << ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_->getParentIdentifier()->getName() << " but " << ClassIdentifier<T>::getIdentifier()->getName() << " is also possible (do you use multiple inheritance?)" << endl; \
     119                    else if (((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_->getParentIdentifier() != ClassIdentifier<T>::getIdentifier()) \
     120                        orxout(internal_warning, context::super) << "SuperFunctionCaller for " << #functionname << " in " << ((ClassIdentifier<T>*)child)->getName() << " calls function of " << ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_->getParentIdentifier()->getName() << " but " << ClassIdentifier<T>::getIdentifier()->getName() << " is also possible (do you use multiple inheritance?)" << endl; \
    121121                } \
    122122            } \
     
    154154                // This call to the apply-function is the whole check. By calling the function with
    155155                // a T* pointer, the right function get's called.
    156                 SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>(0));
     156                SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>(nullptr));
    157157
    158158                // Go go the superCheck for of next super-function (functionnumber + 1)
     
    171171
    172172                // Iterate through all children
    173                 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildren().begin(); it != identifier->getDirectChildren().end(); ++it)
     173                for (const Identifier* child : identifier->getDirectChildren())
    174174                {
    175175                    // Check if the caller is a fallback-caller
    176                     if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)
     176                    if (((ClassIdentifier<T>*)child)->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_)
    177177                    {
    178178                        // Delete the fallback caller an prepare to get a real caller
    179                         delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_;
    180                         ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0;
    181                         ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false;
     179                        delete ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_;
     180                        ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_ = nullptr;
     181                        ((ClassIdentifier<T>*)child)->bSuperFunctionCaller_##functionname##_isFallback_ = false;
    182182                    }
    183183
    184184                    // Check if there's not already a caller
    185                     if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)
     185                    if (!((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_)
    186186                    {
    187187                        // Add the SuperFunctionCaller
    188                         orxout(verbose, context::super) << "adding functionpointer to " << ((ClassIdentifier<T>*)(*it))->getName() << endl;
    189                         ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>;
     188                        orxout(verbose, context::super) << "adding functionpointer to " << ((ClassIdentifier<T>*)child)->getName() << endl;
     189                        ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>;
    190190                    }
    191191
    192192                    // If there is already a caller, but for another parent, print a warning
    193                     else if (((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_->getParentIdentifier() != ClassIdentifier<T>::getIdentifier())
    194                         orxout(internal_warning, context::super) << "SuperFunctionCaller for " << #functionname << " in " << ((ClassIdentifier<T>*)(*it))->getName() << " calls function of " << ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_->getParentIdentifier()->getName() << " but " << ClassIdentifier<T>::getIdentifier()->getName() << " is also possible (do you use multiple inheritance?)" << endl;
     193                    else if (((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_->getParentIdentifier() != ClassIdentifier<T>::getIdentifier())
     194                        orxout(internal_warning, context::super) << "SuperFunctionCaller for " << #functionname << " in " << ((ClassIdentifier<T>*)child)->getName() << " calls function of " << ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_->getParentIdentifier()->getName() << " but " << ClassIdentifier<T>::getIdentifier()->getName() << " is also possible (do you use multiple inheritance?)" << endl;
    195195                }
    196196            }
     
    584584        // Creates the super-function-callers by calling the first SuperFunctionCondition check
    585585        // This get's called within the initialization of an Identifier
    586         virtual void createSuperFunctionCaller() const
     586        virtual void createSuperFunctionCaller() const override
    587587        {
    588588            SuperFunctionCondition<0, T, 0, 0>::superCheck();
Note: See TracChangeset for help on using the changeset viewer.