Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 809 for code/branches/core


Ignore:
Timestamp:
Feb 13, 2008, 2:47:10 AM (17 years ago)
Author:
landauf
Message:

commented and documented ClassManager, IdentifierDistributor and ClassTreeMask

Location:
code/branches/core/src/orxonox/core
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core/src/orxonox/core/ClassManager.h

    r806 r809  
    2626 */
    2727
     28/*!
     29    @file ClassManager.h
     30    @brief Definition and Implementation of the ClassManager template.
     31
     32    The ClassManager is a helper-class for ClassIdentifier. Because ClassIdentifiers must
     33    be unique, they are created through the IdentifierDistributor-class to assure the
     34    uniqueness of the ClassIdentifier. But accessing Identifiers through IdentifierDistributor
     35    is slow, because it uses strings and a map. Thats why we use the ClassManager-template: It's
     36    a singleton like ClassIdentifier, but it doesn't hurt if there are multiple instances in
     37    different libraries, because they all store the same pointer to the unique ClassIdentifier
     38    which they've retrieved through IdentifierDistributor.
     39*/
     40
    2841#ifndef _ClassManager_H__
    2942#define _ClassManager_H__
     
    3851namespace orxonox
    3952{
     53    //! ClassManager is a helper class to allow faster access on the ClassIdentifiers.
     54    /**
     55        Because accessing the IdentifierDistributor is slow, the ClassManager accesses it once
     56        and stores the result in a member-variable. IdentifierDistributor assures the uniqueness
     57        of the ClassIdentifier, even if there are multiple instances of the ClassManager-template
     58        in different libraries.
     59    */
    4060    template <class T>
    4161    class ClassManager
     
    5171            ~ClassManager() {}                                       // don't delete
    5272
    53             bool bInitialized_;
    54             ClassIdentifier<T>* identifier_;
     73            bool bInitialized_;                 //!< This is false until the ClassIdentifier gets assigned
     74            ClassIdentifier<T>* identifier_;    //!< The unique ClassIdentifier for the class T
    5575    };
    5676
     
    82102    ClassIdentifier<T>* ClassManager<T>::getIdentifier(const std::string& name)
    83103    {
     104        // Check if the ClassManager is already initialized
    84105        if (!ClassManager<T>::getSingleton()->bInitialized_)
    85106        {
     107            // It's not -> retrieve the ClassIdentifier through IdentifierDistributor
     108            COUT(4) << "*** Create Identifier Singleton." << std::endl;
    86109
    87             COUT(4) << "*** Create Identifier Singleton." << std::endl;
     110            // First create a ClassIdentifier in case there's no instance existing yet
    88111            ClassIdentifier<T>* temp = new ClassIdentifier<T>();
     112
     113            // Ask the IdentifierDistributor for the unique ClassIdentifier
    89114            ClassManager<T>::getSingleton()->identifier_ = (ClassIdentifier<T>*)IdentifierDistributor::getIdentifier(name, temp);
     115
     116            // If the retrieved Identifier differs from our proposal, we don't need the proposal any more
    90117            if (temp != ClassManager<T>::getSingleton()->identifier_)
    91118                delete temp;
     119
    92120            ClassManager<T>::getSingleton()->bInitialized_ = true;
    93121        }
    94122
     123        // Finally return the unique ClassIdentifier
    95124        return ClassManager<T>::getSingleton()->identifier_;
    96125    }
  • code/branches/core/src/orxonox/core/ClassTreeMask.cc

    r808 r809  
    2626 */
    2727
     28/*!
     29    @file ClassTreeMask.cc
     30    @brief Implementation of the ClassTreeMask, ClassTreeMaskNode and ClassTreeMaskIterator classes.
     31*/
     32
    2833#include "ClassTreeMask.h"
    2934#include "Identifier.h"
     
    3540    // ###    ClassTreeMaskNode    ###
    3641    // ###############################
     42    /**
     43        @brief Constructor: Creates the node, sets the subclass and the rule.
     44        @param subclass The subclass the rule refers to
     45        @param bIncluded The rule: included (true) or excluded (false)
     46    */
    3747    ClassTreeMaskNode::ClassTreeMaskNode(const Identifier* subclass, bool bIncluded)
    3848    {
     
    4151    }
    4252
     53    /**
     54        @brief Destructor: Deletes all subnodes.
     55    */
    4356    ClassTreeMaskNode::~ClassTreeMaskNode()
    4457    {
     58        // Go through the list of all subnodes and delete them
    4559        for (std::list<ClassTreeMaskNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); )
    4660            delete (*(it++));
    4761    }
    4862
     63    /**
     64        @brief Sets the rule for the node to "included".
     65    */
    4966    void ClassTreeMaskNode::include()
    5067    {
     
    5269    }
    5370
     71    /**
     72        @brief Sets the rule for the node to "excluded".
     73    */
    5474    void ClassTreeMaskNode::exclude()
    5575    {
     
    5777    }
    5878
     79    /**
     80        @brief Sets the rule for the node to a given value.
     81        @param bIncluded The rule: included (true) or excluded (false)
     82    */
    5983    void ClassTreeMaskNode::setIncluded(bool bIncluded)
    6084    {
     
    6286    }
    6387
     88    /**
     89        @brief Adds a new subnode to the list of subnodes.
     90        @param subnode The new subnode
     91    */
    6492    void ClassTreeMaskNode::addSubnode(ClassTreeMaskNode* subnode)
    6593    {
     
    6795    }
    6896
     97    /**
     98        @brief Tells if the rule is "included" or not.
     99        @return The rule: true = included, false = excluded
     100    */
    69101    bool ClassTreeMaskNode::isIncluded() const
    70102    {
     
    72104    }
    73105
     106    /**
     107        @brief Tells if the rule is "excluded" or not.
     108        @return The inverted rule: true = excluded, false = included
     109    */
    74110    bool ClassTreeMaskNode::isExcluded() const
    75111    {
     
    77113    }
    78114
     115    /**
     116        @brief Returns the Identifier of the class the rule refers to.
     117        @return The Identifier representing the class
     118    */
    79119    const Identifier* ClassTreeMaskNode::getClass() const
    80120    {
     
    86126    // ###  ClassTreeMaskIterator  ###
    87127    // ###############################
     128    /**
     129        @brief Constructor: Initializes the iterator by creating a helper-list with the root-node and putting it to the stack.
     130        @param node The root-node
     131    */
    88132    ClassTreeMaskIterator::ClassTreeMaskIterator(ClassTreeMaskNode* node)
    89133    {
     134        // Create a list and put the root-note into it
    90135        std::list<ClassTreeMaskNode*>::iterator it = this->rootlist_.insert(this->rootlist_.end(), node);
     136
     137        // Put the iterator to the only element of the list and the corresponding end()-iterator on the stack
    91138        this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>(it, this->rootlist_.end()));
    92139    }
    93140
     141    /**
     142        @brief Destructor: Does nothing.
     143    */
    94144    ClassTreeMaskIterator::~ClassTreeMaskIterator()
    95145    {
    96146    }
    97147
     148    /**
     149        @brief Iterates through the rule-tree.
     150        @return A reference to the iterator itself
     151    */
    98152    ClassTreeMaskIterator& ClassTreeMaskIterator::operator++()
    99153    {
     154        // Check if the actual node has subnodes
    100155        if ((*this->nodes_.top().first)->subnodes_.begin() != (*this->nodes_.top().first)->subnodes_.end())
     156        {
     157            // Yes it has: Push an iterator, pointing at the first subnode, on the stack
    101158            this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>((*this->nodes_.top().first)->subnodes_.begin(), (*this->nodes_.top().first)->subnodes_.end()));
     159        }
    102160        else
    103161        {
     162            // No subnodes, meaning we reached a leaf: Go to the next node
    104163            do
    105164            {
     165                // Iterate one step in the current list
    106166                ++this->nodes_.top().first;
     167
     168                // Check if we reached the end of the list (the second item in the stored pair always represents the end)
    107169                if (this->nodes_.top().first == this->nodes_.top().second)
    108170                {
     171                    // Yes we've reached the end: Pop the list-iterator from the stack
    109172                    this->nodes_.pop();
     173
     174                    // Continue with the loop, meaning: Try to iterate through the previous list
    110175                    continue;
    111176                }
    112177
     178                // If we reached this point, we aren't yet at the end of the list: Leave the loop
    113179                break;
    114             } while (!this->nodes_.empty());
    115         }
    116 
     180            } while (!this->nodes_.empty()); // Stop looping if the stack is empty, meaning: We've iterated to the end
     181        }
     182
     183        // Finally return a reference to the iterator itself
    117184        return *this;
    118185    }
    119186
     187    /**
     188        @brief Returns a pointer to the ClassTreeMaskNode whereon the iterator points.
     189        @return The pointer to the node
     190    */
    120191    ClassTreeMaskNode* ClassTreeMaskIterator::operator*() const
    121192    {
     
    123194    }
    124195
     196    /**
     197        @brief Returns a pointer to the ClassTreeMaskNode whereon the iterator points.
     198        @return The pointer to the node
     199    */
    125200    ClassTreeMaskNode* ClassTreeMaskIterator::operator->() const
    126201    {
     
    128203    }
    129204
     205    /**
     206        @brief Returns true if the stack is empty, meaning we've reached the end of the tree.
     207        @return True if we've reached the end of the tree
     208    */
    130209    ClassTreeMaskIterator::operator bool()
    131210    {
     
    133212    }
    134213
     214    /**
     215        @brief Compares the current node with the given one and returns true if they match.
     216        @param compare The node to compare with
     217        @return The result of the comparison (true if they match)
     218    */
    135219    bool ClassTreeMaskIterator::operator==(ClassTreeMaskNode* compare)
    136220    {
     
    141225    }
    142226
     227    /**
     228        @brief Compares the current node with the given one and returns true if they don't match.
     229        @param compare The node to compare with
     230        @return The result of the comparison (true if they don't match)
     231    */
    143232    bool ClassTreeMaskIterator::operator!=(ClassTreeMaskNode* compare)
    144233    {
     
    153242    // ###      ClassTreeMask      ###
    154243    // ###############################
     244    /**
     245        @brief Constructor: Adds the root-node of the tree with the first rule ("include everything").
     246    */
    155247    ClassTreeMask::ClassTreeMask()
    156248    {
     
    158250    }
    159251
     252    /**
     253        @brief Copyconstructor: Adds the root-node of the tree with the first rule ("include everything") and adds all rules from the other mask.
     254        @param other The other mask
     255    */
    160256    ClassTreeMask::ClassTreeMask(const ClassTreeMask& other)
    161257    {
     
    165261    }
    166262
     263    /**
     264        @brief Destructor: Deletes the root node (which will delete all subnodes too).
     265    */
    167266    ClassTreeMask::~ClassTreeMask()
    168267    {
     
    170269    }
    171270
     271    /**
     272        @brief Adds a new "include" rule for a given subclass to the mask.
     273        @param subclass The subclass
     274    */
    172275    void ClassTreeMask::include(const Identifier* subclass)
    173276    {
     
    175278    }
    176279
     280    /**
     281        @brief Adds a new "exclude" rule for a given subclass to the mask.
     282        @param subclass The subclass
     283    */
    177284    void ClassTreeMask::exclude(const Identifier* subclass)
    178285    {
     
    180287    }
    181288
     289    /**
     290        @brief Adds a new rule for a given subclass to the mask.
     291        @param subclass The subclass
     292        @param bInclude The rule: include (true) or exclude (false)
     293    */
    182294    void ClassTreeMask::add(const Identifier* subclass, bool bInclude)
    183295    {
     
    185297    }
    186298
     299    /**
     300        @brief Adds a new rule for a given subclass to a node of the internal rule-tree (recursive function).
     301        @param node The node
     302        @param subclass The subclass
     303        @param bInclude The rule: include (true) or exclude (false)
     304    */
    187305    void ClassTreeMask::add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude)
    188306    {
     
    201319                if (subclass->isA((*it)->getClass()))
    202320                {
    203                     // We've found an existing node -> delegate the work and return
     321                    // We've found an existing node -> delegate the work with a recursive function-call and return
    204322                    this->add(*it, subclass, bInclude);
    205323                    return;
     
    230348    }
    231349
     350    /**
     351        @brief Resets the mask to "include everything".
     352    */
    232353    void ClassTreeMask::reset()
    233354    {
     
    236357    }
    237358
     359    /**
     360        @brief Tells if a given subclass is included or not.
     361        @param subclass The subclass
     362        @return Included (true) or excluded (false)
     363    */
    238364    bool ClassTreeMask::isIncluded(const Identifier* subclass) const
    239365    {
     
    241367    }
    242368
     369    /**
     370        @brief Tells if a given subclass of a node in the rule-tree is included or not (recursive function).
     371        @param node The node
     372        @param subclass The subclass
     373        @return Included (true) or excluded (false)
     374    */
    243375    bool ClassTreeMask::isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const
    244376    {
    245 //std::cout << "1_1: " << subclass->getName() << " (" << subclass << ") / " << node->getClass()->getName() << " (" << node->getClass() << ")" << std::endl;
    246377        // Check if the searched subclass is of the same type as the class in the current node or a derivative
    247378        if (subclass->isA(node->getClass()))
     
    251382                return node->isIncluded();
    252383
    253             // Go through the list of subnodes and look for a node containing the searched subclass
     384            // Go through the list of subnodes and look for a node containing the searched subclass and delegate the request by a recursive function-call.
    254385            for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); ++it)
    255386                if (subclass->isA((*it)->getClass()))
     
    266397    }
    267398
     399    /**
     400        @brief Tells if a given subclass is excluded or not.
     401        @param subclass The subclass
     402        @return The inverted rule: Excluded (true) or included (false)
     403    */
    268404    bool ClassTreeMask::isExcluded(const Identifier* subclass) const
    269405    {
     
    271407    }
    272408
     409    /**
     410        @brief Removes all unneeded rules that don't change the information of the mask.
     411    */
    273412    void ClassTreeMask::clean()
    274413    {
     
    276415    }
    277416
     417    /**
     418        @brief Removes all unneded rules that don't change the information of a node of a mask (recursive function).
     419        @param node The node
     420    */
    278421    void ClassTreeMask::clean(ClassTreeMaskNode* node)
    279422    {
    280 //std::cout << "4_1: " << node->getClass()->getName() << ": " << node->isIncluded() << "\n";
     423        // Iterate through all subnodes of the given node
    281424        for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); )
    282425        {
    283 //std::cout << "4_2: " << (*it)->getClass()->getName() << ": " << (*it)->isIncluded() << "\n";
     426            // Recursive function-call: Clean the subnode
    284427            this->clean(*it);
    285 //std::cout << "4_3\n";
     428
     429            // Now check if the subnode contains the same rule as the current node
    286430            if ((*it)->isIncluded() == node->isIncluded())
    287431            {
    288 //std::cout << "4_4\n";
     432                // It does: Move all subnodes of the redundant subnode to the current node
    289433                node->subnodes_.insert(node->subnodes_.end(), (*it)->subnodes_.begin(), (*it)->subnodes_.end());
    290434                (*it)->subnodes_.clear();
    291                 node->subnodes_.erase(it);
    292                 it = node->subnodes_.begin();
    293 //std::cout << "4_5\n";
     435
     436                // Remove the redundant subnode from the current node
     437                node->subnodes_.erase(it++);
    294438            }
    295439            else
    296440            {
    297 //std::cout << "4_6\n";
     441                // The subnode is necessary: Move on to the next subnode
    298442                ++it;
    299443            }
    300444        }
    301 //std::cout << "4_7\n";
    302     }
    303 
     445    }
     446
     447    /**
     448        @brief Assignment operator: Adds all rules of the other mask.
     449        @param other The other mask
     450        @return A reference to the mask itself
     451    */
    304452    ClassTreeMask& ClassTreeMask::operator=(const ClassTreeMask& other)
    305453    {
     454        // Make a copy to avoid troubles with self-assignments (like A = A).
    306455        ClassTreeMask temp(other);
    307456
     457        // Removes all current rules
    308458        this->reset();
    309459
     460        // Copy all rules from the other mask
    310461        for (ClassTreeMaskIterator it = temp.root_; it; ++it)
    311462            this->add(it->getClass(), it->isIncluded());
    312463
     464        // Return a reference to the mask itself
    313465        return (*this);
    314466    }
    315467
     468    /**
     469        @brief Prefix operator + does nothing.
     470        @return A reference to the mask itself
     471    */
    316472    ClassTreeMask& ClassTreeMask::operator+()
    317473    {
     
    319475    }
    320476
     477    /**
     478        @brief Prefix operator - inverts the mask.
     479        @return The inverted mask
     480    */
    321481    ClassTreeMask ClassTreeMask::operator-() const
    322482    {
     
    324484    }
    325485
     486    /**
     487        @brief Adds two masks in the sense of a union (all classes that are included in at least one of the masks will be included in the resulting mask too).
     488        @param other The mask to unite with
     489        @return The union
     490    */
    326491    ClassTreeMask ClassTreeMask::operator+(const ClassTreeMask& other) const
    327492    {
     493        // Create a new mask
    328494        ClassTreeMask newmask;
     495
     496        // Add all nodes from the first mask, calculate the rule with the or-operation
    329497        for (ClassTreeMaskIterator it = this->root_; it; ++it)
    330498        {
     
    332500            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass));
    333501        }
     502
     503        // Add all nodes from the second mask, calculate the rule with the or-operation
    334504        for (ClassTreeMaskIterator it = other.root_; it; ++it)
    335505        {
     
    337507            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass));
    338508        }
     509
     510        // Drop all redundant rules
    339511        newmask.clean();
    340512
     513        // Return the new mask
    341514        return newmask;
    342515    }
    343516
     517    /**
     518        @brief Intersects two masks (only classes that are included in both masks will be included in the resulting mask too).
     519        @param other The mask to intersect with
     520        @return The intersection
     521    */
    344522    ClassTreeMask ClassTreeMask::operator*(const ClassTreeMask& other) const
    345523    {
     524        // Create a new mask
    346525        ClassTreeMask newmask;
     526
     527        // Add all nodes from the first mask, calculate the rule with the and-operation
    347528        for (ClassTreeMaskIterator it = this->root_; it; ++it)
    348529        {
     
    350531            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass));
    351532        }
     533
     534        // Add all nodes from the second mask, calculate the rule with the and-operation
    352535        for (ClassTreeMaskIterator it = other.root_; it; ++it)
    353536        {
     
    355538            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass));
    356539        }
     540
     541        // Drop all redundant rules
    357542        newmask.clean();
    358543
     544        // Return the new mask
    359545        return newmask;
    360546    }
    361547
     548    /**
     549        @brief Removes all elements of the second mask from the first mask (all classes that are included in the first mask stay included, except those that are included in the second mask too).
     550        @param other The mask to subtract.
     551        @return The difference
     552    */
    362553    ClassTreeMask ClassTreeMask::operator-(const ClassTreeMask& other) const
    363554    {
     
    365556    }
    366557
     558    /**
     559        @brief Inverts the mask (all included classes are now excluded and vice versa).
     560        @return The complement
     561    */
    367562    ClassTreeMask ClassTreeMask::operator!() const
    368563    {
     564        // Create a new mask
    369565        ClassTreeMask newmask;
     566
     567        // Add all nodes from the other mask, inverting the rules
    370568        for (ClassTreeMaskIterator it = this->root_; it; ++it)
    371569        {
     
    373571            newmask.add(subclass, !this->isIncluded(subclass));
    374572        }
     573
     574        // Return the new mask
    375575        return newmask;
    376576    }
    377577
     578    /**
     579        @brief Unites this mask with another mask.
     580        @param other The other mask
     581        @return A reference to the mask itself
     582    */
    378583    ClassTreeMask& ClassTreeMask::operator+=(const ClassTreeMask& other)
    379584    {
     
    382587    }
    383588
     589    /**
     590        @brief Intersects this mask with another mask.
     591        @param other The other mask
     592        @return A reference to the mask itself
     593    */
    384594    ClassTreeMask& ClassTreeMask::operator*=(const ClassTreeMask& other)
    385595    {
     
    388598    }
    389599
     600    /**
     601        @brief Subtracts another mask from this mask.
     602        @param other The other mask
     603        @return A reference to the mask itself
     604    */
    390605    ClassTreeMask& ClassTreeMask::operator-=(const ClassTreeMask& other)
    391606    {
     
    394609    }
    395610
     611    /**
     612        @brief Intersects two masks (only classes that are included in both masks will be included in the resulting mask too).
     613        @param other The mask to intersect with
     614        @return The intersection
     615    */
    396616    ClassTreeMask ClassTreeMask::operator&(const ClassTreeMask& other) const
    397617    {
     
    399619    }
    400620
     621    /**
     622        @brief Adds two masks in the sense of a union (all classes that are included in at least one of the masks will be included in the resulting mask too).
     623        @param other The mask to unite with
     624        @return The union
     625    */
    401626    ClassTreeMask ClassTreeMask::operator|(const ClassTreeMask& other) const
    402627    {
     
    404629    }
    405630
     631    /**
     632        @brief Joins two masks in the sense of a xor (exclusivity) operation (all classes that are included in exactly one of the masks, but not in both, will be included in the resulting mask too).
     633        @param other The mask to join with
     634        @return The result
     635    */
    406636    ClassTreeMask ClassTreeMask::operator^(const ClassTreeMask& other) const
    407637    {
     638        // Create a new mask
    408639        ClassTreeMask newmask;
     640
     641        // Add all nodes from the first mask, calculate the rule with the xor-operation
    409642        for (ClassTreeMaskIterator it = this->root_; it; ++it)
    410643        {
     
    412645            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass));
    413646        }
     647
     648        // Add all nodes from the second mask, calculate the rule with the xor-operation
    414649        for (ClassTreeMaskIterator it = other.root_; it; ++it)
    415650        {
     
    417652            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass));
    418653        }
     654
     655        // Drop all redundant rules
    419656        newmask.clean();
    420657
     658        // Return the new mask
    421659        return newmask;
    422660    }
    423661
     662    /**
     663        @brief Inverts the mask (all included classes are now excluded and vice versa).
     664        @return The complement
     665    */
    424666    ClassTreeMask ClassTreeMask::operator~() const
    425667    {
     
    427669    }
    428670
     671    /**
     672        @brief Intersects this mask with another mask (and-operation)
     673        @param other The other mask
     674        @return A reference to the mask itself
     675    */
    429676    ClassTreeMask& ClassTreeMask::operator&=(const ClassTreeMask& other)
    430677    {
     
    433680    }
    434681
     682    /**
     683        @brief Unites this mask with another mask (or-operation).
     684        @param other The other mask
     685        @return A reference to the mask itself
     686    */
    435687    ClassTreeMask& ClassTreeMask::operator|=(const ClassTreeMask& other)
    436688    {
     
    439691    }
    440692
     693    /**
     694        @brief Joins this mask with another mask with a xor-operation.
     695        @param other The other mask
     696        @return A reference to the mask itself
     697    */
    441698    ClassTreeMask& ClassTreeMask::operator^=(const ClassTreeMask& other)
    442699    {
     
    445702    }
    446703
     704    /**
     705        @brief Converts the content of a mask into a human readable string and puts it on the ostream.
     706        @param out The ostream
     707        @param mask The mask
     708        @return A reference to the ostream
     709    */
    447710    std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask)
    448711    {
     712        // Iterate through all rules
    449713        for (ClassTreeMaskIterator it = mask.root_; it; ++it)
    450714        {
     715            // Calculate the prefix: + means included, - means excluded
    451716            if (it->isIncluded())
    452717                out << "+";
     
    454719                out << "-";
    455720
     721            // Put the name of the corresponding class on the stream
    456722            out << it->getClass()->getName() << " ";
    457723        }
  • code/branches/core/src/orxonox/core/ClassTreeMask.h

    r807 r809  
    2626 */
    2727
     28/*!
     29    @file ClassTreeMask.h
     30    @brief Definition of the ClassTreeMask, ClassTreeMaskNode and ClassTreeMaskIterator classes.
     31
     32    ClassTreeMask is a class to define a mask of the class-tree beginning with BaseObject.
     33    You can include or exclude classes by calling the corresponding functions with the
     34    Identifier of the class.
     35
     36    You can work with a ClassTreeMask in the sense of the set theory, meaning that you can create
     37    unions, intersections, complements and differences by using overloaded operators.
     38
     39    The ClassTreeMask is internally represented by a tree. The nodes in the tree are
     40    ClassTreeMaskNodes, containing the rule (included or excluded) for this class and all
     41    subclasses and a list of all subnodes. To minimize the size, the tree contains only
     42    nodes changing the mask. By adding new rules, the tree gets reordered dynamically.
     43
     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().
     50
     51    Because of the complicated shape of the internal tree, there is an iterator to iterate
     52    through all ClassTreeMaskNodes of a mask. It starts with the BaseObject and moves on to
     53    the first subclass until it reaches a leaf of the tree. Then the iterator moves one step
     54    back and iterates to the second subclass. If there are no more subclasses, it steps another
     55    step back, and so on.
     56
     57    Example: A and B are childs of BaseObject, A1 and A2 are childs of A, B1 and B2 are childs of B.
     58    The ClassTreeMaskIterator would move trough the tree in the following order:
     59    BaseObject, A, A1, A2, B, B1, B2.
     60
     61    Note that the iterator doesn't move trough the whole class-tree, but only through the
     62    internal tree of the mask, containing the minimal needed set of nodes to describe the mask.
     63*/
     64
    2865#ifndef _ClassTreeMask_H__
    2966#define _ClassTreeMask_H__
     
    3673namespace orxonox
    3774{
     75    // ###############################
     76    // ###    ClassTreeMaskNode    ###
     77    // ###############################
     78    //! The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask.
     79    /**
     80        The ClassTreeMaskNode is used to store the rule (included or excluded) for a given
     81        class (described by the corresponding Identifier). The nodes are used in the internal
     82        tree of ClassTreeMask. To build a tree, they store a list of all subnodes.
     83    */
    3884    class ClassTreeMaskNode
    3985    {
     
    57103
    58104        private:
    59             const Identifier* subclass_;
    60             bool bIncluded_;
    61             std::list<ClassTreeMaskNode*> subnodes_;
     105            const Identifier* subclass_;                //!< The Identifier of the subclass the rule refers to
     106            bool bIncluded_;                            //!< The rule: included or excluded
     107            std::list<ClassTreeMaskNode*> subnodes_;    //!< A list containing all subnodes in the tree
    62108    };
    63109
     110
     111    // ###############################
     112    // ###  ClassTreeMaskIterator  ###
     113    // ###############################
     114    //! The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask, containing the rules.
     115    /**
     116        Because of the complicated shape of the internal rule-tree of ClassTreeMask, an
     117        iterator is used to move through all nodes of the tree. It starts with the BaseObject
     118        and moves on to the first subclass until it reaches a leaf of the tree. Then the
     119        iterator moves one step back and iterates to the second subclass. If there are no more
     120        subclasses, it steps another step back, and so on.
     121    */
    64122    class ClassTreeMaskIterator
    65123    {
     
    76134
    77135        private:
    78             std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_;
    79             std::list<ClassTreeMaskNode*> rootlist_;
     136            std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_;    //!< A stack to store list-iterators
     137            std::list<ClassTreeMaskNode*> rootlist_;                                                                            //!< A list for internal use (it only stores the root-node)
    80138    };
    81139
     140
     141    // ###############################
     142    // ###      ClassTreeMask      ###
     143    // ###############################
     144    //! The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not.
     145    /**
     146        With a ClassTreeMask, you can include or exclude subtrees of the class-tree, starting
     147        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.
     152    */
    82153    class ClassTreeMask
    83154    {
     
    126197            void clean(ClassTreeMaskNode* node);
    127198
    128             ClassTreeMaskNode* root_;
     199            ClassTreeMaskNode* root_;   //!< The root-node of the internal rule-tree, usually BaseObject
    129200    };
    130201}
  • code/branches/core/src/orxonox/core/Identifier.h

    r806 r809  
    180180        This makes it possible to store informations about a class, sharing them with all
    181181        objects of that class without defining static variables in every class.
     182
     183        To be really sure that not more than exactly one object exists (even with libraries),
     184        ClassIdentifiers are only created by IdentifierDistributor.
     185
     186        You can access the ClassIdentifiers created by IdentifierDistributor through the
     187        ClassManager singletons.
    182188    */
    183189    template <class T>
  • code/branches/core/src/orxonox/core/IdentifierDistributor.cc

    r805 r809  
    2626 */
    2727
     28/*!
     29    @file IdentifierDistributor.cc
     30    @brief Implementation of the IdentifierDistributor class.
     31*/
     32
    2833#include "IdentifierDistributor.h"
    2934#include "Identifier.h"
     
    3136namespace orxonox
    3237{
     38    /**
     39        @brief Returns the only instance of a ClassIdentifier for a given class.
     40        @param name The name of the class
     41        @param proposal A proposal for the ClassIdentifier in case there is no entry yet.
     42        @return The unique ClassIdentifier
     43    */
    3344    Identifier* IdentifierDistributor::getIdentifier(const std::string& name, Identifier* proposal)
    3445    {
     46        // Create the only instance of the IdentifierDistributor-singleton
    3547        static IdentifierDistributor theOneAndOnlyInstance = IdentifierDistributor();
    3648
     49        // Look for an entry in the map
    3750        std::map<std::string, Identifier*>::const_iterator it = theOneAndOnlyInstance.identifiers_.find(name);
    3851        if (it != theOneAndOnlyInstance.identifiers_.end())
    3952        {
     53            // There is already an entry: return it
    4054            return (*it).second;
    4155        }
    4256        else
    4357        {
     58            // There is no entry: put the proposal into the map and return it
    4459            theOneAndOnlyInstance.identifiers_[name] = proposal;
    4560            return proposal;
  • code/branches/core/src/orxonox/core/IdentifierDistributor.h

    r805 r809  
    2626 */
    2727
     28/*!
     29    @file IdentifierDistributor.h
     30    @brief Definition of the IdentifierDistributor class
     31
     32    The IdentifierDistributor makes sure that only one instance of ClassIdentifier for each
     33    template parameter T exists. All Identifiers are stored in a map with their name.
     34    IdentifierDistributor is a singleton class, it can't be created or deleted directly.
     35*/
     36
    2837#ifndef _IdentifierDistributor_H__
    2938#define _IdentifierDistributor_H__
     
    3544namespace orxonox
    3645{
     46    //! The Identifier Distributor stores all Identifiers and makes sure there are no ambiguities.
    3747    class IdentifierDistributor
    3848    {
     
    4151
    4252        private:
    43             IdentifierDistributor() {};
    44             IdentifierDistributor(const IdentifierDistributor& distributor) {}
    45             ~IdentifierDistributor() {}
     53            IdentifierDistributor() {};                                         // Don't create
     54            IdentifierDistributor(const IdentifierDistributor& distributor) {}  // Don't copy
     55            ~IdentifierDistributor() {}                                         // Don't delete
    4656
    47             std::map<std::string, Identifier*> identifiers_;
     57            std::map<std::string, Identifier*> identifiers_;    //!< The map to store all Identifiers.
    4858    };
    4959}
Note: See TracChangeset for help on using the changeset viewer.