29 #include <boost/format.hpp> 30 #include <boost/algorithm/string.hpp> 40 name(name), parent(parent) {
45 name(name), loggerProxy(loggerProxy), parent(parent) {
72 if (path.size() == 0) {
73 throw invalid_argument(
"Empty path given");
76 const string directChildName = path.front();
78 subPath.erase(subPath.begin());
80 childPath.push_back(directChildName);
85 children[path.front()]->setLoggerProxy(
86 createFn(childPath,
children[directChildName]));
89 if (path.size() > 1) {
90 return children[directChildName]->addChildren(subPath, createFn,
103 for (map<string, LoggerTreeNodePtr>::const_iterator it =
children.begin();
107 childPath.push_back(it->first);
109 bool descend = visitor->visit(childPath, it->second,
112 it->second->visit(visitor, childPath);
124 if (path.size() == 0) {
125 throw invalid_argument(
"Empty name path given");
127 map<string, LoggerTreeNodePtr>::const_iterator childIt =
children.find(
133 subPath.erase(subPath.begin());
134 return childIt->second->hasChild(subPath);
138 map<string, LoggerTreeNodePtr>::const_iterator it =
children.find(name);
140 throw invalid_argument(
142 boost::format(
"No direct child with name %1 exists.")
149 if (path.size() == 0) {
150 throw invalid_argument(
"Empty name path given");
152 map<string, LoggerTreeNodePtr>::const_iterator childIt =
children.find(
155 throw invalid_argument(
157 boost::format(
"No direct child with name %1 exists.")
161 subPath.erase(subPath.begin());
162 return childIt->second->getChild(subPath);
177 string lowerName =
name;
178 boost::algorithm::to_lower(lowerName);
179 boost::algorithm::split(path, lowerName, boost::algorithm::is_any_of(
"."));
182 assert(path.size() > 0);
189 if (path.back() ==
"level" || path.back() ==
"system") {
190 throw invalid_argument(
191 "Logger names must not end with system or level (case-insensitive), but I received: '" 200 for (NamePath::const_iterator it = path.begin(); it != path.end(); ++it) {
202 if (it != --path.end()) {
boost::shared_ptr< LoggerProxy > LoggerProxyPtr
LoggerTreeNodePtr getParent() const
void setAssignedLevel(boost::shared_ptr< Logger::Level > level)
LoggerTreeNodePtr getChild(const std::string &name) const
LoggerTreeNodeWeakPtr parent
pair< _T1, _T2 > make_pair(_T1 __x, _T2 __y)
A convenience wrapper for creating a pair from two objects.
void setLoggerProxy(LoggerProxyPtr loggerProxy)
std::vector< std::string > NamePath
A unique representation of a name.
Level
Possible logging levels.
LoggerProxyPtr getLoggerProxy() const
LoggerProxyPtr loggerProxy
std::string name
New name part of this node.
LoggerTreeNode(const std::string &name, LoggerTreeNodeWeakPtr parent)
Creates a new node without an assigned LoggerProxy.
bool hasChild(const std::string &name) const
boost::shared_ptr< Logger::Level > getAssignedLevel() const
boost::shared_ptr< LoggerTreeNode > LoggerTreeNodePtr
boost::shared_ptr< Visitor > VisitorPtr
boost::shared_ptr< Logger::Level > assignedLevel
std::string getName() const
std::map< std::string, LoggerTreeNodePtr > children
bool hasAssignedLevel() const
void visit(VisitorPtr visitor, const NamePath &thisPath=NamePath())
Visits every sub-node excluding this node.
boost::function< LoggerProxyPtr(const NamePath &name, LoggerTreeNodePtr node)> CreateFunction
boost::weak_ptr< LoggerTreeNode > LoggerTreeNodeWeakPtr
static std::string pathToName(const NamePath &path)
static NamePath nameToPath(const std::string &name)
Converts a string name of the form a.test.string to a hierarchical logger path representation.
LoggerTreeNodePtr addChildren(const NamePath &path, CreateFunction createFn, const NamePath &processedPath=NamePath())
Retrieves an (indirect) child and creates required ancestors of this child using a custom callback me...
bool addChild(LoggerTreeNodePtr child)
Adds a child if it does not exist so far.