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"
40 ///////////////////////////////hh.p////////////////////////////////////////
51 : public boost::enable_shared_from_this<GenericNode>
54 ///////////////////////////////////////////////////////////////////////////
57 typedef boost::shared_ptr<GenericNode> ptr;
58 typedef boost::shared_ptr<GenericNode const> cptr;
59 typedef boost::weak_ptr<GenericNode> weak_ptr;
61 ///////////////////////////////////////////////////////////////////////////
63 virtual ~GenericNode();
65 std::string const & name() const;
66 boost::shared_ptr<DirectoryNode> parent() const;
69 std::string path() const;
75 explicit GenericNode(std::string const & name);
77 void name(std::string const & name);
78 static void name(GenericNode & node, std::string const & name);
79 void parent(DirectoryNode * parent);
83 DirectoryNode * parent_;
85 friend class intrusive_refcount_base;
86 friend class DirectoryNode;
91 class DirectoryNode : public GenericNode
93 typedef std::map<std::string, GenericNode::ptr> ChildMap;
96 ///////////////////////////////////////////////////////////////////////////
99 typedef boost::shared_ptr<DirectoryNode> ptr;
100 typedef boost::shared_ptr<DirectoryNode const> cptr;
101 typedef boost::weak_ptr<DirectoryNode> weak_ptr;
103 typedef boost::iterator_range<ChildMap::const_iterator> ChildrenRange;
104 typedef ChildMap::const_iterator child_iterator;
106 ///////////////////////////////////////////////////////////////////////////
108 GenericNode & add(std::auto_ptr<GenericNode> node, bool uniquify = true);
110 DirectoryNode & operator[](std::string const & name) const;
111 CommandNode & operator()(std::string const & name) const;
112 GenericNode & get(std::string const & name) const;
114 DirectoryNode & mkdir(std::string const & name);
116 ChildrenRange children() const;
118 template <class ForwardRange>
119 GenericNode & traverse(ForwardRange const & range);
122 cptr thisptr() const;
125 explicit DirectoryNode(std::string const & name);
128 void add(GenericNode::ptr node, bool uniquify);
132 friend DirectoryNode & root();
135 struct DuplicateNodeNameException : public senf::Exception
136 { DuplicateNodeNameException() : senf::Exception("Duplicate node name") {}};
138 struct UnknownNodeNameException : public senf::Exception
139 { UnknownNodeNameException() : senf::Exception("Unknown node name") {}};
143 class CommandNode : public GenericNode
146 ///////////////////////////////////////////////////////////////////////////
149 typedef boost::shared_ptr<CommandNode> ptr;
150 typedef boost::shared_ptr<CommandNode const> cptr;
151 typedef boost::weak_ptr<CommandNode> weak_ptr;
153 ///////////////////////////////////////////////////////////////////////////
155 virtual void operator()(std::ostream & output,
156 ParseCommandInfo::ArgumentsRange const & arguments) = 0;
159 cptr thisptr() const;
162 explicit CommandNode(std::string const & name);
168 DirectoryNode & root();
172 ///////////////////////////////hh.e////////////////////////////////////////
175 //#include "Node.cti"
182 // comment-column: 40
183 // c-file-style: "senf"
184 // indent-tabs-mode: nil
185 // ispell-local-dictionary: "american"
186 // compile-command: "scons -u test"