HowTos/NewPacket: Remove old code from example
[senf.git] / Console / OverloadedCommand.cc
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 OverloadedCommand non-inline non-template implementation */
25
26 #include "OverloadedCommand.hh"
27 //#include "OverloadedCommand.ih"
28
29 // Custom includes
30
31 //#include "OverloadedCommand.mpp"
32 #define prefix_
33 ///////////////////////////////cc.p////////////////////////////////////////
34
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::console::OverloadedCommandNode
37
38 prefix_ void senf::console::OverloadedCommandNode::v_help(std::ostream & os)
39     const
40 {
41     os << doc_;
42     Overloads::const_iterator i (overloads_.begin());
43     Overloads::const_iterator const i_end (overloads_.end());
44     for (; i != i_end; ++i) {
45         os << "\n\n";
46         (*i)->help(os);
47     }
48 }
49
50 prefix_ void senf::console::OverloadedCommandNode::v_execute(std::ostream & output,
51                                                              Arguments const & arguments)
52     const
53 {
54     Overloads::const_iterator i (overloads_.begin());
55     Overloads::const_iterator const i_end (overloads_.end());
56     SyntaxErrorException err;
57     for (; i != i_end; ++i) {
58         try {
59             (**i)(output, arguments);
60             return;
61         }
62         catch (SyntaxErrorException & ex) {
63             err = ex;
64         };
65     }
66     throw err;
67 }
68
69 ///////////////////////////////////////////////////////////////////////////
70 // senf::console::SimpleCommandOverload
71
72 prefix_ void senf::console::SimpleCommandOverload::v_help(std::ostream & os)
73     const
74 {
75     os << doc_;
76 }
77
78 prefix_ void senf::console::SimpleCommandOverload::v_execute(std::ostream & os,
79                                                              Arguments const & arguments)
80     const
81 {
82     fn_(os, arguments);
83 }
84
85 ///////////////////////////////cc.e////////////////////////////////////////
86 #undef prefix_
87 //#include "OverloadedCommand.mpp"
88
89 \f
90 // Local Variables:
91 // mode: c++
92 // fill-column: 100
93 // comment-column: 40
94 // c-file-style: "senf"
95 // indent-tabs-mode: nil
96 // ispell-local-dictionary: "american"
97 // compile-command: "scons -u test"
98 // End: