00001 //////////////////////////////////////////////////////////////////////// 00002 // The NAME_TYPE mechanism is far, far supperior to the CLASS_NAME() 00003 // macro, as it can handle ANY type name. 00004 // It does not have a multi-include guard, as it's usage does not 00005 // call for one. 00006 //////////////////////////////////////////////////////////////////////// 00007 #include <string> 00008 #ifndef NAME_TYPE 00009 # error "You must set both NAME_TYPE and TYPE_NAME before including this supermacro." 00010 #endif // NAME_TYPE 00011 00012 #ifndef TYPE_NAME 00013 # error "TYPE_NAME must be set if you use NAME_TYPE. Set it to the string form of NAME_TYPE." 00014 #endif 00015 00016 // #include "class_name.h" // for clname namespace suff 00017 00018 #ifndef CLNAME_INCLUDED 00019 #define CLNAME_INCLUDED 1 00020 // /** 00021 // The clname namespace contains INTERNAL code for the class_name 00022 // utility class. DON'T USE IT. 100% experimental. 00023 // */ 00024 // namespace clname { 00025 00026 // /** experimental. don't use. */ 00027 // typedef std::map<const std::type_info *,std::string> name_map_type; 00028 00029 // /** internal marker class */ 00030 // struct classname_sharing_context {}; 00031 00032 // /** experimental. don't use. */ 00033 // name_map_type & names_map() 00034 // { 00035 // return s11n::phoenix<name_map_type,classname_sharing_context>::instance(); 00036 // } 00037 00038 // /** experimental. don't use. */ 00039 // template <typename T> 00040 // void register_name( const std::string & classname ) 00041 // { 00042 // const std::type_info * ti = & typeid((T *)0); 00043 // names_map()[ti] = classname; 00044 // } 00045 00046 // /** experimental. don't use. */ 00047 // template <typename T> 00048 // const char * classname( const T * t ) 00049 // { 00050 // typedef name_map_type::const_iterator CIT; 00051 // const std::type_info * tid = & typeid(t); 00052 // CIT cit = names_map().find( tid ); 00053 // return (names_map().end() == cit) 00054 // ? tid->name() // eeek! 00055 // : (*cit).second.c_str(); 00056 00057 // } 00058 // } // namespace clname 00059 #include "class_name.h" 00060 #endif // CLNAME_INCLUDED 00061 00062 namespace { 00063 // template <typename T> struct class_name; 00064 00065 template <> 00066 struct class_name< NAME_TYPE > 00067 { 00068 static const char * name() { 00069 return TYPE_NAME; 00070 } 00071 }; 00072 template <> 00073 struct class_name< const NAME_TYPE > 00074 { 00075 static const char * name() { 00076 return TYPE_NAME; 00077 } 00078 }; 00079 template <> 00080 struct class_name< NAME_TYPE * > 00081 { 00082 static const char * name() { 00083 return TYPE_NAME; 00084 } 00085 }; 00086 00087 template <> 00088 struct class_name< const NAME_TYPE * > 00089 { 00090 static const char * name() { 00091 return TYPE_NAME; 00092 } 00093 }; 00094 00095 } 00096 #undef NAME_TYPE 00097 #undef TYPE_NAME 00098