1 #ifndef MSP_DATAFILE_TYPE_H_
2 #define MSP_DATAFILE_TYPE_H_
4 #include <msp/core/inttypes.h>
5 #include <msp/strings/lexicalcast.h>
17 Symbol(const T &n): name(lexical_cast<std::string>(n)) { }
19 template<typename T> operator T() const { return lexical_cast<T>(name); }
24 static const char signature = 'i';
31 static const char signature = 'f';
38 static const char signature = 'b';
45 static const char signature = 's';
46 typedef std::string Store;
52 // For backward compatibility
53 static const char signature = 'e';
57 const char valid_signatures[] =
62 StringType::signature,
63 SymbolType::signature,
70 struct Yes { char c[2]; };
71 struct No { char c; };
74 static Yes f(typename U::LoadType *);
78 enum { value = (sizeof(f<T>(0))==sizeof(Yes)) };
81 template<typename T, bool lt = HasLoadType<T>::value>
85 struct TypeInfo<short int, false>: IntType { };
88 struct TypeInfo<unsigned short int, false>: IntType { };
91 struct TypeInfo<int, false>: IntType { };
94 struct TypeInfo<unsigned int, false>: IntType { };
97 struct TypeInfo<long int, false>: IntType { };
100 struct TypeInfo<unsigned long int, false>: IntType { };
102 #if defined(_MSC_VER)
104 struct TypeInfo<__int64, false>: IntType { };
107 struct TypeInfo<unsigned __int64, false>: IntType { };
108 #elif defined(__GNUC__)
110 struct TypeInfo<long long int, false>: IntType { };
113 struct TypeInfo<unsigned long long int, false>: IntType { };
117 struct TypeInfo<float, false>: FloatType { };
120 struct TypeInfo<double, false>: FloatType { };
123 struct TypeInfo<bool, false>: BoolType { };
126 struct TypeInfo<std::string, false>: StringType { };
129 struct TypeInfo<char *, false>: StringType { };
132 struct TypeInfo<const char *, false>: StringType { };
135 struct TypeInfo<const T, false>: TypeInfo<T> { };
138 struct TypeInfo<T &, false>: TypeInfo<T> { };
141 struct TypeInfo<T, true>: TypeInfo<typename T::LoadType>
142 { typedef typename T::LoadType Load; };
145 struct TypeInfo<T, false>: SymbolType
148 } // namespace DataFile