Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 10, 2016, 1:54:11 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v2 into cpp11_v3

Location:
code/branches/cpp11_v3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v3

  • code/branches/cpp11_v3/src/libraries/core/class/Identifier.h

    r10624 r11054  
    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);
     
    269270    class ClassIdentifier : public Identifier
    270271    {
    271         BOOST_STATIC_ASSERT((boost::is_base_of<Identifiable, T>::value));
     272        static_assert(std::is_base_of<Identifiable, T>::value, "ClassIdentifier can only be used with Identifiables");
    272273
    273274        #ifndef DOXYGEN_SHOULD_SKIP_THIS
     
    279280            ClassIdentifier(const std::string& name, Factory* factory, bool bLoadable) : Identifier(name, factory, bLoadable)
    280281            {
    281                 OrxVerify(ClassIdentifier<T>::classIdentifier_s == NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name());
     282                OrxVerify(ClassIdentifier<T>::classIdentifier_s == nullptr, "Assertion failed in ClassIdentifier of type " << typeid(T).name());
    282283                ClassIdentifier<T>::classIdentifier_s = this;
    283284
     
    291292            bool initializeObject(T* object);
    292293
    293             virtual void updateConfigValues(bool updateChildren = true) const;
    294 
    295             virtual const std::type_info& getTypeInfo()
     294            virtual void updateConfigValues(bool updateChildren = true) const override;
     295
     296            virtual const std::type_info& getTypeInfo() override
    296297                { return typeid(T); }
    297298
    298             virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const
    299                 { return dynamic_cast<T*>(object) != 0; }
    300 
    301             virtual void destroyObjects();
     299            virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const override
     300                { return dynamic_cast<T*>(object) != nullptr; }
     301
     302            virtual void destroyObjects() override;
    302303
    303304            static ClassIdentifier<T>* getIdentifier();
    304305
    305306        private:
    306             ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
     307            // non-copyable:
     308            ClassIdentifier(const ClassIdentifier<T>&) = delete;
     309            ClassIdentifier& operator=(const ClassIdentifier<T>&) = delete;
    307310
    308311            void setConfigValues(T* object, Configurable*) const;
     
    321324            void updateConfigValues(bool updateChildren, Identifiable*) const;
    322325
    323             static WeakPtr<ClassIdentifier<T> > classIdentifier_s;
     326            static WeakPtr<ClassIdentifier<T>> classIdentifier_s;
    324327    };
    325328
    326329    template <class T>
    327     WeakPtr<ClassIdentifier<T> > ClassIdentifier<T>::classIdentifier_s;
     330    WeakPtr<ClassIdentifier<T>> ClassIdentifier<T>::classIdentifier_s;
    328331
    329332    /**
     
    334337    /*static*/ inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
    335338    {
    336         if (ClassIdentifier<T>::classIdentifier_s == NULL)
     339        if (ClassIdentifier<T>::classIdentifier_s == nullptr)
    337340            ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*) IdentifierManager::getInstance().getIdentifierByTypeInfo(typeid(T));
    338341
    339         OrxVerify(ClassIdentifier<T>::classIdentifier_s != NULL, "Did you forget to register the class of type " << typeid(T).name() << "?");
     342        OrxVerify(ClassIdentifier<T>::classIdentifier_s != nullptr, "Did you forget to register the class of type " << typeid(T).name() << "?");
    340343        return ClassIdentifier<T>::classIdentifier_s;
    341344    }
     
    365368
    366369            // 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)));
     370            object->objectPointers_.emplace_back(this->getClassID(), static_cast<void*>(object));
    368371            return false;
    369372        }
     
    408411    void ClassIdentifier<T>::destroyObjects()
    409412    {
    410         this->destroyObjects((T*)0);
     413        this->destroyObjects((T*)nullptr);
    411414    }
    412415
     
    417420    void ClassIdentifier<T>::destroyObjects(Listable*)
    418421    {
    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; )
     422        ObjectList<T> list(Context::getRootContext()->getObjectList(this));
     423        for (typename ObjectList<T>::iterator it = list.begin(); it != list.end(); )
    423424            this->destroyObject(*(it++));
    424425    }
     
    451452    void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const
    452453    {
    453         this->updateConfigValues(updateChildren, static_cast<T*>(NULL));
     454        this->updateConfigValues(updateChildren, static_cast<T*>(nullptr));
    454455    }
    455456
     
    460461            return;
    461462
    462         for (ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it)
    463             this->setConfigValues(*it, *it);
     463        for (T* object : ObjectList<T>())
     464            this->setConfigValues(object, object);
    464465
    465466        if (updateChildren)
    466             for (std::set<const Identifier*>::const_iterator it = this->getChildren().begin(); it != this->getChildren().end(); ++it)
    467                 (*it)->updateConfigValues(false);
     467            for (const Identifier* child : this->getChildren())
     468                child->updateConfigValues(false);
    468469    }
    469470
     
    483484        registered in the class hierarchy.
    484485    @return
    485         Returns NULL if the cast is not possible
     486        Returns nullptr if the cast is not possible
    486487    @note
    487         In case of NULL return (and using MSVC), a dynamic_cast might still be possible if
     488        In case of nullptr return (and using MSVC), a dynamic_cast might still be possible if
    488489        a class forgot to register its objects.
    489490        Also note that the function is implemented differently for GCC/MSVC.
     
    494495#ifdef ORXONOX_COMPILER_MSVC
    495496        typedef Loki::TypeTraits<typename Loki::TypeTraits<T>::PointeeType>::NonConstType ClassType;
    496         if (source != NULL)
     497        if (source != nullptr)
    497498            return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID());
    498499        else
    499             return NULL;
     500            return nullptr;
    500501#else
    501502        return dynamic_cast<T>(source);
Note: See TracChangeset for help on using the changeset viewer.