Console: Implement ObjectDirectory proxy
[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()
47     : parent_ (0)
48 {}
49
50 prefix_ void senf::console::GenericNode::name(std::string const & name)
51 {
52     name_ = name;
53 }
54
55 prefix_ void senf::console::GenericNode::name(GenericNode & node, std::string const & name)
56 {
57     node.name_ = name;
58 }
59
60 prefix_ boost::shared_ptr<senf::console::DirectoryNode> senf::console::GenericNode::parent()
61     const
62 {
63     return boost::static_pointer_cast<DirectoryNode>(
64         parent_ ? parent_->shared_from_this() : ptr() );
65 }
66
67 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::unlink()
68 {
69     SENF_ASSERT( parent() );
70     return parent()->remove(name());
71 }
72
73 prefix_ void senf::console::GenericNode::help(std::ostream & output)
74     const
75 {
76     v_help(output);
77 }
78
79 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::thisptr()
80 {
81     return shared_from_this();
82 }
83
84 prefix_ senf::console::GenericNode::cptr senf::console::GenericNode::thisptr()
85     const
86 {
87     return shared_from_this();
88 }
89
90 ///////////////////////////////////////////////////////////////////////////
91 // senf::console::DirectoryNode
92
93 prefix_ std::auto_ptr<senf::console::DirectoryNode>
94 senf::console::DirectoryNode::create()
95 {
96     return std::auto_ptr<DirectoryNode>(new DirectoryNode());
97 }
98
99 prefix_ senf::console::DirectoryNode &
100 senf::console::DirectoryNode::operator[](std::string const & name)
101     const
102 {
103     return dynamic_cast<DirectoryNode&>(get(name));
104 }
105
106 prefix_ senf::console::CommandNode &
107 senf::console::DirectoryNode::operator()(std::string const & name)
108     const
109 {
110     return dynamic_cast<CommandNode&>(get(name));
111 }
112
113 prefix_ senf::console::DirectoryNode &
114 senf::console::DirectoryNode::mkdir(std::string const & name)
115 {
116     std::auto_ptr<DirectoryNode> node (create());
117     return add(name, node);
118 }
119
120 prefix_ senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::children()
121     const
122 {
123     return boost::make_iterator_range(children_.begin(), children_.end());
124 }
125
126 prefix_ senf::console::DirectoryNode::DirectoryNode()
127 {}
128
129 prefix_ senf::console::DirectoryNode &
130 senf::console::DirectoryNode::doc(std::string const & doc)
131 {
132     doc_ = doc;
133     return *this;
134 }
135
136 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::thisptr()
137 {
138     return boost::static_pointer_cast<DirectoryNode>(shared_from_this());
139 }
140
141 prefix_ senf::console::DirectoryNode::cptr senf::console::DirectoryNode::thisptr()
142     const
143 {
144     return boost::static_pointer_cast<DirectoryNode const>(shared_from_this());
145 }
146
147 ///////////////////////////////////////////////////////////////////////////
148 // senf::console::CommandNode
149
150 prefix_ senf::console::CommandNode::ptr senf::console::CommandNode::thisptr()
151 {
152     return boost::static_pointer_cast<CommandNode>(shared_from_this());
153 }
154
155 prefix_ senf::console::CommandNode::cptr senf::console::CommandNode::thisptr()
156     const
157 {
158     return boost::static_pointer_cast<CommandNode const>(shared_from_this());
159 }
160
161 prefix_ senf::console::CommandNode::CommandNode()
162 {}
163
164 ///////////////////////////////////////////////////////////////////////////
165 // senf::console::SimpleCommandNode
166
167 prefix_ void senf::console::SimpleCommandNode::operator()(std::ostream & output,
168                                                           Arguments const & arguments)
169 {
170     fn_(output, arguments);
171 }
172
173 prefix_ senf::console::SimpleCommandNode::SimpleCommandNode(Function const & fn)
174     : fn_ (fn)
175 {}
176
177 prefix_ std::auto_ptr<senf::console::SimpleCommandNode>
178 senf::console::SimpleCommandNode::create(Function const & fn)
179 {
180     return std::auto_ptr<SimpleCommandNode>(new SimpleCommandNode(fn));
181 }
182
183 prefix_ senf::console::SimpleCommandNode &
184 senf::console::SimpleCommandNode::doc(std::string const & doc)
185 {
186     doc_ = doc;
187     return *this;
188 }
189
190 ///////////////////////////////cci.e///////////////////////////////////////
191 #undef prefix_
192
193 \f
194 // Local Variables:
195 // mode: c++
196 // fill-column: 100
197 // comment-column: 40
198 // c-file-style: "senf"
199 // indent-tabs-mode: nil
200 // ispell-local-dictionary: "american"
201 // compile-command: "scons -u test"
202 // End: