RSC  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoggerTreeNode.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSC project.
4  *
5  * Copyright (C) 2011 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <map>
30 #include <string>
31 #include <vector>
32 
33 #include <boost/enable_shared_from_this.hpp>
34 #include <boost/function.hpp>
35 #include <boost/shared_ptr.hpp>
36 
37 #include "LoggerProxy.h"
38 
39 namespace rsc {
40 namespace logging {
41 
43 typedef boost::shared_ptr<LoggerTreeNode> LoggerTreeNodePtr;
44 typedef boost::weak_ptr<LoggerTreeNode> LoggerTreeNodeWeakPtr;
45 
55 class LoggerTreeNode: public boost::enable_shared_from_this<LoggerTreeNode> {
56 public:
57 
62  typedef std::vector<std::string> NamePath;
63 
71  LoggerTreeNode(const std::string& name, LoggerTreeNodeWeakPtr parent);
72 
80  LoggerTreeNode(const std::string& name, LoggerProxyPtr loggerProxy,
82 
84 
85  std::string getName() const;
86 
88 
90 
97  bool addChild(LoggerTreeNodePtr child);
98 
99  typedef boost::function<
101 
112  CreateFunction createFn, const NamePath &processedPath = NamePath());
113 
119  class Visitor {
120  public:
121  virtual ~Visitor();
122 
131  virtual bool visit(const NamePath& path, LoggerTreeNodePtr node, const Logger::Level& parentLevel) = 0;
132 
133  };
134  typedef boost::shared_ptr<Visitor> VisitorPtr;
135 
141  void visit(VisitorPtr visitor, const NamePath& thisPath = NamePath());
142 
143  bool hasChild(const std::string& name) const;
144 
145  bool hasChild(const NamePath& path) const;
146 
147  LoggerTreeNodePtr getChild(const std::string& name) const;
148 
149  LoggerTreeNodePtr getChild(const NamePath& path) const;
150 
151  void clearChildren();
152 
161  static NamePath nameToPath(const std::string& name);
162  static std::string pathToName(const NamePath& path);
163 
164  boost::shared_ptr<Logger::Level> getAssignedLevel() const;
165  void setAssignedLevel(boost::shared_ptr<Logger::Level> level);
166  void setAssignedLevel(const Logger::Level& level);
167  bool hasAssignedLevel() const;
168 
169 private:
170 
175  std::string name;
177 
179  std::map<std::string, LoggerTreeNodePtr> children;
180 
181  boost::shared_ptr<Logger::Level> assignedLevel;
182 
183 };
184 
185 }
186 }
187