Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • 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);
Note: See TracChangeset for help on using the changeset viewer.