Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 21, 2015, 7:05:53 PM (9 years ago)
Author:
muemart
Message:

Run clang-modernize -loop-convert

  • Again, not all possible loops were converted
  • It can do pretty cool transformations, but I had to fix a few compile errors, so there might be some runtime errors lurking around too
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

    r10768 r10821  
    8787        for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
    8888            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);
     89        for (const auto & elem : this->children_)
     90            const_cast<Identifier*>(elem)->parents_.remove(this);
     91        for (const auto & elem : this->directChildren_)
     92            const_cast<Identifier*>(elem)->directParents_.remove(this);
     93
     94        for (auto & elem : this->configValues_)
     95            delete (elem.second);
     96        for (auto & elem : this->xmlportParamContainers_)
     97            delete (elem.second);
     98        for (auto & elem : this->xmlportObjectContainers_)
     99            delete (elem.second);
    100100    }
    101101
     
    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 auto & elem : initializationTrace)
     160                if (elem != this)
     161                    this->parents_.push_back(elem);
    162162        }
    163163        else
     
    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 auto & elem : this->parents_)
     264        {
     265            if ((elem)->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)
     267                for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(elem)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(elem)->parents_.end(); ++it_parent_parent)
    268268                    this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent);
    269                 this->addIfNotExists(expectedIdentifierTrace, *it_parent);
     269                this->addIfNotExists(expectedIdentifierTrace, elem);
    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)
     274        for (const auto & elem : this->directParents_)
     275        {
     276            for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(elem)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(elem)->parents_.end(); ++it_parent_parent)
    277277                this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent);
    278             this->addIfNotExists(expectedIdentifierTrace, *it_parent);
     278            this->addIfNotExists(expectedIdentifierTrace, elem);
    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 auto & elem : this->parents_)
     288                orxout(internal_warning) << " " << (elem)->getName();
    289289            orxout(internal_warning) << endl;
    290290
     
    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 auto & elem : this->directParents_)
     298                orxout(internal_warning) << " " << (elem)->getName();
    299299            orxout(internal_warning) << endl;
    300300        }
  • code/branches/cpp11_v2/src/libraries/core/class/Identifier.h

    r10817 r10821  
    462462
    463463        if (updateChildren)
    464             for (std::set<const Identifier*>::const_iterator it = this->getChildren().begin(); it != this->getChildren().end(); ++it)
    465                 (*it)->updateConfigValues(false);
     464            for (const auto & elem : this->getChildren())
     465                (elem)->updateConfigValues(false);
    466466    }
    467467
  • code/branches/cpp11_v2/src/libraries/core/class/IdentifierManager.cc

    r10768 r10821  
    9393        {
    9494            Context temporaryContext(nullptr);
    95             for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
     95            for (auto identifier : this->identifiers_)
    9696            {
    97                 Identifier* identifier = (*it);
     97               
    9898                if (identifier->isInitialized())
    9999                    continue;
     
    127127
    128128        // finish the initialization of all identifiers
    129         for (std::set<Identifier*>::const_iterator it = initializedIdentifiers.begin(); it != initializedIdentifiers.end(); ++it)
    130             (*it)->finishInitialization();
     129        for (const auto & initializedIdentifier : initializedIdentifiers)
     130            (initializedIdentifier)->finishInitialization();
    131131
    132132        // only check class hierarchy in dev mode because it's an expensive operation and it requires a developer to fix detected problems anyway.
     
    144144    {
    145145        // 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;
     146        for (const auto & elem : this->identifiers_)
     147            if (!(elem)->isInitialized())
     148                orxout(internal_error) << "Identifier was registered late and is not initialized: " << (elem)->getName() << " / " << (elem)->getTypeInfo().name() << endl;
    149149
    150150        // for all initialized identifiers, check if a sample instance behaves as expected according to the class hierarchy
    151151        Context temporaryContext(nullptr);
    152         for (std::set<Identifier*>::const_iterator it1 = initializedIdentifiers.begin(); it1 != initializedIdentifiers.end(); ++it1)
     152        for (const auto & initializedIdentifier : initializedIdentifiers)
    153153        {
    154             if (!(*it1)->hasFactory())
     154            if (!(initializedIdentifier)->hasFactory())
    155155                continue;
    156156
    157             Identifiable* temp = (*it1)->fabricate(&temporaryContext);
    158 
    159             for (std::set<Identifier*>::const_iterator it2 = this->identifiers_.begin(); it2 != this->identifiers_.end(); ++it2)
     157            Identifiable* temp = (initializedIdentifier)->fabricate(&temporaryContext);
     158
     159            for (const auto & elem : this->identifiers_)
    160160            {
    161                 bool isA_AccordingToRtti = (*it2)->canDynamicCastObjectToIdentifierClass(temp);
    162                 bool isA_AccordingToClassHierarchy = temp->isA((*it2));
     161                bool isA_AccordingToRtti = (elem)->canDynamicCastObjectToIdentifierClass(temp);
     162                bool isA_AccordingToClassHierarchy = temp->isA((elem));
    163163
    164164                if (isA_AccordingToRtti != isA_AccordingToClassHierarchy)
    165165                {
    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;
     166                    orxout(internal_error) << "Class hierarchy does not match RTTI: Class hierarchy claims that " << (initializedIdentifier)->getName() <<
     167                        (isA_AccordingToClassHierarchy ? " is a " : " is not a ") << (elem)->getName() << " but RTTI says the opposite." << endl;
    168168                }
    169169            }
     
    184184    {
    185185        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();
     186        for (const auto & elem : this->identifiers_)
     187            (elem)->reset();
    188188    }
    189189
     
    260260    {
    261261        // 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);
     262        for (const auto & elem : this->identifiers_)
     263            if ((elem)->getTypeInfo() == typeInfo)
     264                return (elem);
    265265        return nullptr;
    266266    }
Note: See TracChangeset for help on using the changeset viewer.