[1151] | 1 | // |
---|
| 2 | // Copyright (C) 2004-2006, Maciej Sobczak |
---|
| 3 | // |
---|
| 4 | // Permission to copy, use, modify, sell and distribute this software |
---|
| 5 | // is granted provided this copyright notice appears in all copies. |
---|
| 6 | // This software is provided "as is" without express or implied |
---|
| 7 | // warranty, and with no claim as to its suitability for any purpose. |
---|
| 8 | // |
---|
| 9 | |
---|
| 10 | // Note: this file is not supposed to be a stand-alone header |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | // the dispatch class is used to execute the callback functor and to |
---|
| 14 | // capture its return value |
---|
| 15 | // further dispatch<void> specialization ignores the res |
---|
| 16 | |
---|
| 17 | template <typename R> |
---|
| 18 | struct dispatch |
---|
| 19 | { |
---|
| 20 | template <class Functor> |
---|
| 21 | static void do_dispatch(Tcl_Interp *interp, Functor f) |
---|
| 22 | { |
---|
| 23 | R res = f(); |
---|
| 24 | set_result(interp, res); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | template <typename T1, class Functor> |
---|
| 28 | static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1) |
---|
| 29 | { |
---|
| 30 | R res = f(t1); |
---|
| 31 | set_result(interp, res); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | template <typename T1, typename T2, class Functor> |
---|
| 35 | static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2) |
---|
| 36 | { |
---|
| 37 | R res = f(t1, t2); |
---|
| 38 | set_result(interp, res); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | template <typename T1, typename T2, typename T3, class Functor> |
---|
| 42 | static void do_dispatch(Tcl_Interp *interp, Functor f, |
---|
| 43 | T1 t1, T2 t2, T3 t3) |
---|
| 44 | { |
---|
| 45 | R res = f(t1, t2, t3); |
---|
| 46 | set_result(interp, res); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 50 | class Functor> |
---|
| 51 | static void do_dispatch(Tcl_Interp *interp, Functor f, |
---|
| 52 | T1 t1, T2 t2, T3 t3, T4 t4) |
---|
| 53 | { |
---|
| 54 | R res = f(t1, t2, t3, t4); |
---|
| 55 | set_result(interp, res); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 59 | typename T5, class Functor> |
---|
| 60 | static void do_dispatch(Tcl_Interp *interp, Functor f, |
---|
| 61 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) |
---|
| 62 | { |
---|
| 63 | R res = f(t1, t2, t3, t4, t5); |
---|
| 64 | set_result(interp, res); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 68 | typename T5, typename T6, class Functor> |
---|
| 69 | static void do_dispatch(Tcl_Interp *interp, Functor f, |
---|
| 70 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) |
---|
| 71 | { |
---|
| 72 | R res = f(t1, t2, t3, t4, t5, t6); |
---|
| 73 | set_result(interp, res); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 77 | typename T5, typename T6, typename T7, class Functor> |
---|
| 78 | static void do_dispatch(Tcl_Interp *interp, Functor f, |
---|
| 79 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) |
---|
| 80 | { |
---|
| 81 | R res = f(t1, t2, t3, t4, t5, t6, t7); |
---|
| 82 | set_result(interp, res); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 86 | typename T5, typename T6, typename T7, typename T8, class Functor> |
---|
| 87 | static void do_dispatch(Tcl_Interp *interp, Functor f, |
---|
| 88 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) |
---|
| 89 | { |
---|
| 90 | R res = f(t1, t2, t3, t4, t5, t6, t7, t8); |
---|
| 91 | set_result(interp, res); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 95 | typename T5, typename T6, typename T7, typename T8, typename T9, |
---|
| 96 | class Functor> |
---|
| 97 | static void do_dispatch(Tcl_Interp *interp, Functor f, |
---|
| 98 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) |
---|
| 99 | { |
---|
| 100 | R res = f(t1, t2, t3, t4, t5, t6, t7, t8, t9); |
---|
| 101 | set_result(interp, res); |
---|
| 102 | } |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | template <> |
---|
| 106 | struct dispatch<void> |
---|
| 107 | { |
---|
| 108 | template <class Functor> |
---|
| 109 | static void do_dispatch(Tcl_Interp *, Functor f) |
---|
| 110 | { |
---|
| 111 | f(); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | template <typename T1, class Functor> |
---|
| 115 | static void do_dispatch(Tcl_Interp *, Functor f, T1 t1) |
---|
| 116 | { |
---|
| 117 | f(t1); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | template <typename T1, typename T2, class Functor> |
---|
| 121 | static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2) |
---|
| 122 | { |
---|
| 123 | f(t1, t2); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | template <typename T1, typename T2, typename T3, class Functor> |
---|
| 127 | static void do_dispatch(Tcl_Interp *, Functor f, |
---|
| 128 | T1 t1, T2 t2, T3 t3) |
---|
| 129 | { |
---|
| 130 | f(t1, t2, t3); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 134 | class Functor> |
---|
| 135 | static void do_dispatch(Tcl_Interp *, Functor f, |
---|
| 136 | T1 t1, T2 t2, T3 t3, T4 t4) |
---|
| 137 | { |
---|
| 138 | f(t1, t2, t3, t4); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 142 | typename T5, class Functor> |
---|
| 143 | static void do_dispatch(Tcl_Interp *, Functor f, |
---|
| 144 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) |
---|
| 145 | { |
---|
| 146 | f(t1, t2, t3, t4, t5); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 150 | typename T5, typename T6, class Functor> |
---|
| 151 | static void do_dispatch(Tcl_Interp *, Functor f, |
---|
| 152 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) |
---|
| 153 | { |
---|
| 154 | f(t1, t2, t3, t4, t5, t6); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 158 | typename T5, typename T6, typename T7, class Functor> |
---|
| 159 | static void do_dispatch(Tcl_Interp *, Functor f, |
---|
| 160 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) |
---|
| 161 | { |
---|
| 162 | f(t1, t2, t3, t4, t5, t6, t7); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 166 | typename T5, typename T6, typename T7, typename T8, class Functor> |
---|
| 167 | static void do_dispatch(Tcl_Interp *, Functor f, |
---|
| 168 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) |
---|
| 169 | { |
---|
| 170 | f(t1, t2, t3, t4, t5, t6, t7, t8); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | template <typename T1, typename T2, typename T3, typename T4, |
---|
| 174 | typename T5, typename T6, typename T7, typename T8, typename T9, |
---|
| 175 | class Functor> |
---|
| 176 | static void do_dispatch(Tcl_Interp *, Functor f, |
---|
| 177 | T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) |
---|
| 178 | { |
---|
| 179 | f(t1, t2, t3, t4, t5, t6, t7, t8, t9); |
---|
| 180 | } |
---|
| 181 | }; |
---|