00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef INSTIGATE_SCRIPTING_GENERIC_BASE
00024 #define INSTIGATE_SCRIPTING_GENERIC_BASE
00025
00033
00034
00035
00036
00037
00038
00039
00040
00046 namespace instigate {
00047 namespace scripting {
00048 namespace generic {
00049 template <int> class require;
00050 template <> class require<1>;
00051 template <typename T, typename U> class conversion;
00052 template <typename T> class conversion<T, T>;
00053 template <typename T> struct type_to_type;
00054 template <int t> struct int_to_type;
00055 }
00056 }
00057 }
00058
00065 #define CHECK(R) {R();}
00066
00072 #define CHECK_CONVERTIBILITY(T, U) {\
00073 instigate::scripting::generic::require<instigate::scripting::\
00074 generic::conversion<T, U>::exists>();}
00075
00079 #define CHECK_SAME_TYPE(T, U) {\
00080 instigate::scripting::generic::require<instigate::scripting::\
00081 generic::conversion<T, U>::same_type>();}
00082
00089 template <>
00090 class instigate::scripting::generic::require<1>
00091 {};
00092
00110 template <typename T, typename U>
00111 class instigate::scripting::generic::conversion
00112 {
00113 private:
00114 typedef char small;
00115 class big { char a[2]; };
00116 static T makeT();
00117 static small test(U);
00118 static big test(...);
00119 public:
00120 static const bool exists = (sizeof(small) == sizeof(test(makeT())));
00121 static const bool same_type = false;
00122 static const bool super_sub_class =
00123 conversion<const U*, const T*>::exists &&
00124 !conversion<const T*, const void*>::same_type;
00125 };
00126
00127 template <typename T>
00128 class instigate::scripting::generic::conversion<T, T>
00129 {
00130 public:
00131 static const bool exists = true;
00132 static const bool same_type = true;
00133 static const bool super_sub_class = false;
00134 };
00135
00164 template <int t>
00165 struct instigate::scripting::generic::int_to_type
00166 {
00167 enum { value = t };
00168 };
00169
00198 template <typename T>
00199 struct instigate::scripting::generic::type_to_type
00200 {
00201 typedef T original_type;
00202 };
00203
00204 template <typename U, typename F>
00205 static void require_same_type(U v1, F v2)
00206 {
00207 CHECK_SAME_TYPE(U, F);
00208 }
00209
00210 #define REQUIRE_SAME_TYPE(v1, v2){require_same_type(v1, v2);}
00211
00212
00213
00214 #endif // INSTIGATE_SCRIPTING_GENERIC_BASE
00215