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 OverloadedCommand non-inline non-template implementation */
26 #include "OverloadedCommand.hh"
27 //#include "OverloadedCommand.ih"
31 //#include "OverloadedCommand.mpp"
33 ///////////////////////////////cc.p////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::console::OverloadedCommandNode
38 ///////////////////////////////////////////////////////////////////////////
39 // So soll die doku aussehen:
42 // 1- foo arg1:int arg2:double
52 // Generic documentation foo blalsdljfl laj flkajslkjs fdlkj oiwlksdj ;llkaj
53 // sdflkja sldkfjslkdfj sdlkfj lskjdf lskjdf lksj dflkj lsdkfj lskdjf lskjkd
54 // Generic documentation foo blalsdljfl laj flkajslkjs fdlkj oiwlksdj ;llkaj
55 // sdflkja sldkfjslkdfj sdlkfj lskjdf lskjdf lksj dflkj lsdkfj lskdjf lskjkd
56 // Generic documentation foo blalsdljfl laj flkajslkjs fdlkj oiwlksdj ;llkaj
57 // sdflkja sldkfjslkdfj sdlkfj lskjdf lskjdf lksj dflkj lsdkfj lskdjf lskjkd
60 // Variant 1 doc la;ksjf lkj sdlkfj lkjekj sdflkj ekljsdlkfj wlej
61 // slkj dkj sldkfj lwekljsdf skldjf lskjdf l jsd
64 // Variant 2 doc lskdfj lwkej lksjdflksjf
67 // Variant 3 doc slkjflw ekj lskdfj lskdjf laksdj flksj elkj aldskjf lwkejlksdj
68 // ldkfaj wlekj slkdfj lskdjf lwkejlkasdjf
70 prefix_ void senf::console::OverloadedCommandNode::v_help(std::ostream & os)
73 typedef std::vector<ArgumentDoc> ArgumentDocs;
74 ArgumentDocs argumentDocs;
75 bool haveDocumentedArg (false);
79 Overloads::const_iterator i (overloads_.begin());
80 Overloads::const_iterator const i_end (overloads_.end());
82 for (; i != i_end; ++i, ++index) {
84 if (overloads_.size() > 1) os << index << "- ";
86 for (unsigned j (0); j < (*i)->numArguments(); ++j) {
88 (*i)->argumentDoc(j, arg);
91 if (! arg.defaultValue.empty())
93 if (! arg.name.empty()) os << arg.name;
94 if (! arg.type.empty()) os << ':' << arg.type;
95 if (arg.name.empty() && arg.type.empty()) os << "...";
96 if (! arg.defaultValue.empty())
99 if (! arg.name.empty()) {
100 ArgumentDocs::iterator k (argumentDocs.begin());
101 ArgumentDocs::iterator const k_end (argumentDocs.end());
102 for (; k != k_end; ++k)
103 if (k->name == arg.name && k->defaultValue == arg.defaultValue) {
104 if (! arg.doc.empty() && k->doc.empty()) {
106 haveDocumentedArg = true;
111 argumentDocs.push_back(arg);
112 if (! arg.doc.empty())
113 haveDocumentedArg = true;
121 if (haveDocumentedArg) {
122 os << "\n" "With:\n";
123 ArgumentDocs::const_iterator i (argumentDocs.begin());
124 ArgumentDocs::const_iterator const i_end (argumentDocs.end());
125 for (; i != i_end; ++i) {
126 if (! i->doc.empty()) {
129 << std::string(i->name.length()<8 ? 8-i->name.length() : 0, ' ')
133 if (! i->defaultValue.empty())
134 os << " default: " << i->defaultValue << '\n';
140 os << "\n" << doc_ << "\n";
143 Overloads::const_iterator i (overloads_.begin());
144 Overloads::const_iterator const i_end (overloads_.end());
146 for (; i != i_end; ++i, ++index) {
147 std::string overloadDoc ((*i)->doc());
148 if (! overloadDoc.empty()) {
150 if (overloads_.size() > 1)
151 os << "Variant " << index << ":\n";
152 os << overloadDoc << "\n";
158 prefix_ void senf::console::OverloadedCommandNode::v_execute(std::ostream & output,
159 ParseCommandInfo const & command)
162 Overloads::const_iterator i (overloads_.begin());
163 Overloads::const_iterator const i_end (overloads_.end());
164 SyntaxErrorException err;
165 for (; i != i_end; ++i) {
167 (**i)(output, command);
170 catch (SyntaxErrorException & ex) {
177 ///////////////////////////////////////////////////////////////////////////
178 // senf::console::SimpleCommandOverload
180 prefix_ unsigned senf::console::SimpleCommandOverload::v_numArguments()
186 prefix_ void senf::console::SimpleCommandOverload::v_argumentDoc(unsigned index, ArgumentDoc & doc)
190 prefix_ std::string senf::console::SimpleCommandOverload::v_doc()
196 prefix_ void senf::console::SimpleCommandOverload::v_execute(std::ostream & os,
197 ParseCommandInfo const & command)
203 ///////////////////////////////cc.e////////////////////////////////////////
205 //#include "OverloadedCommand.mpp"
211 // comment-column: 40
212 // c-file-style: "senf"
213 // indent-tabs-mode: nil
214 // ispell-local-dictionary: "american"
215 // compile-command: "scons -u test"