Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 16, 2008, 7:31:18 PM (16 years ago)
Author:
landauf
Message:

big update:

  • reimplemented direct-child and direct-parent list and several related functions (get-iterator, get-list)
  • reimplemented isDirectChildOf- and isDirectParentOf-functions in Identifier, SubclassIdentifier and OrxonoxClass
  • renamed isDirectlyA to isExactlyA in Identifier, SubclassIdentifier and OrxonoxClass
  • ClassTreeMask works now with interfaces and has more possibilities (parameters for overwriting of previous rules and cleaning after adding a new function)
  • ObjectList's begin() and end() functions use ClassManager to avoid problems with libraries
  • the Factory got functions to return begin() and end() iterator for the identifier-map
  • overloaded << operator to put identifier-lists on the stream
Location:
code/branches/core/src/orxonox/core
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core/src/orxonox/core/ClassTreeMask.cc

    r813 r817  
    5757    {
    5858        // Go through the list of all subnodes and delete them
     59        this->deleteAllSubnodes();
     60    }
     61
     62    /**
     63        @brief Sets the rule for the node to "included".
     64    */
     65    void ClassTreeMaskNode::include(bool overwrite)
     66    {
     67        this->setIncluded(true, overwrite);
     68    }
     69
     70    /**
     71        @brief Sets the rule for the node to "excluded".
     72    */
     73    void ClassTreeMaskNode::exclude(bool overwrite)
     74    {
     75        this->setIncluded(false, overwrite);
     76    }
     77
     78    /**
     79        @brief Sets the rule for the node to a given value and erases all following rules.
     80        @param bIncluded The rule: included (true) or excluded (false)
     81    */
     82    void ClassTreeMaskNode::setIncluded(bool bIncluded, bool overwrite)
     83    {
     84        if (overwrite)
     85            this->deleteAllSubnodes();
     86
     87        this->bIncluded_ = bIncluded;
     88    }
     89
     90    /**
     91        @brief Adds a new subnode to the list of subnodes.
     92        @param subnode The new subnode
     93    */
     94    void ClassTreeMaskNode::addSubnode(ClassTreeMaskNode* subnode)
     95    {
     96        this->subnodes_.insert(this->subnodes_.end(), subnode);
     97    }
     98
     99    /**
     100        @brief Tells if the rule is "included" or not.
     101        @return The rule: true = included, false = excluded
     102    */
     103    bool ClassTreeMaskNode::isIncluded() const
     104    {
     105        return this->bIncluded_;
     106    }
     107
     108    /**
     109        @brief Tells if the rule is "excluded" or not.
     110        @return The inverted rule: true = excluded, false = included
     111    */
     112    bool ClassTreeMaskNode::isExcluded() const
     113    {
     114        return (!this->bIncluded_);
     115    }
     116
     117    /**
     118        @brief Returns the Identifier of the class the rule refers to.
     119        @return The Identifier representing the class
     120    */
     121    const Identifier* ClassTreeMaskNode::getClass() const
     122    {
     123        return this->subclass_;
     124    }
     125
     126    /**
     127        @brief Deletes all subnodes of this node.
     128    */
     129    void ClassTreeMaskNode::deleteAllSubnodes()
     130    {
     131        // Go through the list of all subnodes and delete them
    59132        for (std::list<ClassTreeMaskNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); )
    60133            delete (*(it++));
    61     }
    62 
    63     /**
    64         @brief Sets the rule for the node to "included".
    65     */
    66     void ClassTreeMaskNode::include()
    67     {
    68         this->bIncluded_ = true;
    69     }
    70 
    71     /**
    72         @brief Sets the rule for the node to "excluded".
    73     */
    74     void ClassTreeMaskNode::exclude()
    75     {
    76         this->bIncluded_ = false;
    77     }
    78 
    79     /**
    80         @brief Sets the rule for the node to a given value.
    81         @param bIncluded The rule: included (true) or excluded (false)
    82     */
    83     void ClassTreeMaskNode::setIncluded(bool bIncluded)
    84     {
    85         this->bIncluded_ = bIncluded;
    86     }
    87 
    88     /**
    89         @brief Adds a new subnode to the list of subnodes.
    90         @param subnode The new subnode
    91     */
    92     void ClassTreeMaskNode::addSubnode(ClassTreeMaskNode* subnode)
    93     {
    94         this->subnodes_.insert(this->subnodes_.end(), subnode);
    95     }
    96 
    97     /**
    98         @brief Tells if the rule is "included" or not.
    99         @return The rule: true = included, false = excluded
    100     */
    101     bool ClassTreeMaskNode::isIncluded() const
    102     {
    103         return this->bIncluded_;
    104     }
    105 
    106     /**
    107         @brief Tells if the rule is "excluded" or not.
    108         @return The inverted rule: true = excluded, false = included
    109     */
    110     bool ClassTreeMaskNode::isExcluded() const
    111     {
    112         return (!this->bIncluded_);
    113     }
    114 
    115     /**
    116         @brief Returns the Identifier of the class the rule refers to.
    117         @return The Identifier representing the class
    118     */
    119     const Identifier* ClassTreeMaskNode::getClass() const
    120     {
    121         return this->subclass_;
     134
     135        // Clear the list
     136        this->subnodes_.clear();
    122137    }
    123138
     
    258273        this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier(), true);
    259274        for (ClassTreeMaskIterator it = other.root_; it; ++it)
    260             this->add(it->getClass(), it->isIncluded());
     275            this->add(it->getClass(), it->isIncluded(), false);
    261276    }
    262277
     
    273288        @param subclass The subclass
    274289    */
    275     void ClassTreeMask::include(const Identifier* subclass)
    276     {
    277         this->add(subclass, true);
     290    void ClassTreeMask::include(const Identifier* subclass, bool overwrite, bool clean)
     291    {
     292        this->add(subclass, true, overwrite, clean);
    278293    }
    279294
     
    282297        @param subclass The subclass
    283298    */
    284     void ClassTreeMask::exclude(const Identifier* subclass)
    285     {
    286         this->add(subclass, false);
     299    void ClassTreeMask::exclude(const Identifier* subclass, bool overwrite, bool clean)
     300    {
     301        this->add(subclass, false, overwrite, clean);
    287302    }
    288303
     
    292307        @param bInclude The rule: include (true) or exclude (false)
    293308    */
    294     void ClassTreeMask::add(const Identifier* subclass, bool bInclude)
    295     {
     309    void ClassTreeMask::add(const Identifier* subclass, bool bInclude, bool overwrite, bool clean)
     310    {
     311        // Check if the given subclass is a child of our root-class
    296312        if (subclass->isA(this->root_->getClass()))
    297             this->add(this->root_, subclass, bInclude);
     313        {
     314            // Yes it is: Just add the rule to the three
     315            this->add(this->root_, subclass, bInclude, overwrite);
     316        }
    298317        else
    299318        {
    300 
    301         }
    302 
    303         this->clean();
     319            // No it's not: Search for classes inheriting from the given class and add the rules for them
     320            for (std::list<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it)
     321                if ((*it)->isA(this->root_->getClass()))
     322                    if (overwrite || (!this->nodeExists(*it))) // If we don't want to overwrite, only add nodes that don't already exist
     323                        this->add(this->root_, *it, bInclude, overwrite);
     324        }
     325
     326        // Clean the rule-tree
     327        if (clean)
     328            this->clean();
    304329    }
    305330
     
    310335        @param bInclude The rule: include (true) or exclude (false)
    311336    */
    312     void ClassTreeMask::add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude)
     337    void ClassTreeMask::add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude, bool overwrite)
    313338    {
    314339        // Check if the current node contains exactly the subclass we want to add
     
    316341        {
    317342            // We're at the right place, just change the mask and return
    318             node->setIncluded(bInclude);
     343            node->setIncluded(bInclude, overwrite);
    319344            return;
    320345        }
    321         else
     346        else if (subclass->isA(node->getClass()))
    322347        {
    323348            // Search for an already existing node, containing the subclass we want to add
     
    327352                {
    328353                    // We've found an existing node -> delegate the work with a recursive function-call and return
    329                     this->add(*it, subclass, bInclude);
     354                    this->add(*it, subclass, bInclude, overwrite);
    330355                    return;
    331356                }
     
    335360            ClassTreeMaskNode* newnode = new ClassTreeMaskNode(subclass, bInclude);
    336361
    337             // Search for nodes that should actually be subnodes of our new node
     362            // Search for nodes that should actually be subnodes of our new node and erase them
    338363            for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); )
    339364            {
    340365                if ((*it)->getClass()->isChildOf(subclass))
    341366                {
    342                     // We've found a subnode: add it to the new node an erase it from the current node
    343                     newnode->addSubnode(*it);
     367                    // We've found a subnode: add it to the new node and erase it from the current node
     368                    if (!overwrite)
     369                        newnode->addSubnode(*it);
     370                    else
     371                        delete (*it);
     372
    344373                    node->subnodes_.erase(it++);
    345374                }
     
    453482
    454483    /**
     484        @brief Checks if a node for the given subclass exists.
     485        @param subclass The Identifier of the subclass
     486        @return True = the node exists
     487    */
     488    bool ClassTreeMask::nodeExists(const Identifier* subclass)
     489    {
     490        for (ClassTreeMaskIterator it = this->root_; it; ++it)
     491            if ((*it)->getClass() == subclass)
     492                return true;
     493
     494        return false;
     495    }
     496
     497    /**
    455498        @brief Assignment operator: Adds all rules of the other mask.
    456499        @param other The other mask
     
    467510        // Copy all rules from the other mask
    468511        for (ClassTreeMaskIterator it = temp.root_; it; ++it)
    469             this->add(it->getClass(), it->isIncluded());
     512            this->add(it->getClass(), it->isIncluded(), false, false);
    470513
    471514        // Return a reference to the mask itself
     
    505548        {
    506549            const Identifier* subclass = it->getClass();
    507             newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass));
     550            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass), false, false);
    508551        }
    509552
     
    512555        {
    513556            const Identifier* subclass = it->getClass();
    514             newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass));
     557            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass), false, false);
    515558        }
    516559
     
    536579        {
    537580            const Identifier* subclass = it->getClass();
    538             newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass));
     581            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass), false, false);
    539582        }
    540583
     
    543586        {
    544587            const Identifier* subclass = it->getClass();
    545             newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass));
     588            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass), false, false);
    546589        }
    547590
     
    576619        {
    577620            const Identifier* subclass = it->getClass();
    578             newmask.add(subclass, !this->isIncluded(subclass));
     621            newmask.add(subclass, !this->isIncluded(subclass), false, false);
    579622        }
    580623
     
    650693        {
    651694            const Identifier* subclass = it->getClass();
    652             newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass));
     695            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass), false, false);
    653696        }
    654697
     
    657700        {
    658701            const Identifier* subclass = it->getClass();
    659             newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass));
     702            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass), false, false);
    660703        }
    661704
  • code/branches/core/src/orxonox/core/ClassTreeMask.h

    r813 r817  
    3434    Identifier of the class.
    3535
    36     You can work with a ClassTreeMask in the sense of the set theory, meaning that you can create
     36    You can work with a ClassTreeMask in the sense of the set-theory, meaning that you can create
    3737    unions, intersections, complements and differences by using overloaded operators.
     38
     39
    3840
    3941    The ClassTreeMask is internally represented by a tree. The nodes in the tree are
     
    4244    nodes changing the mask. By adding new rules, the tree gets reordered dynamically.
    4345
    44     You can manually add useless rules and they stay in the tree. That way you can add rules in
    45     any order without changing information of the resulting mask. Example: A new mask includes all
    46     classes. Now you explicitly include a subclass. This seems to be useless. But if you exclude a
    47     baseclass of the formerly included subclass, the subclass stays included. You could create the
    48     same mask by first excluding the baseclass and then including the subclass. You can drop
    49     useless rules from the tree by calling clean().
     46    Adding a new rule overwrites all rules assigned to inherited classes. Use overwrite = false
     47    if you don't like this feature. Useless rules that don't change the information of the mask
     48    aren't saved in the internal tree. Use clean = false if you wan't to save them.
     49
     50    With overwrite = false and clean = false it doesn't matter in which way you create the mask.
     51    You can manually drop useless rules from the tree by calling clean().
     52
     53
    5054
    5155    Because of the complicated shape of the internal tree, there is an iterator to iterate
     
    9195            ~ClassTreeMaskNode();
    9296
    93             void include();
    94             void exclude();
    95             void setIncluded(bool bIncluded);
     97            void include(bool overwrite = true);
     98            void exclude(bool overwrite = true);
     99            void setIncluded(bool bIncluded, bool overwrite = true);
    96100
    97101            void addSubnode(ClassTreeMaskNode* subnode);
     
    103107
    104108        private:
     109            void deleteAllSubnodes();
     110
    105111            const Identifier* subclass_;                //!< The Identifier of the subclass the rule refers to
    106112            bool bIncluded_;                            //!< The rule: included or excluded
     
    146152        With a ClassTreeMask, you can include or exclude subtrees of the class-tree, starting
    147153        with a given subclass, described by the corresponding Identifier. To minimize the size
    148         of the mask, the mask saves only relevant rules. But you are allowed to manually add
    149         rules that don't change the information of the mask. This way you can create the same
    150         mask by adding the same rules in a different way without changing the information. If
    151         you want to drop useless rules, call the clean() function.
     154        of the mask, the mask saves only relevant rules. But you can manually add rules that
     155        don't change the information of the mask by using clean = false. If you want to drop
     156        useless rules, call the clean() function.
    152157    */
    153158    class _CoreExport ClassTreeMask
     
    158163            ~ClassTreeMask();
    159164
    160             void include(const Identifier* subclass);
    161             void exclude(const Identifier* subclass);
    162             void add(const Identifier* subclass, bool bInclude);
     165            void include(const Identifier* subclass, bool overwrite = true, bool clean = true);
     166            void exclude(const Identifier* subclass, bool overwrite = true, bool clean = true);
     167            void add(const Identifier* subclass, bool bInclude, bool overwrite = true, bool clean = true);
    163168            void reset();
    164169            void clean();
     
    193198
    194199        private:
    195             void add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude);
     200            void add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude, bool overwrite = true);
    196201            bool isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const;
    197202            void clean(ClassTreeMaskNode* node);
     203            bool nodeExists(const Identifier* subclass);
    198204
    199205            ClassTreeMaskNode* root_;   //!< The root-node of the internal rule-tree, usually BaseObject
  • code/branches/core/src/orxonox/core/Factory.cc

    r813 r817  
    109109      return &theOneAndOnlyFactoryInstance;
    110110    }
     111
     112    /**
     113        @brief Returns the begin-iterator of the factory-map.
     114        @return The begin-iterator
     115    */
     116    std::map<std::string, Identifier*>::const_iterator Factory::getFactoryBegin()
     117    {
     118        return Factory::getFactoryPointer()->identifierStringMap_.begin();
     119    }
     120
     121    /**
     122        @brief Returns the end-iterator of the factory-map.
     123        @return The end-iterator
     124    */
     125    std::map<std::string, Identifier*>::const_iterator Factory::getFactoryEnd()
     126    {
     127        return Factory::getFactoryPointer()->identifierStringMap_.end();
     128    }
    111129}
  • code/branches/core/src/orxonox/core/Factory.h

    r813 r817  
    6767
    6868            static Factory* getFactoryPointer();    // avoid overriding order problem in the static intialisation process
     69            static std::map<std::string, Identifier*>::const_iterator getFactoryBegin();
     70            static std::map<std::string, Identifier*>::const_iterator getFactoryEnd();
    6971
    7072        private:
  • code/branches/core/src/orxonox/core/Identifier.cc

    r813 r817  
    3030    @brief Implementation of the Identifier class.
    3131*/
     32
     33#include <ostream>
    3234
    3335#include "Identifier.h"
     
    5052
    5153        this->children_ = new std::list<const Identifier*>();
     54        this->directChildren_ = new std::list<const Identifier*>();
    5255
    5356        // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables
     
    6265    {
    6366        delete this->children_;
     67        delete this->directChildren_;
    6468    }
    6569
     
    7579        if (parents)
    7680        {
    77             std::list<const Identifier*>::iterator temp1 = parents->begin();
    78             while (temp1 != parents->end())
     81            this->parents_ = (*parents);
     82            this->directParents_ = (*parents);
     83
     84            // Iterate through all parents
     85            for (std::list<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)
    7986            {
    80                 this->parents_.insert(this->parents_.end(), *temp1);
    81                 (*temp1)->getChildren().insert((*temp1)->getChildren().end(), this); // We're a child of our parents
    82 
    83                 ++temp1;
     87                // Tell the parent we're one of it's children
     88                (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);
     89
     90                // Erase all parents of our parent from our direct-parent-list
     91                for (std::list<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)
     92                {
     93                    // Search for the parent's parent in our direct-parent-list
     94                    for (std::list<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)
     95                    {
     96                        if ((*it1) == (*it2))
     97                        {
     98                            // We've found a non-direct parent in our list: Erase it
     99                            this->directParents_.erase(it2);
     100                            break;
     101                        }
     102                    }
     103                }
     104            }
     105
     106            // Now iterate through all direct parents
     107            for (std::list<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
     108            {
     109                // Tell the parent we're one of it's direct children
     110                (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
    84111            }
    85112        }
     
    98125        else
    99126        {
    100             // Abstract classes don't have a factory and therefore can't create new objects
    101127            COUT(1) << "An error occurred in Identifier:" << std::endl;
    102             COUT(1) << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract." << std::endl;
     128            COUT(1) << "Error: Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << std::endl;
    103129            COUT(1) << "Aborting..." << std::endl;
    104130            abort();
     
    130156        @param identifier The identifier to compare with
    131157    */
    132     bool Identifier::isDirectlyA(const Identifier* identifier) const
     158    bool Identifier::isExactlyA(const Identifier* identifier) const
    133159    {
    134160        return (identifier == this);
     
    145171
    146172    /**
     173        @brief Returns true, if the assigned identifier is a direct child of the given identifier.
     174        @param identifier The identifier to compare with
     175    */
     176    bool Identifier::isDirectChildOf(const Identifier* identifier) const
     177    {
     178        return this->identifierIsInList(identifier, this->directParents_);
     179    }
     180
     181    /**
    147182        @brief Returns true, if the assigned identifier is a parent of the given identifier.
    148183        @param identifier The identifier to compare with
     
    151186    {
    152187        return this->identifierIsInList(identifier, *this->children_);
     188    }
     189
     190    /**
     191        @brief Returns true, if the assigned identifier is a direct parent of the given identifier.
     192        @param identifier The identifier to compare with
     193    */
     194    bool Identifier::isDirectParentOf(const Identifier* identifier) const
     195    {
     196        return this->identifierIsInList(identifier, *this->directChildren_);
    153197    }
    154198
     
    167211        return false;
    168212    }
     213
     214    std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list)
     215    {
     216        for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
     217            out << (*it)->getName() << " ";
     218
     219        return out;
     220    }
    169221}
  • code/branches/core/src/orxonox/core/Identifier.h

    r814 r817  
    3939
    4040    Every object has a pointer to the Identifier of its class. This allows the use isA(...),
    41     isDirectlyA(...), isChildOf(...) and isParentOf(...).
     41    isExactlyA(...), isChildOf(...) and isParentOf(...).
    4242
    4343    To create the class-hierarchy, the Identifier has some intern functions and variables.
     
    8282
    8383        Every object has a pointer to the Identifier of its class. This allows the use isA(...),
    84         isDirectlyA(...), isChildOf(...) and isParentOf(...).
     84        isExactlyA(...), isChildOf(...) and isParentOf(...).
    8585
    8686        You can't directly create an Identifier, it's just the base-class for ClassIdentifier.
     
    102102            BaseObject* fabricate();
    103103            bool isA(const Identifier* identifier) const;
    104             bool isDirectlyA(const Identifier* identifier) const;
     104            bool isExactlyA(const Identifier* identifier) const;
    105105            bool isChildOf(const Identifier* identifier) const;
     106            bool isDirectChildOf(const Identifier* identifier) const;
    106107            bool isParentOf(const Identifier* identifier) const;
     108            bool isDirectParentOf(const Identifier* identifier) const;
    107109
    108110            /** @brief Removes all objects of the corresponding class. */
     
    114116            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
    115117            inline const std::list<const Identifier*>& getParents() const { return this->parents_; }
    116 
    117118            /** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */
    118119            inline std::list<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); }
    119 
    120120            /** @brief Returns the end-iterator of the parents-list. @return The end-iterator */
    121121            inline std::list<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }
    122122
     123            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
     124            inline const std::list<const Identifier*>& getChildren() const { return (*this->children_); }
    123125            /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */
    124126            inline std::list<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }
    125 
    126127            /** @brief Returns the end-iterator of the children-list. @return The end-iterator */
    127128            inline std::list<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }
     129
     130            /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */
     131            inline const std::list<const Identifier*>& getDirectParents() const { return this->directParents_; }
     132            /** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */
     133            inline std::list<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); }
     134            /** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */
     135            inline std::list<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }
     136
     137            /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */
     138            inline const std::list<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
     139            /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */
     140            inline std::list<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }
     141            /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */
     142            inline std::list<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
    128143
    129144            /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
     
    143158            inline void setConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
    144159                { this->configValues_[varname] = container; }
     160
     161            static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list);
    145162
    146163        private:
     
    150167            void initialize(std::list<const Identifier*>* parents);
    151168
    152             /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
    153             inline std::list<const Identifier*>& getParents() { return this->parents_; }
    154 
    155169            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    156             inline std::list<const Identifier*>& getChildren() const { return (*this->children_); }
     170            inline std::list<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
     171            /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */
     172            inline std::list<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
    157173
    158174            /**
     
    174190            }
    175191
    176             static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list);
    177 
    178             std::list<const Identifier*> parents_;                      //!< The Parents of the class the Identifier belongs to
    179             std::list<const Identifier*>* children_;                    //!< The Children of the class the Identifier belongs to
     192            std::list<const Identifier*> parents_;                      //!< The parents of the class the Identifier belongs to
     193            std::list<const Identifier*>* children_;                    //!< The children of the class the Identifier belongs to
     194
     195            std::list<const Identifier*> directParents_;                //!< The direct parents of the class the Identifier belongs to
     196            std::list<const Identifier*>* directChildren_;              //!< The direct children of the class the Identifier belongs to
    180197
    181198            std::string name_;                                          //!< The name of the class the Identifier belongs to
     
    188205    };
    189206
     207    std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list);
     208
    190209
    191210    // ###############################
     
    215234            void removeObjects() const;
    216235            void setName(const std::string& name);
     236            inline const ObjectList<T>* getObjects() const { return this->objects_; }
    217237
    218238        private:
     
    231251    ClassIdentifier<T>::ClassIdentifier()
    232252    {
    233         this->objects_ = ObjectList<T>::getList();
     253//        this->objects_ = ObjectList<T>::getList();
     254        this->objects_ = new ObjectList<T>();
    234255        this->bSetName_ = false;
    235256    }
     
    294315    void ClassIdentifier<T>::removeObjects() const
    295316    {
    296         for (Iterator<T> it = ObjectList<T>::start(); it;)
     317        for (Iterator<T> it = this->objects_->start(); it;)
    297318            delete *(it++);
    298319    }
     320
    299321
    300322    // ###############################
     
    409431
    410432            /** @brief Returns true, if the assigned identifier is exactly of the given type. @param identifier The identifier to compare with */
    411             inline bool isDirectlyA(const Identifier* identifier) const
    412                 { return this->identifier_->isDirectlyA(identifier); }
     433            inline bool isExactlyA(const Identifier* identifier) const
     434                { return this->identifier_->isExactlyA(identifier); }
    413435
    414436            /** @brief Returns true, if the assigned identifier is a child of the given identifier. @param identifier The identifier to compare with */
     
    416438                { return this->identifier_->isChildOf(identifier); }
    417439
     440            /** @brief Returns true, if the assigned identifier is a direct child of the given identifier. @param identifier The identifier to compare with */
     441            inline bool isDirectChildOf(const Identifier* identifier) const
     442                { return this->identifier_->isDirectChildOf(identifier); }
     443
    418444            /** @brief Returns true, if the assigned identifier is a parent of the given identifier. @param identifier The identifier to compare with */
    419445            inline bool isParentOf(const Identifier* identifier) const
    420446                { return this->identifier_->isParentOf(identifier); }
     447
     448            /** @brief Returns true, if the assigned identifier is a direct parent of the given identifier. @param identifier The identifier to compare with */
     449            inline bool isDirectParentOf(const Identifier* identifier) const
     450                { return this->identifier_->isDirectParentOf(identifier); }
    421451
    422452        private:
  • code/branches/core/src/orxonox/core/ObjectList.h

    r813 r817  
    4040#include "CorePrereqs.h"
    4141#include "Iterator.h"
     42#include "ClassManager.h"
    4243
    4344namespace orxonox
     
    8384    {
    8485        public:
    85             static ObjectList<T>* getList();
     86            ObjectList();
     87            ~ObjectList();
    8688
    8789            ObjectListElement<T>* add(T* object);
     
    9092            /** @brief Returns the first element in the list. @return The first element */
    9193            inline static Iterator<T> start()
    92                 { return Iterator<T>(getList()->first_); }
     94                { return Iterator<T>(ClassManager<T>::getIdentifier()->getObjects()->first_); }
    9395
    9496            /** @brief Returns the first element in the list. @return The first element */
    9597            inline static Iterator<T> begin()
    96                 { return Iterator<T>(getList()->first_); }
     98                { return Iterator<T>(ClassManager<T>::getIdentifier()->getObjects()->first_); }
    9799
    98100            /** @brief Returns the last element in the list. @return The last element */
    99101            inline static Iterator<T> end()
    100                 { return Iterator<T>(getList()->last_); }
     102                { return Iterator<T>(ClassManager<T>::getIdentifier()->getObjects()->last_); }
    101103
    102104            ObjectListElement<T>* first_;       //!< The first element in the list
    103105            ObjectListElement<T>* last_;        //!< The last element in the list
    104 
    105         private:
    106             ObjectList();
    107             ~ObjectList();
    108106    };
    109107
     
    131129            this->first_ = temp;
    132130        }
    133     }
    134 
    135     /**
    136         @brief Returns a pointer to the only existing instance for the given class T. @return The instance
    137     */
    138     template <class T>
    139     ObjectList<T>* ObjectList<T>::getList()
    140     {
    141         static ObjectList<T> theOnlyObjectListObjectForClassT = ObjectList<T>();
    142         return &theOnlyObjectListObjectForClassT;
    143131    }
    144132
  • code/branches/core/src/orxonox/core/OrxonoxClass.h

    r813 r817  
    7272            inline void createParents() { this->parents_ = new std::list<const Identifier*>(); }
    7373
    74 //            /** @brief Sets the Parents of the object. Used by the RegisterObject-macro. */
    75 //            inline void setParents(std::list<const Identifier*>* parents) { this->parents_ = parents; }
    76 
    7774            /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */
    7875            inline MetaObjectList& getMetaList() { return this->metaList_; }
     
    8380                { return this->getIdentifier()->isA(identifier); }
    8481            /** @brief Returns true if the objects class is exactly of the given type. */
    85             inline bool isDirectlyA(const Identifier* identifier)
    86                 { return this->getIdentifier()->isDirectlyA(identifier); }
     82            inline bool isExactlyA(const Identifier* identifier)
     83                { return this->getIdentifier()->isExactlyA(identifier); }
    8784            /** @brief Returns true if the objects class is a child of the given type. */
    8885            inline bool isChildOf(const Identifier* identifier)
    8986                { return this->getIdentifier()->isChildOf(identifier); }
     87            /** @brief Returns true if the objects class is a direct child of the given type. */
     88            inline bool isDirectChildOf(const Identifier* identifier)
     89                { return this->getIdentifier()->isDirectChildOf(identifier); }
    9090            /** @brief Returns true if the objects class is a parent of the given type. */
    9191            inline bool isParentOf(const Identifier* identifier)
    9292                { return this->getIdentifier()->isParentOf(identifier); }
     93            /** @brief Returns true if the objects class is a direct parent of the given type. */
     94            inline bool isDirectParentOf(const Identifier* identifier)
     95                { return this->getIdentifier()->isDirectParentOf(identifier); }
    9396
    9497
     
    97100                { return this->getIdentifier()->isA(identifier->getIdentifier()); }
    98101            /** @brief Returns true if the objects class is exactly of the given type. */
    99             inline bool isDirectlyA(const SubclassIdentifier<class B>* identifier)
    100                 { return this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); }
     102            inline bool isExactlyA(const SubclassIdentifier<class B>* identifier)
     103                { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); }
    101104            /** @brief Returns true if the objects class is a child of the given type. */
    102105            inline bool isChildOf(const SubclassIdentifier<class B>* identifier)
    103106                { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }
     107            /** @brief Returns true if the objects class is a direct child of the given type. */
     108            inline bool isDirectChildOf(const SubclassIdentifier<class B>* identifier)
     109                { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); }
    104110            /** @brief Returns true if the objects class is a parent of the given type. */
    105111            inline bool isParentOf(const SubclassIdentifier<class B>* identifier)
    106112                { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }
     113            /** @brief Returns true if the objects class is a direct parent of the given type. */
     114            inline bool isDirectParentOf(const SubclassIdentifier<class B>* identifier)
     115                { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); }
    107116
    108117
     
    111120                { return this->getIdentifier()->isA(identifier.getIdentifier()); }
    112121            /** @brief Returns true if the objects class is exactly of the given type. */
    113             inline bool isDirectlyA(const SubclassIdentifier<class B> identifier)
    114                 { return this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); }
     122            inline bool isExactlyA(const SubclassIdentifier<class B> identifier)
     123                { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); }
    115124            /** @brief Returns true if the objects class is a child of the given type. */
    116125            inline bool isChildOf(const SubclassIdentifier<class B> identifier)
    117126                { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }
     127            /** @brief Returns true if the objects class is a direct child of the given type. */
     128            inline bool isDirectChildOf(const SubclassIdentifier<class B> identifier)
     129                { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); }
    118130            /** @brief Returns true if the objects class is a parent of the given type. */
    119131            inline bool isParentOf(const SubclassIdentifier<class B> identifier)
    120132                { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }
     133            /** @brief Returns true if the objects class is a direct parent of the given type. */
     134            inline bool isDirectParentOf(const SubclassIdentifier<class B> identifier)
     135                { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); }
    121136
    122137
     
    125140                { return this->getIdentifier()->isA(object->getIdentifier()); }
    126141            /** @brief Returns true if the objects class is exactly of the given type. */
    127             inline bool isDirectlyA(const OrxonoxClass* object)
    128                 { return this->getIdentifier()->isDirectlyA(object->getIdentifier()); }
     142            inline bool isExactlyA(const OrxonoxClass* object)
     143                { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
    129144            /** @brief Returns true if the objects class is a child of the given type. */
    130145            inline bool isChildOf(const OrxonoxClass* object)
    131146                { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
     147            /** @brief Returns true if the objects class is a direct child of the given type. */
     148            inline bool isDirectChildOf(const OrxonoxClass* object)
     149                { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
    132150            /** @brief Returns true if the objects class is a parent of the given type. */
    133151            inline bool isParentOf(const OrxonoxClass* object)
    134152                { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
     153            /** @brief Returns true if the objects class is a direct child of the given type. */
     154            inline bool isDirectParentOf(const OrxonoxClass* object)
     155                { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
    135156
    136157
Note: See TracChangeset for help on using the changeset viewer.