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