Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 5, 2015, 10:47:51 PM (9 years ago)
Author:
landauf
Message:

use range-based for-loop where it makes sense (e.g. ObjectList)

Location:
code/branches/cpp11_v2/src/libraries/core/class
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/class/Identifier.cc

    r10917 r10919  
    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);
     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);
    8989        for (const Identifier* child : this->children_)
    9090            const_cast<Identifier*>(child)->parents_.remove(this);
     
    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
     
    265265            if (parent->isVirtualBase())
    266266            {
    267                 for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(parent)->parents_.end(); ++it_parent_parent)
    268                     this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent);
     267                for (const Identifier* parent_parent : const_cast<Identifier*>(parent)->parents_)
     268                    this->addIfNotExists(expectedIdentifierTrace, parent_parent);
    269269                this->addIfNotExists(expectedIdentifierTrace, parent);
    270270            }
     
    274274        for (const Identifier* directParent : this->directParents_)
    275275        {
    276             for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(directParent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(directParent)->parents_.end(); ++it_parent_parent)
    277                 this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent);
     276            for (const Identifier* parent_parent : const_cast<Identifier*>(directParent)->parents_)
     277                this->addIfNotExists(expectedIdentifierTrace, parent_parent);
    278278            this->addIfNotExists(expectedIdentifierTrace, directParent);
    279279        }
     
    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
  • code/branches/cpp11_v2/src/libraries/core/class/Identifier.h

    r10918 r10919  
    458458            return;
    459459
    460         for (ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it)
    461             this->setConfigValues(*it, *it);
     460        for (T* object : ObjectList<T>())
     461            this->setConfigValues(object, object);
    462462
    463463        if (updateChildren)
  • code/branches/cpp11_v2/src/libraries/core/class/Super.h

    r10817 r10919  
    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##_ = nullptr; \
    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            } \
     
    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##_ = nullptr;
    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            }
Note: See TracChangeset for help on using the changeset viewer.