4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
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.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Node public header */
31 #include <boost/shared_ptr.hpp>
32 #include <boost/weak_ptr.hpp>
33 #include <boost/enable_shared_from_this.hpp>
34 #include <boost/utility.hpp>
35 #include <boost/range/iterator_range.hpp>
36 #include "../Utils/Exception.hh"
39 ///////////////////////////////hh.p////////////////////////////////////////
50 : public boost::enable_shared_from_this<GenericNode>
53 ///////////////////////////////////////////////////////////////////////////
56 typedef boost::shared_ptr<GenericNode> ptr;
57 typedef boost::shared_ptr<GenericNode const> cptr;
58 typedef boost::weak_ptr<GenericNode> weak_ptr;
60 ///////////////////////////////////////////////////////////////////////////
62 virtual ~GenericNode();
64 std::string const & name() const;
65 boost::shared_ptr<DirectoryNode> parent() const;
68 std::string path() const;
74 explicit GenericNode(std::string const & name);
76 void name(std::string const & name);
77 static void name(GenericNode & node, std::string const & name);
78 void parent(DirectoryNode * parent);
82 DirectoryNode * parent_;
84 friend class intrusive_refcount_base;
85 friend class DirectoryNode;
90 class DirectoryNode : public GenericNode
92 typedef std::map<std::string, GenericNode::ptr> ChildMap;
95 ///////////////////////////////////////////////////////////////////////////
98 typedef boost::shared_ptr<DirectoryNode> ptr;
99 typedef boost::shared_ptr<DirectoryNode const> cptr;
100 typedef boost::weak_ptr<DirectoryNode> weak_ptr;
102 typedef boost::iterator_range<ChildMap::const_iterator> ChildrenRange;
103 typedef ChildMap::const_iterator child_iterator;
105 ///////////////////////////////////////////////////////////////////////////
107 GenericNode & add(std::auto_ptr<GenericNode> node, bool uniquify = true);
109 DirectoryNode & operator[](std::string const & name) const;
110 CommandNode & operator()(std::string const & name) const;
111 GenericNode & get(std::string const & name) const;
113 DirectoryNode & mkdir(std::string const & name);
115 ChildrenRange children() const;
117 template <class ForwardRange>
118 GenericNode & traverse(ForwardRange const & range);
121 cptr thisptr() const;
124 explicit DirectoryNode(std::string const & name);
127 void add(GenericNode::ptr node, bool uniquify);
131 friend DirectoryNode & root();
134 struct DuplicateNodeNameException : public senf::Exception
135 { DuplicateNodeNameException() : senf::Exception("Duplicate node name") {}};
137 struct UnknownNodeNameException : public senf::Exception
138 { UnknownNodeNameException() : senf::Exception("Unknown node name") {}};
142 class CommandNode : public GenericNode
145 ///////////////////////////////////////////////////////////////////////////
148 typedef boost::shared_ptr<CommandNode> ptr;
149 typedef boost::shared_ptr<CommandNode const> cptr;
150 typedef boost::weak_ptr<CommandNode> weak_ptr;
152 ///////////////////////////////////////////////////////////////////////////
155 cptr thisptr() const;
158 explicit CommandNode(std::string const & name);
164 DirectoryNode & root();
168 ///////////////////////////////hh.e////////////////////////////////////////
171 //#include "Node.cti"
178 // comment-column: 40
179 // c-file-style: "senf"
180 // indent-tabs-mode: nil
181 // ispell-local-dictionary: "american"
182 // compile-command: "scons -u test"