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_GENERIC_BASE
00024 #define INSTIGATE_GENERIC_BASE
00025
00033
00034
00035
00036
00037
00038
00039
00040
00046 namespace instigate {
00047 namespace generic {
00048 template <int> class require;
00049 template <> class require<1>;
00050 template <typename T, typename U> class conversion;
00051 template <typename T> class conversion<T, T>;
00052 template <typename T> struct type_to_type;
00053 template <int t> struct int_to_type;
00054 }
00055 }
00056
00057
00064 #define CHECK(R) {R();}
00065
00071 #define CHECK_CONVERTIBILITY(T, U) {\
00072 instigate::generic::require<instigate::\
00073 generic::conversion<T, U>::exists>();}
00074
00078 #define CHECK_SAME_TYPE(T, U) {\
00079 instigate::generic::require<instigate::\
00080 generic::conversion<T, U>::same_type>();}
00081
00088 template <>
00089 class instigate::generic::require<1>
00090 {};
00091
00109 template <typename T, typename U>
00110 class instigate::generic::conversion
00111 {
00112 private:
00113 typedef char small;
00114 class big { char a[2]; };
00115 static T makeT();
00116 static small test(U);
00117 static big test(...);
00118 public:
00119 static const bool exists = (sizeof(small) == sizeof(test(makeT())));
00120 static const bool same_type = false;
00121 static const bool super_sub_class =
00122 conversion<const U*, const T*>::exists &&
00123 !conversion<const T*, const void*>::same_type;
00124 };
00125
00126 template <typename T>
00127 class instigate::generic::conversion<T, T>
00128 {
00129 public:
00130 static const bool exists = true;
00131 static const bool same_type = true;
00132 static const bool super_sub_class = false;
00133 };
00134
00163 template <int t>
00164 struct instigate::generic::int_to_type
00165 {
00166 enum { value = t };
00167 };
00168
00197 template <typename T>
00198 struct instigate::generic::type_to_type
00199 {
00200 typedef T original_type;
00201 };
00202
00203 template <typename U, typename F>
00204 static void require_same_type(U v1, F v2)
00205 {
00206 CHECK_SAME_TYPE(U, F);
00207 }
00208
00209 #define REQUIRE_SAME_TYPE(v1, v2){require_same_type(v1, v2);}
00210
00211
00212
00213 #endif // INSTIGATE_FRAMEWORK_GENERIC_BASE
00214