00001
00002
00003
00004 #ifndef AITOOLS_INVERTEDINDEX_CONVERTER_HPP
00005 #define AITOOLS_INVERTEDINDEX_CONVERTER_HPP
00006
00007 #include <stdint.h>
00008 #include <typeinfo>
00009 #include <string>
00010
00011 namespace aitools {
00012 namespace invertedindex {
00013
00023 class Converter {
00024
00025 private:
00026
00030 Converter();
00031
00035 ~Converter();
00036
00037 public:
00038
00044 static uint32_t str_to_ui32(const std::string& str);
00045
00051 static uint64_t str_to_ui64(const std::string& str);
00052
00058 static std::string ui32_to_str(uint32_t number);
00059
00065 static std::string ui64_to_str(uint64_t number);
00066
00067 static std::string float_to_str(float number);
00068
00069 static std::string double_to_str(double number);
00070
00071 template<typename T>
00072 static std::string nameof();
00073
00074 };
00075
00076
00077
00078 template<typename T>
00079 std::string
00080 Converter::nameof()
00081 {
00082
00083 if (typeid(T) == typeid(char)) return "char";
00084 else if (typeid(T) == typeid(wchar_t)) return "wchar_t";
00085
00086 else if (typeid(T) == typeid(int8_t)) return "int8_t";
00087 else if (typeid(T) == typeid(int16_t)) return "int16_t";
00088 else if (typeid(T) == typeid(int32_t)) return "int32_t";
00089 else if (typeid(T) == typeid(int64_t)) return "int64_t";
00090
00091 else if (typeid(T) == typeid(uint8_t)) return "uint8_t";
00092 else if (typeid(T) == typeid(uint16_t)) return "uint16_t";
00093 else if (typeid(T) == typeid(uint32_t)) return "uint32_t";
00094 else if (typeid(T) == typeid(uint64_t)) return "uint64_t";
00095
00096 else if (typeid(T) == typeid(float)) return "float";
00097 else if (typeid(T) == typeid(double)) return "double";
00098
00099 else return std::string(typeid(T).name());
00100 }
00101
00102 }
00103 }
00104
00105 #endif // AITOOLS_INVERTEDINDEX_CONVERTER_HPP