00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MMX_OBJECT_FORMAT_HPP
00014 #define __MMX_OBJECT_FORMAT_HPP
00015 #include <basix/string.hpp>
00016 #include <basix/generic.hpp>
00017
00018 namespace mmx {
00019 #define TMPL template<typename C>
00020
00021
00022
00023
00024
00025 template<typename Obj, typename Cat>
00026 struct object_format {
00027 Cat tp;
00028 inline object_format () {}
00029 inline object_format (const no_format&) {}
00030 inline object_format (const Obj& obj): tp (obj->tp) {}
00031 inline object_format (const Cat& tp2): tp (tp2) {}
00032 inline object_format (const object_format& x): tp (x.tp) {}
00033 inline object_format<Obj,Cat> rfm () const { return *this; }
00034 };
00035
00036 #define DEFINE_OBJECT_FORMAT(Obj,Cat) \
00037 STMPL struct format<Obj >: public object_format<Obj,Cat> { \
00038 typedef object_format<Obj,Cat> FT; \
00039 inline format (): FT (no_format ()) {} \
00040 inline format (const no_format& nfm): FT (nfm) {} \
00041 inline format (const Cat& tp): FT (tp) {} \
00042 inline format (const FT& x): FT (x) {} \
00043 inline format (const format<Obj >& fm): FT (fm.rfm()) {} \
00044 inline format<Obj > tfm () const { return *this; } \
00045 inline Obj sample () const { \
00046 return Obj (get_sample (this->tp), this->tp); } \
00047 }; \
00048 \
00049 inline format<Obj> \
00050 copy (const format<Obj> &x) { return format<Obj> (x); } \
00051 inline bool \
00052 operator == (const format<Obj>& x, const format<Obj>& y) { \
00053 return x.tp == y.tp; } \
00054 inline bool \
00055 operator != (const format<Obj>& x, const format<Obj>& y) { \
00056 return x.tp != y.tp; } \
00057 inline bool \
00058 exact_eq (const format<Obj>& x, const format<Obj>& y) { \
00059 return exact_eq (x.tp, y.tp); } \
00060 inline bool \
00061 exact_neq (const format<Obj>& x, const format<Obj>& y) { \
00062 return exact_neq (x.tp, y.tp); } \
00063 inline bool \
00064 hard_eq (const format<Obj>& x, const format<Obj>& y) { \
00065 return hard_eq (x.tp, y.tp); } \
00066 inline bool \
00067 hard_neq (const format<Obj>& x, const format<Obj>& y) { \
00068 return hard_neq (x.tp, y.tp); } \
00069 inline nat \
00070 hash (const format<Obj>& x) { \
00071 return hash (x.tp); } \
00072 inline nat \
00073 exact_hash (const format<Obj>& x) { \
00074 return exact_hash (x.tp); } \
00075 inline nat \
00076 hard_hash (const format<Obj>& x) { \
00077 return hard_hash (x.tp); } \
00078 inline syntactic \
00079 flatten (const format<Obj>& x) { \
00080 string name= cpp_demangle (typeid (format<Obj>).name ()); \
00081 return apply (flatten (lit (name)), flatten (x.tp)); } \
00082 inline format<Obj> \
00083 get_format (const Obj& x) { \
00084 return format<Obj> (x->tp); }
00085
00086 #undef TMPL
00087 }
00088 #endif // __MMX_OBJECT_FORMAT_HPP