PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // RemoteMethodDoc.h 00004 // 00005 // Copyright (C) 2006 Nicolas Chapados, Pascal Vincent 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 // Authors: Nicolas Chapados 00036 00040 #ifndef RemoteMethodDoc_INC 00041 #define RemoteMethodDoc_INC 00042 00043 // From C++ stdlib 00044 #include <string> 00045 #include <list> 00046 #include <utility> // For pair 00047 #include <vector> 00048 #include "plearn/base/tuple.h" 00049 00050 namespace PLearn { 00051 00052 using std::string; 00053 using std::pair; 00054 using std::list; 00055 00059 struct BodyDoc 00060 { 00061 BodyDoc(const char* s) 00062 : m_doc(s) 00063 { } 00064 00065 string m_doc; 00066 }; 00067 00071 struct ArgDoc 00072 { 00073 ArgDoc(const string& argument_name, const string& doc) 00074 : m_argument_name(argument_name), 00075 m_doc(doc) 00076 { } 00077 00078 string m_argument_name; 00079 string m_doc; 00080 }; 00081 00085 struct RetDoc 00086 { 00087 RetDoc(const char* s) 00088 : m_doc(s) 00089 { } 00090 00091 string m_doc; 00092 }; 00093 00098 struct ArgTypeDoc 00099 { 00100 ArgTypeDoc(const string& typestr) 00101 : m_typestr(typestr) 00102 { } 00103 00104 string m_typestr; 00105 }; 00106 00110 struct RetTypeDoc 00111 { 00112 RetTypeDoc(const string& typestr) 00113 : m_typestr(typestr) 00114 { } 00115 00116 string m_typestr; 00117 }; 00118 00119 00132 class RemoteMethodDoc 00133 { 00134 public: 00136 RemoteMethodDoc() 00137 { } 00138 00139 RemoteMethodDoc(const BodyDoc& doc) 00140 : m_body_doc(doc.m_doc) 00141 { } 00142 00143 RemoteMethodDoc(const RetDoc& doc) 00144 : m_return_doc(doc.m_doc) 00145 { } 00146 00147 RemoteMethodDoc(const ArgDoc& doc) 00148 : m_args_doc(1, doc) 00149 { } 00150 00151 void setName(const string& methodname) const 00152 { m_name = methodname; } 00153 00155 00156 const string& name() const 00157 { 00158 return m_name; 00159 } 00160 00164 void checkConsistency() const; 00165 00166 int nArgs() const 00167 { 00168 checkConsistency(); 00169 return m_args_type.size(); 00170 } 00171 00172 const string& bodyDoc() const 00173 { 00174 return m_body_doc; 00175 } 00176 00177 const string& returnDoc() const 00178 { 00179 return m_return_doc; 00180 } 00181 00182 const string& returnType() const 00183 { 00184 return m_return_type; 00185 } 00186 00187 const list<ArgDoc>& argListDoc() const 00188 { 00189 return m_args_doc; 00190 } 00191 00192 const list<string>& argListType() const 00193 { 00194 return m_args_type; 00195 } 00196 00198 const RemoteMethodDoc& operator,(const BodyDoc& doc) const 00199 { 00200 m_body_doc += doc.m_doc; 00201 return *this; 00202 } 00203 00205 const RemoteMethodDoc& operator,(const RetDoc& doc) const 00206 { 00207 m_return_doc += doc.m_doc; 00208 return *this; 00209 } 00210 00212 const RemoteMethodDoc& operator,(const RetTypeDoc& doc) const 00213 { 00214 m_return_type = doc.m_typestr; 00215 return *this; 00216 } 00217 00219 const RemoteMethodDoc& operator,(const ArgDoc& doc) const 00220 { 00221 m_args_doc.push_back(doc); 00222 return *this; 00223 } 00224 00227 const RemoteMethodDoc& operator,(const ArgTypeDoc& doc) const 00228 { 00229 m_args_type.push_back(doc.m_typestr); 00230 return *this; 00231 } 00232 00235 string getPrototypeString(string argsep=", ") const; 00236 00238 string getFullHelpText() const; 00239 00240 00241 protected: 00242 mutable string m_name; 00243 mutable string m_body_doc; 00244 mutable string m_return_doc; 00245 mutable string m_return_type; 00246 mutable list<ArgDoc> m_args_doc; 00247 mutable list<string> m_args_type; 00248 }; 00249 00251 inline RemoteMethodDoc operator,(const BodyDoc& body, const ArgDoc& arg) 00252 { 00253 RemoteMethodDoc doc(body); 00254 return doc.operator,(arg); 00255 } 00256 00258 inline RemoteMethodDoc operator,(const BodyDoc& body, const RetDoc& ret) 00259 { 00260 RemoteMethodDoc doc(body); 00261 return doc.operator,(ret); 00262 } 00263 00265 inline RemoteMethodDoc operator,(const ArgDoc& arg, const BodyDoc& body) 00266 { 00267 RemoteMethodDoc doc(body); 00268 return doc.operator,(arg); 00269 } 00270 00272 inline RemoteMethodDoc operator,(const ArgDoc& arg, const RetDoc& ret) 00273 { 00274 RemoteMethodDoc doc(ret); 00275 return doc.operator,(arg); 00276 } 00277 00279 inline RemoteMethodDoc operator,(const RetDoc& ret, const BodyDoc& body) 00280 { 00281 RemoteMethodDoc doc(body); 00282 return doc.operator,(ret); 00283 } 00284 00286 inline RemoteMethodDoc operator,(const RetDoc& ret, const ArgDoc& arg) 00287 { 00288 RemoteMethodDoc doc(arg); 00289 return doc.operator,(ret); 00290 } 00291 00292 } // end of namespace PLearn 00293 00294 #endif 00295 00296 00297 /* 00298 Local Variables: 00299 mode:c++ 00300 c-basic-offset:4 00301 c-file-style:"stroustrup" 00302 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00303 indent-tabs-mode:nil 00304 fill-column:79 00305 End: 00306 */ 00307 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :