Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 19, 2008, 12:38:32 AM (16 years ago)
Author:
landauf
Message:

Namespaces are working now. I love this feature, can't stop playing with it :D

File:
1 edited

Legend:

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

    r895 r901  
    4949        std::set<NamespaceNode*> nodes;
    5050
    51         if (name == "")
     51        if ((name.size() == 0) || (name == ""))
    5252        {
    5353            nodes.insert(this);
     
    5656        {
    5757            unsigned int pos = name.find("::");
    58             std::string firstPart = name.substr(0, pos);
    59             std::string secondPart = name.substr(pos + 2, std::string::npos);
     58            std::string firstPart = name;
     59            std::string secondPart;
     60
     61            if (pos != std::string::npos)
     62            {
     63                firstPart = name.substr(0, pos);
     64                secondPart = name.substr(pos + 2, std::string::npos);
     65            }
    6066
    6167            if (firstPart == "..")
     
    6470                {
    6571                    COUT(2) << "Warning: Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", namespace is root." << std::endl;
     72                    nodes = this->getNodeRelative(secondPart);
     73                }
     74                else if (!this->parent_)
     75                {
     76                    COUT(2) << "Warning: Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", no parent namespace set." << std::endl;
    6677                    nodes = this->getNodeRelative(secondPart);
    6778                }
     
    7889
    7990                if ((*it).second->isHidden())
     91                {
    8092                    COUT(2) << "Warning: Subnamespace '" << firstPart << "' in namespace '" << this->name_ << "' is hidden and can't be accessed." << std::endl;
     93                    nodes.insert(this);
     94                }
    8195                else
     96                {
    8297                    nodes = (*it).second->getNodeRelative(secondPart);
     98                }
    8399            }
    84100            else
    85101            {
     102                bool bFoundMatchingNamespace = false;
     103
    86104                for (std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
    87105                {
     
    90108                        std::set<NamespaceNode*> temp2 = (*it).second->getNodeRelative(secondPart);
    91109                        nodes.insert(temp2.begin(), temp2.end());
     110                        bFoundMatchingNamespace = true;
    92111                    }
     112                }
     113
     114                if (!bFoundMatchingNamespace)
     115                {
     116                    COUT(2) << "Warning: No file included with name '" << firstPart.substr(1, std::string::npos) << "' at this part of the level file, using parent namespace instead." << std::endl;
     117                    nodes = this->getNodeRelative(secondPart);
    93118                }
    94119            }
     
    113138        return false;
    114139    }
     140
     141    std::string NamespaceNode::toString() const
     142    {
     143        std::string output = this->name_;
     144
     145        if (this->subnodes_.size() > 0)
     146        {
     147            output += " (";
     148
     149            int i = 0;
     150            for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); i++, ++it)
     151            {
     152                if (i > 0)
     153                    output += ", ";
     154
     155                output += (*it).second->toString();
     156            }
     157
     158            output += ")";
     159        }
     160
     161        return output;
     162    }
     163
     164    std::string NamespaceNode::toString(const std::string& indentation) const
     165    {
     166        std::string output = (indentation + this->name_ + "\n");
     167
     168        for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
     169            output += (*it).second->toString(indentation + "  ");
     170
     171        return output;
     172    }
    115173}
Note: See TracChangeset for help on using the changeset viewer.