Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/NamespaceNode.cc @ 10745

Last change on this file since 10745 was 8858, checked in by landauf, 13 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
  • Property svn:eol-style set to native
File size: 5.8 KB
RevLine 
[1505]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "NamespaceNode.h"
[8858]30#include "util/Output.h"
[1505]31
32namespace orxonox
33{
34    NamespaceNode::NamespaceNode(const std::string& name, NamespaceNode* parent)
35    {
36        this->name_ = name;
37        this->parent_ = parent;
38        this->bRoot_ = false;
39        this->bHidden_ = false;
40    }
41
42    NamespaceNode::~NamespaceNode()
43    {
44        for (std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); )
[6417]45            delete (it++)->second;
[1505]46    }
47
48    std::set<NamespaceNode*> NamespaceNode::getNodeRelative(const std::string& name)
49    {
50        std::set<NamespaceNode*> nodes;
51
[6417]52        if (name.empty())
[1505]53        {
54            nodes.insert(this);
55        }
56        else
57        {
[1889]58            size_t pos = name.find("::");
[1505]59            std::string firstPart = name;
60            std::string secondPart;
61
62            if (pos != std::string::npos)
63            {
64                firstPart = name.substr(0, pos);
65                secondPart = name.substr(pos + 2, std::string::npos);
66            }
67
68            if (firstPart == "..")
69            {
70                if (this->bRoot_)
71                {
[8858]72                    orxout(internal_warning) << "Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", namespace is root." << endl;
[1505]73                    nodes = this->getNodeRelative(secondPart);
74                }
75                else if (!this->parent_)
76                {
[8858]77                    orxout(internal_warning) << "Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", no parent namespace set." << endl;
[1505]78                    nodes = this->getNodeRelative(secondPart);
79                }
80                else
81                {
82                    nodes = this->parent_->getNodeRelative(secondPart);
83                }
84            }
85            else if (name.find('@') != 0)
86            {
87                std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.find(firstPart);
88                if (it == this->subnodes_.end())
89                    it = this->subnodes_.insert(this->subnodes_.begin(), std::pair<std::string, NamespaceNode*>(firstPart, new NamespaceNode(firstPart, this)));
90
[6417]91                if (it->second->isHidden())
[1505]92                {
[8858]93                    orxout(internal_warning) << "Subnamespace '" << firstPart << "' in namespace '" << this->name_ << "' is hidden and can't be accessed." << endl;
[1505]94                    nodes.insert(this);
95                }
96                else
97                {
[6417]98                    nodes = it->second->getNodeRelative(secondPart);
[1505]99                }
100            }
101            else
102            {
103                bool bFoundMatchingNamespace = false;
104
105                for (std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
106                {
[6417]107                    if (it->first.find(firstPart) == (it->first.size() - firstPart.size()))
[1505]108                    {
[6417]109                        std::set<NamespaceNode*> temp2 = it->second->getNodeRelative(secondPart);
[1505]110                        nodes.insert(temp2.begin(), temp2.end());
111                        bFoundMatchingNamespace = true;
112                    }
113                }
114
115                if (!bFoundMatchingNamespace)
116                {
[8858]117                    orxout(internal_warning) << "No file included with name '" << firstPart.substr(1, std::string::npos) << "' at this part of the level file, using parent namespace instead." << endl;
[1505]118                    nodes = this->getNodeRelative(secondPart);
119                }
120            }
121        }
122
123        return nodes;
124    }
125
126    bool NamespaceNode::includes(const NamespaceNode* ns) const
127    {
128        if (ns == this)
129        {
130            return true;
131        }
132        else
133        {
134            for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
[6417]135                if (it->second->includes(ns))
[1505]136                    return true;
137        }
138
139        return false;
140    }
141
142    std::string NamespaceNode::toString() const
143    {
144        std::string output = this->name_;
145
146        if (this->subnodes_.size() > 0)
147        {
148            output += " (";
149
150            int i = 0;
151            for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); i++, ++it)
152            {
153                if (i > 0)
154                    output += ", ";
155
[6417]156                output += it->second->toString();
[1505]157            }
158
[6417]159            output += ')';
[1505]160        }
161
162        return output;
163    }
164
165    std::string NamespaceNode::toString(const std::string& indentation) const
166    {
[6417]167        std::string output = (indentation + this->name_ + '\n');
[1505]168
169        for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
[6417]170            output += it->second->toString(indentation + "  ");
[1505]171
172        return output;
173    }
174}
Note: See TracBrowser for help on using the repository browser.