Console: Factored out path traversal into generic traversal helper
[senf.git] / Console / Node.cci
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
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
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Node inline non-template implementation */
25
26 //#include "Node.ih"
27
28 // Custom includes
29 #include "../Utils/senfassert.hh"
30
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
33
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::console::GenericNode
36
37 prefix_ senf::console::GenericNode::~GenericNode()
38 {}
39
40 prefix_ std::string const & senf::console::GenericNode::name()
41     const
42 {
43     return name_;
44 }
45
46 prefix_ senf::console::GenericNode::GenericNode(std::string const & name)
47     : name_ (name), parent_ (0)
48 {
49     ///\fixme Provide a default name if 'name' is empty ?
50 }
51
52 prefix_ void senf::console::GenericNode::name(std::string const & name)
53 {
54     name_ = name;
55 }
56
57 prefix_ void senf::console::GenericNode::name(GenericNode & node, std::string const & name)
58 {
59     node.name_ = name;
60 }
61
62 prefix_ boost::shared_ptr<senf::console::DirectoryNode> senf::console::GenericNode::parent()
63     const
64 {
65     return boost::static_pointer_cast<DirectoryNode>(
66         parent_ ? parent_->shared_from_this() : ptr() );
67 }
68
69 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::thisptr()
70 {
71     return shared_from_this();
72 }
73
74 prefix_ senf::console::GenericNode::cptr senf::console::GenericNode::thisptr()
75     const
76 {
77     return shared_from_this();
78 }
79
80 ///////////////////////////////////////////////////////////////////////////
81 // senf::console::DirectoryNode
82
83 prefix_ senf::console::GenericNode &
84 senf::console::DirectoryNode::add(std::auto_ptr<GenericNode> node, bool uniquify)
85 {
86     GenericNode::ptr p (node.release());
87     add(p, uniquify);
88     return *p;
89 }
90
91 prefix_ senf::console::DirectoryNode &
92 senf::console::DirectoryNode::operator[](std::string const & name)
93     const
94 {
95     return dynamic_cast<DirectoryNode&>(get(name));
96 }
97
98 prefix_ senf::console::CommandNode &
99 senf::console::DirectoryNode::operator()(std::string const & name)
100     const
101 {
102     return dynamic_cast<CommandNode&>(get(name));
103 }
104
105 prefix_ senf::console::DirectoryNode &
106 senf::console::DirectoryNode::mkdir(std::string const & name)
107 {
108     return static_cast<DirectoryNode &>(
109         add(std::auto_ptr<GenericNode>(new DirectoryNode(name))));
110 }
111
112 prefix_ senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::children()
113     const
114 {
115     return boost::make_iterator_range(children_.begin(), children_.end());
116 }
117
118 prefix_ senf::console::DirectoryNode::DirectoryNode(std::string const & name)
119     : GenericNode(name)
120 {}
121
122 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::thisptr()
123 {
124     return boost::static_pointer_cast<DirectoryNode>(shared_from_this());
125 }
126
127 prefix_ senf::console::DirectoryNode::cptr senf::console::DirectoryNode::thisptr()
128     const
129 {
130     return boost::static_pointer_cast<DirectoryNode const>(shared_from_this());
131 }
132
133 ///////////////////////////////////////////////////////////////////////////
134 // senf::console::CommandNode
135
136 prefix_ senf::console::CommandNode::CommandNode(std::string const & name)
137     : GenericNode(name)
138 {}
139
140 prefix_ senf::console::CommandNode::ptr senf::console::CommandNode::thisptr()
141 {
142     return boost::static_pointer_cast<CommandNode>(shared_from_this());
143 }
144
145 prefix_ senf::console::CommandNode::cptr senf::console::CommandNode::thisptr()
146     const
147 {
148     return boost::static_pointer_cast<CommandNode const>(shared_from_this());
149 }
150
151 ///////////////////////////////cci.e///////////////////////////////////////
152 #undef prefix_
153
154 \f
155 // Local Variables:
156 // mode: c++
157 // fill-column: 100
158 // comment-column: 40
159 // c-file-style: "senf"
160 // indent-tabs-mode: nil
161 // ispell-local-dictionary: "american"
162 // compile-command: "scons -u test"
163 // End: