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) {
83 os << " " << index << "- " << name();
84 for (unsigned j (0); j < (*i)->numArguments(); ++j) {
86 (*i)->argumentDoc(j, arg);
89 if (! arg.defaultValue.empty())
91 if (! arg.name.empty()) os << arg.name;
92 if (! arg.type.empty()) os << ':' << arg.type;
93 if (arg.name.empty() && arg.type.empty()) os << "...";
94 if (! arg.defaultValue.empty())
97 if (! arg.name.empty()) {
98 ArgumentDocs::iterator k (argumentDocs.begin());
99 ArgumentDocs::iterator const k_end (argumentDocs.end());
100 for (; k != k_end; ++k)
101 if (k->name == arg.name && k->defaultValue == arg.defaultValue) {
102 if (! arg.doc.empty() && k->doc.empty()) {
104 haveDocumentedArg = true;
109 argumentDocs.push_back(arg);
110 if (! arg.doc.empty())
111 haveDocumentedArg = true;
119 if (haveDocumentedArg) {
120 os << "\n" "With:\n";
121 ArgumentDocs::const_iterator i (argumentDocs.begin());
122 ArgumentDocs::const_iterator const i_end (argumentDocs.end());
123 for (; i != i_end; ++i) {
124 if (! i->doc.empty()) {
127 << std::string(i->name.length()<8 ? 8-i->name.length() : 0, ' ')
131 if (! i->defaultValue.empty())
132 os << " default: " << i->defaultValue << '\n';
138 os << "\n" << doc_ << "\n";
141 Overloads::const_iterator i (overloads_.begin());
142 Overloads::const_iterator const i_end (overloads_.end());
144 for (; i != i_end; ++i, ++index) {
145 std::string overloadDoc ((*i)->doc());
146 if (! overloadDoc.empty())
147 os << "\n" << "Variant " << index << ":\n"
148 << overloadDoc << "\n";
153 prefix_ void senf::console::OverloadedCommandNode::v_execute(std::ostream & output,
154 ParseCommandInfo const & command)
157 Overloads::const_iterator i (overloads_.begin());
158 Overloads::const_iterator const i_end (overloads_.end());
159 SyntaxErrorException err;
160 for (; i != i_end; ++i) {
162 (**i)(output, command);
165 catch (SyntaxErrorException & ex) {
172 ///////////////////////////////////////////////////////////////////////////
173 // senf::console::SimpleCommandOverload
175 prefix_ unsigned senf::console::SimpleCommandOverload::v_numArguments()
181 prefix_ void senf::console::SimpleCommandOverload::v_argumentDoc(unsigned index, ArgumentDoc & doc)
185 prefix_ std::string senf::console::SimpleCommandOverload::v_doc()
191 prefix_ void senf::console::SimpleCommandOverload::v_execute(std::ostream & os,
192 ParseCommandInfo const & command)
198 ///////////////////////////////cc.e////////////////////////////////////////
200 //#include "OverloadedCommand.mpp"
206 // comment-column: 40
207 // c-file-style: "senf"
208 // indent-tabs-mode: nil
209 // ispell-local-dictionary: "american"
210 // compile-command: "scons -u test"