PLearn 0.1
RemoteDeclareMethod.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // RemoteDeclareMethod.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 RemoteDeclareMethod_INC
00041 #define RemoteDeclareMethod_INC
00042 
00043 // From PLearn
00044 #include "RemoteMethodMap.h"
00045 #include "RemoteMethodDoc.h"
00046 #include "RemoteTrampoline.h"
00047 #include <plearn/base/StaticInitializer.h>
00048 
00049 // From C++ stdlib
00050 #include <string>
00051 
00052 namespace PLearn {
00053 
00054 // What follows is a utility cast to bring const methods into non-const
00055 #define METHOD_UNCONST(M) (typename Trampoline::MethodType)(M)
00056 
00059 RemoteMethodMap& getGlobalFunctionMap();
00060 
00061 
00062 #define BEGIN_DECLARE_REMOTE_FUNCTIONS static void declareRemoteFunctions() {
00063 #define END_DECLARE_REMOTE_FUNCTIONS } static StaticInitializer _remote_function_initializer_(&declareRemoteFunctions);
00064 
00065 // What follows is a bunch of 'declareFunction' overloads, each instantiating the
00066 // appropriate FRemoteTrampoline
00067 
00068 //#####  0 Argument  ##########################################################
00069 
00070 template <class R>
00071 inline void declareFunction(const string& funcname,
00072                             R (*func)(),
00073                             const RemoteMethodDoc& doc,
00074                             const RemoteTrampoline::flag_t& flgs= 0)
00075 {
00076     RemoteMethodMap& rmm = getGlobalFunctionMap();
00077     typedef FRemoteTrampoline_0<R> Trampoline;
00078     rmm.insert(funcname, Trampoline::expected_nargs,
00079                new Trampoline(funcname, doc, func, flgs));
00080 }
00081 
00082 
00083 //#####  1 Argument  ##########################################################
00084 
00085 template <class R, class A1>
00086 inline void declareFunction(const string& funcname,
00087                             R (*func)(A1),
00088                             const RemoteMethodDoc& doc,
00089                             const RemoteTrampoline::flag_t& flgs= 0)
00090 {
00091     RemoteMethodMap& rmm = getGlobalFunctionMap();
00092     typedef FRemoteTrampoline_1<R,A1> Trampoline;
00093     rmm.insert(funcname, Trampoline::expected_nargs,
00094                new Trampoline(funcname, doc, func, flgs));
00095 }
00096 
00097 
00098 //#####  2 Arguments  #########################################################
00099 
00100 template <class R, class A1, class A2>
00101 inline void declareFunction(const string& funcname,
00102                             R (*func)(A1,A2),
00103                             const RemoteMethodDoc& doc,
00104                             const RemoteTrampoline::flag_t& flgs= 0)
00105 {
00106     RemoteMethodMap& rmm = getGlobalFunctionMap();
00107     typedef FRemoteTrampoline_2<R,A1,A2> Trampoline;
00108     rmm.insert(funcname, Trampoline::expected_nargs,
00109                new Trampoline(funcname, doc, func, flgs));
00110 }
00111 
00112 
00113 //#####  3 Arguments  #########################################################
00114 
00115 template <class R, class A1, class A2, class A3>
00116 inline void declareFunction(const string& funcname,
00117                             R (*func)(A1,A2,A3),
00118                             const RemoteMethodDoc& doc,
00119                             const RemoteTrampoline::flag_t& flgs= 0)
00120 {
00121     RemoteMethodMap& rmm = getGlobalFunctionMap();
00122     typedef FRemoteTrampoline_3<R,A1,A2,A3> Trampoline;
00123     rmm.insert(funcname, Trampoline::expected_nargs,
00124                new Trampoline(funcname, doc, func, flgs));
00125 }
00126 
00127 
00128 //#####  4 Arguments  #########################################################
00129 
00130 template <class R, class A1, class A2, class A3, class A4>
00131 inline void declareFunction(const string& funcname,
00132                             R (*func)(A1,A2,A3,A4),
00133                             const RemoteMethodDoc& doc,
00134                             const RemoteTrampoline::flag_t& flgs= 0)
00135 {
00136     RemoteMethodMap& rmm = getGlobalFunctionMap();
00137     typedef FRemoteTrampoline_4<R,A1,A2,A3,A4> Trampoline;
00138     rmm.insert(funcname, Trampoline::expected_nargs,
00139                new Trampoline(funcname, doc, func, flgs));
00140 }
00141 
00142 //#####  5 Arguments  #########################################################
00143 
00144 template <class R, class A1, class A2, class A3, class A4, class A5>
00145 inline void declareFunction(const string& funcname,
00146                             R (*func)(A1,A2,A3,A4,A5),
00147                             const RemoteMethodDoc& doc,
00148                             const RemoteTrampoline::flag_t& flgs= 0)
00149 {
00150     RemoteMethodMap& rmm = getGlobalFunctionMap();
00151     typedef FRemoteTrampoline_5<R,A1,A2,A3,A4,A5> Trampoline;
00152     rmm.insert(funcname, Trampoline::expected_nargs,
00153                new Trampoline(funcname, doc, func, flgs));
00154 }
00155 
00156 //#####  6 Arguments  #########################################################
00157 
00158 template <class R, class A1, class A2, class A3, class A4, class A5, class A6>
00159 inline void declareFunction(const string& funcname,
00160                             R (*func)(A1,A2,A3,A4,A5,A6),
00161                             const RemoteMethodDoc& doc,
00162                             const RemoteTrampoline::flag_t& flgs= 0)
00163 {
00164     RemoteMethodMap& rmm = getGlobalFunctionMap();
00165     typedef FRemoteTrampoline_6<R,A1,A2,A3,A4,A5,A6> Trampoline;
00166     rmm.insert(funcname, Trampoline::expected_nargs,
00167                new Trampoline(funcname, doc, func, flgs));
00168 }
00169 
00170 
00171 // What follows is a bunch of 'declareMethod' overloads, each instantiating the
00172 // appropriate RemoteTrampoline
00173 
00174 //#####  0 Argument  ##########################################################
00175 
00176 // Non-const method
00177 template <class T, class R>
00178 inline void declareMethod(RemoteMethodMap& rmm,
00179                           const string& methodname,
00180                           R (T::*method)(),
00181                           const RemoteMethodDoc& doc,
00182                           const RemoteTrampoline::flag_t& flgs= 0)
00183 {
00184     typedef RemoteTrampoline_0<T,R> Trampoline;
00185     rmm.insert(methodname, Trampoline::expected_nargs,
00186                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00187 }
00188 
00189 // Const method
00190 template <class T, class R>
00191 inline void declareMethod(RemoteMethodMap& rmm,
00192                           const string& methodname,
00193                           R (T::*method)() const,
00194                           const RemoteMethodDoc& doc,
00195                           const RemoteTrampoline::flag_t& flgs= 0)
00196 {
00197     typedef RemoteTrampoline_0<T,R> Trampoline;
00198     rmm.insert(methodname, Trampoline::expected_nargs,
00199                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00200 }
00201 
00202 
00203 //#####  1 Argument  ##########################################################
00204 
00205 // Non-const method
00206 template <class T, class R, class A1>
00207 inline void declareMethod(RemoteMethodMap& rmm,
00208                           const string& methodname,
00209                           R (T::*method)(A1),
00210                           const RemoteMethodDoc& doc,
00211                           const RemoteTrampoline::flag_t& flgs= 0)
00212 {
00213     typedef RemoteTrampoline_1<T,R,A1> Trampoline;
00214     rmm.insert(methodname, Trampoline::expected_nargs,
00215                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00216 }
00217 
00218 // Const method
00219 template <class T, class R, class A1>
00220 inline void declareMethod(RemoteMethodMap& rmm,
00221                           const string& methodname,
00222                           R (T::*method)(A1) const,
00223                           const RemoteMethodDoc& doc,
00224                           const RemoteTrampoline::flag_t& flgs= 0)
00225 {
00226     typedef RemoteTrampoline_1<T,R,A1> Trampoline;
00227     rmm.insert(methodname, Trampoline::expected_nargs,
00228                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00229 }
00230 
00231 
00232 //#####  2 Arguments  #########################################################
00233 
00234 // Non-const method
00235 template <class T, class R, class A1, class A2>
00236 inline void declareMethod(RemoteMethodMap& rmm,
00237                           const string& methodname,
00238                           R (T::*method)(A1,A2),
00239                           const RemoteMethodDoc& doc,
00240                           const RemoteTrampoline::flag_t& flgs= 0)
00241 {
00242     typedef RemoteTrampoline_2<T,R,A1,A2> Trampoline;
00243     rmm.insert(methodname, Trampoline::expected_nargs,
00244                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00245 }
00246 
00247 // Const method
00248 template <class T, class R, class A1, class A2>
00249 inline void declareMethod(RemoteMethodMap& rmm,
00250                           const string& methodname,
00251                           R (T::*method)(A1,A2) const,
00252                           const RemoteMethodDoc& doc,
00253                           const RemoteTrampoline::flag_t& flgs= 0)
00254 {
00255     typedef RemoteTrampoline_2<T,R,A1,A2> Trampoline;
00256     rmm.insert(methodname, Trampoline::expected_nargs,
00257                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00258 }
00259 
00260 
00261 //#####  3 Arguments  #########################################################
00262 
00263 // Non-const method
00264 template <class T, class R, class A1, class A2, class A3>
00265 inline void declareMethod(RemoteMethodMap& rmm,
00266                           const string& methodname,
00267                           R (T::*method)(A1,A2,A3),
00268                           const RemoteMethodDoc& doc,
00269                           const RemoteTrampoline::flag_t& flgs= 0)
00270 {
00271     typedef RemoteTrampoline_3<T,R,A1,A2,A3> Trampoline;
00272     rmm.insert(methodname, Trampoline::expected_nargs,
00273                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00274 }
00275 
00276 // Const method
00277 template <class T, class R, class A1, class A2, class A3>
00278 inline void declareMethod(RemoteMethodMap& rmm,
00279                           const string& methodname,
00280                           R (T::*method)(A1,A2,A3) const,
00281                           const RemoteMethodDoc& doc,
00282                           const RemoteTrampoline::flag_t& flgs= 0)
00283 {
00284     typedef RemoteTrampoline_3<T,R,A1,A2,A3> Trampoline;
00285     rmm.insert(methodname, Trampoline::expected_nargs,
00286                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00287 }
00288 
00289 
00290 //#####  4 Arguments  #########################################################
00291 
00292 // Non-const method
00293 template <class T, class R, class A1, class A2, class A3, class A4>
00294 inline void declareMethod(RemoteMethodMap& rmm,
00295                           const string& methodname,
00296                           R (T::*method)(A1,A2,A3,A4),
00297                           const RemoteMethodDoc& doc,
00298                           const RemoteTrampoline::flag_t& flgs= 0)
00299 {
00300     typedef RemoteTrampoline_4<T,R,A1,A2,A3,A4> Trampoline;
00301     rmm.insert(methodname, Trampoline::expected_nargs,
00302                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00303 }
00304 
00305 // Const method
00306 template <class T, class R, class A1, class A2, class A3, class A4>
00307 inline void declareMethod(RemoteMethodMap& rmm,
00308                           const string& methodname,
00309                           R (T::*method)(A1,A2,A3,A4) const,
00310                           const RemoteMethodDoc& doc,
00311                           const RemoteTrampoline::flag_t& flgs= 0)
00312 {
00313     typedef RemoteTrampoline_4<T,R,A1,A2,A3,A4> Trampoline;
00314     rmm.insert(methodname, Trampoline::expected_nargs,
00315                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00316 }
00317 
00318 
00319 //#####  5 Arguments  #########################################################
00320 
00321 // Non-const method
00322 template <class T, class R, class A1, class A2, class A3, class A4, class A5>
00323 inline void declareMethod(RemoteMethodMap& rmm,
00324                           const string& methodname,
00325                           R (T::*method)(A1,A2,A3,A4,A5),
00326                           const RemoteMethodDoc& doc,
00327                           const RemoteTrampoline::flag_t& flgs= 0)
00328 {
00329     typedef RemoteTrampoline_5<T,R,A1,A2,A3,A4,A5> Trampoline;
00330     rmm.insert(methodname, Trampoline::expected_nargs,
00331                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00332 }
00333 
00334 // Const method
00335 template <class T, class R, class A1, class A2, class A3, class A4, class A5>
00336 inline void declareMethod(RemoteMethodMap& rmm,
00337                           const string& methodname,
00338                           R (T::*method)(A1,A2,A3,A4,A5) const,
00339                           const RemoteMethodDoc& doc,
00340                           const RemoteTrampoline::flag_t& flgs= 0)
00341 {
00342     typedef RemoteTrampoline_5<T,R,A1,A2,A3,A4,A5> Trampoline;
00343     rmm.insert(methodname, Trampoline::expected_nargs,
00344                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00345 }
00346 
00347 
00348 //#####  6 Arguments  #########################################################
00349 
00350 // Non-const method
00351 template <class T, class R, class A1, class A2, class A3, class A4, class A5, class A6>
00352 inline void declareMethod(RemoteMethodMap& rmm,
00353                           const string& methodname,
00354                           R (T::*method)(A1,A2,A3,A4,A5,A6),
00355                           const RemoteMethodDoc& doc,
00356                           const RemoteTrampoline::flag_t& flgs= 0)
00357 {
00358     typedef RemoteTrampoline_6<T,R,A1,A2,A3,A4,A5,A6> Trampoline;
00359     rmm.insert(methodname, Trampoline::expected_nargs,
00360                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00361 }
00362 
00363 // Const method
00364 template <class T, class R, class A1, class A2, class A3, class A4, class A5, class A6>
00365 inline void declareMethod(RemoteMethodMap& rmm,
00366                           const string& methodname,
00367                           R (T::*method)(A1,A2,A3,A4,A5,A6) const,
00368                           const RemoteMethodDoc& doc,
00369                           const RemoteTrampoline::flag_t& flgs= 0)
00370 {
00371     typedef RemoteTrampoline_6<T,R,A1,A2,A3,A4,A5,A6> Trampoline;
00372     rmm.insert(methodname, Trampoline::expected_nargs,
00373                new Trampoline(methodname, doc, METHOD_UNCONST(method), flgs));
00374 }
00375 
00376 
00377 
00378 } // end of namespace PLearn
00379 
00380 #endif
00381 
00382 
00383 /*
00384   Local Variables:
00385   mode:c++
00386   c-basic-offset:4
00387   c-file-style:"stroustrup"
00388   c-file-offsets:((innamespace . 0)(inline-open . 0))
00389   indent-tabs-mode:nil
00390   fill-column:79
00391   End:
00392 */
00393 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines