Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 18, 2015, 1:07:08 PM (9 years ago)
Author:
landauf
Message:

use lists instead of sets to store parent identifiers. this allows to store the exact order of initialization of parent classes.

Location:
code/branches/core7/src/libraries/core/class
Files:
4 edited

Legend:

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

    r10371 r10372  
    135135    {
    136136        if (this->parents_.empty())
    137             this->directParents_.insert(directParent);
     137            this->directParents_.push_back(directParent);
    138138        else
    139139            orxout(internal_error) << "Trying to add " << directParent->getName() << " as a direct parent of " << this->getName() << " after the latter was already initialized" << endl;
     
    146146     * @param initializationTrace All identifiers that were recorded while creating an instance of this class (including nested classes and this identifier itself)
    147147     */
    148     void Identifier::initializeParents(const std::set<const Identifier*>& initializationTrace)
     148    void Identifier::initializeParents(const std::list<const Identifier*>& initializationTrace)
    149149    {
    150150        if (!IdentifierManager::getInstance().isCreatingHierarchy())
     
    156156        if (this->directParents_.empty())
    157157        {
    158             for (std::set<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it)
     158            for (std::list<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it)
    159159                if (*it != this)
    160                     this->parents_.insert(*it);
     160                    this->parents_.push_back(*it);
    161161        }
    162162        else
     
    183183
    184184            // initialize all parents
    185             for (std::set<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
     185            for (std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
    186186                const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent
    187187
    188188            // parents of parents are no direct parents of this identifier
    189189            this->directParents_ = this->parents_;
    190             for (std::set<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)
    191                 for (std::set<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)
    192                     this->directParents_.erase(*it_parent_parent);
     190            for (std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)
     191                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)
     192                    this->directParents_.remove(*it_parent_parent);
    193193        }
    194194        else if (!this->directParents_.empty())
     
    197197
    198198            // initialize all direct parents
    199             for (std::set<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
     199            for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
    200200                const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent
    201201
    202202            // direct parents and their parents are also parents of this identifier (but only add them once)
    203203            this->parents_ = this->directParents_;
    204             for (std::set<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)
    205                 for (std::set<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)
     204            for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)
     205                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)
    206206                    if (std::find(this->parents_.begin(), this->parents_.end(), *it_parent_parent) == this->parents_.end())
    207                         this->parents_.insert(*it_parent_parent);
     207                        this->parents_.push_back(*it_parent_parent);
    208208        }
    209209        else if (!this->isExactlyA(Class(Identifiable)))
     
    216216
    217217        // tell all parents that this identifier is a child
    218         for (std::set<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
     218        for (std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
    219219            const_cast<Identifier*>(*it)->children_.insert(this);
    220220
    221221        // tell all direct parents that this identifier is a direct child
    222         for (std::set<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
     222        for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
    223223        {
    224224            const_cast<Identifier*>(*it)->directChildren_.insert(this);
     
    255255    bool Identifier::isChildOf(const Identifier* identifier) const
    256256    {
    257         return (this->parents_.find(identifier) != this->parents_.end());
     257        return (std::find(this->parents_.begin(), this->parents_.end(),  identifier) != this->parents_.end());
    258258    }
    259259
     
    264264    bool Identifier::isDirectChildOf(const Identifier* identifier) const
    265265    {
    266         return (this->directParents_.find(identifier) != this->directParents_.end());
     266        return (std::find(this->directParents_.begin(), this->directParents_.end(), identifier) != this->directParents_.end());
    267267    }
    268268
  • code/branches/core7/src/libraries/core/class/Identifier.h

    r10371 r10372  
    148148            Identifier& inheritsFrom(Identifier* directParent);
    149149
    150             void initializeParents(const std::set<const Identifier*>& initializationTrace);
     150            void initializeParents(const std::list<const Identifier*>& initializationTrace);
    151151            void finishInitialization();
    152152
     
    159159
    160160            /// Returns the parents of the class the Identifier belongs to.
    161             inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
     161            inline const std::list<const Identifier*>& getParents() const { return this->parents_; }
    162162            /// Returns the children of the class the Identifier belongs to.
    163163            inline const std::set<const Identifier*>& getChildren() const { return this->children_; }
    164164            /// Returns the direct parents of the class the Identifier belongs to.
    165             inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; }
     165            inline const std::list<const Identifier*>& getDirectParents() const { return this->directParents_; }
    166166            /// Returns the direct children the class the Identifier belongs to.
    167167            inline const std::set<const Identifier*>& getDirectChildren() const { return this->directChildren_; }
     
    209209
    210210        private:
    211             std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
     211            std::list<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to (sorted by their order of initialization)
    212212            std::set<const Identifier*> children_;                         //!< The children of the class the Identifier belongs to
    213213
    214             std::set<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to
     214            std::list<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to (sorted by their order of initialization)
    215215            std::set<const Identifier*> directChildren_;                   //!< The direct children of the class the Identifier belongs to
    216216
  • code/branches/core7/src/libraries/core/class/IdentifierManager.cc

    r10371 r10372  
    216216            if (this->recordTraceForIdentifier_)
    217217            {
    218                 if (this->identifierTraceOfNewObject_[identifiable].insert(identifiable->getIdentifier()).second == false)
     218                std::list<const Identifier*>& traceForObject = this->identifierTraceOfNewObject_[identifiable];
     219                if (std::find(traceForObject.begin(), traceForObject.end(), identifiable->getIdentifier()) != traceForObject.end())
    219220                {
    220221                    orxout(internal_warning) << this->recordTraceForIdentifier_->getName() << " inherits two times from " <<
    221222                        identifiable->getIdentifier()->getName() << ". Did you forget to use virtual inheritance?" << endl;
    222223                }
     224                traceForObject.push_back(identifiable->getIdentifier());
    223225            }
    224226        }
  • code/branches/core7/src/libraries/core/class/IdentifierManager.h

    r10370 r10372  
    3838
    3939#include <map>
    40 #include <set>
     40#include <list>
    4141#include <string>
    4242
     
    111111            /// 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
    112112            /// a consequence of this, e.g. nested member objects).
    113             std::map<Identifiable*, std::set<const Identifier*> > identifierTraceOfNewObject_;
     113            std::map<Identifiable*, std::list<const Identifier*> > identifierTraceOfNewObject_;
    114114            Identifier* recordTraceForIdentifier_; //!< The identifier for which we want to record the trace of identifiers during object creation. If null, no trace is recorded.
    115115    };
Note: See TracChangeset for help on using the changeset viewer.