00001
00009 #ifndef ZMQMESSAGE_METATYPES_HPP_
00010 #define ZMQMESSAGE_METATYPES_HPP_
00011
00012 namespace ZmqMessage
00013 {
00019 namespace Private
00020 {
00021 template <bool, class T = void>
00022 struct EnableIf {};
00023
00024 template <class T>
00025 struct EnableIf<true, T> { typedef T type; };
00026
00027 template <bool, class T = void>
00028 struct DisableIf {};
00029
00030 template <class T>
00031 struct DisableIf<false, T> { typedef T type; };
00032
00033 template <class T>
00034 struct IsStr
00035 {
00036 typedef char Yes;
00037 typedef struct { char c[2]; } No;
00038
00039 template <typename U, size_t (U::*LengthFn)() const = &U::length>
00040 struct LengthTraits;
00041 template <typename U, const char* (U::*DataFn)() const = &U::data>
00042 struct DataTraits;
00043
00044 template <typename U>
00045 static No check_str(...);
00046
00047 template <typename U>
00048 static Yes check_str(LengthTraits<U>*, DataTraits<U>*);
00049
00050 static const bool value = (sizeof(check_str<T>(0, 0)) == sizeof(Yes));
00051 };
00052
00053 template <class T>
00054 struct IsRaw
00055 {
00056 typedef char Yes;
00057 typedef struct { char c[2]; } No;
00058
00059 template <typename U>
00060 static No check_mark(...);
00061
00062 template <typename U>
00063 static Yes check_mark(typename U::raw_mark* = 0);
00064
00065 static const bool value = (sizeof(check_mark<T>(0)) == sizeof(Yes));
00066 };
00067 }
00068 }
00069
00076 #define ZMQMESSAGE_BINARY_TYPE(type_name) \
00077 namespace ZmqMessage \
00078 { \
00079 namespace Private \
00080 { \
00081 template <> \
00082 struct IsRaw<type_name> \
00083 { \
00084 static const bool value = true; \
00085 }; \
00086 } \
00087 }
00088
00095 #define ZMQMESSAGE_TEXT_TYPE(type_name) \
00096 namespace ZmqMessage \
00097 { \
00098 namespace Private \
00099 { \
00100 template <> \
00101 struct IsRaw<type_name> \
00102 { \
00103 static const bool value = false; \
00104 }; \
00105 } \
00106 }
00107
00108
00109
00110 #endif