00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef STRINGIZER_H
00027 #define STRINGIZER_H
00028 
00029 #include <sstream>
00030 
00031 template <typename Char>
00032 struct basic_stringizer
00033 {
00034     typedef std::basic_string<Char> String;
00035 
00036     template <typename T>
00037     String operator()(const T& t)
00038     {
00039         std::basic_stringstream<Char> s;
00040         s << t;
00041         return s.str();
00042     }
00043 
00044 #ifndef NO_PARTIAL_SPECIALIZATION
00045     template <>
00046     String operator()<Char*>(const Char* s)
00047     { return s; }
00048 
00049     template <>
00050     String operator()<String>(const String& s)
00051     { return s; }
00052 
00053     template <typename T>
00054     String operator()<T*>(const T* p)
00055     { return operator()<void*>(p); }
00056 
00057     template <>
00058     String operator()<void*>(const void* p)
00059     {
00060         std::basic_stringstream<Char> s;
00061         s << const_cast<void*>(p);
00062         return s.str();
00063     }
00064 #endif // NO_PARTIAL_SPECIALIZATION
00065 };
00066 
00067 
00068 typedef basic_stringizer<char> stringizer;
00069 typedef basic_stringizer<wchar_t> wstringizer;
00070 
00071 template <typename T>
00072 inline std::string stringize(T t)
00073 { return stringizer()(t); }
00074 
00075 template <typename T>
00076 inline std::wstring wstringize(T t)
00077 { return wstringizer()(t); }
00078 
00079 #endif // STRINGIZER_H