1 #ifndef MSP_DATAFILE_TYPE_H_
2 #define MSP_DATAFILE_TYPE_H_
4 #include <msp/core/inttypes.h>
5 #include <msp/strings/lexicalcast.h>
15 Symbol(const T &n): name(lexical_cast<std::string>(n)) { }
17 template<typename T> operator T() const { return lexical_cast<T>(name); }
22 static const char signature = 'i';
29 static const char signature = 'f';
36 static const char signature = 'b';
43 static const char signature = 's';
44 typedef std::string Store;
50 // For backward compatibility
51 static const char signature = 'e';
55 const char valid_signatures[] =
60 StringType::signature,
61 SymbolType::signature,
68 struct Yes { char c[2]; };
69 struct No { char c; };
72 static Yes f(typename U::LoadType *);
76 enum { value = (sizeof(f<T>(0))==sizeof(Yes)) };
79 template<typename T, bool lt = HasLoadType<T>::value>
83 struct TypeInfo<short int, false>: IntType { };
86 struct TypeInfo<unsigned short int, false>: IntType { };
89 struct TypeInfo<int, false>: IntType { };
92 struct TypeInfo<unsigned int, false>: IntType { };
95 struct TypeInfo<long int, false>: IntType { };
98 struct TypeInfo<unsigned long int, false>: IntType { };
100 #if defined(_MSC_VER)
102 struct TypeInfo<__int64, false>: IntType { };
105 struct TypeInfo<unsigned __int64, false>: IntType { };
106 #elif defined(__GNUC__)
108 struct TypeInfo<long long int, false>: IntType { };
111 struct TypeInfo<unsigned long long int, false>: IntType { };
115 struct TypeInfo<float, false>: FloatType { };
118 struct TypeInfo<double, false>: FloatType { };
121 struct TypeInfo<bool, false>: BoolType { };
124 struct TypeInfo<std::string, false>: StringType { };
127 struct TypeInfo<char *, false>: StringType { };
130 struct TypeInfo<const char *, false>: StringType { };
133 struct TypeInfo<const T, false>: TypeInfo<T> { };
136 struct TypeInfo<T &, false>: TypeInfo<T> { };
139 struct TypeInfo<T, true>: TypeInfo<typename T::LoadType>
140 { typedef typename T::LoadType Load; };
143 struct TypeInfo<T, false>: SymbolType
146 } // namespace DataFile