]> git.tdb.fi Git - libs/datafile.git/blob - source/type.h
Don't use long long on MSVC
[libs/datafile.git] / source / type.h
1 #ifndef MSP_DATAFILE_TYPE_H_
2 #define MSP_DATAFILE_TYPE_H_
3
4 #include <msp/strings/lexicalcast.h>
5
6 namespace Msp {
7 namespace DataFile {
8
9 struct Symbol
10 {
11         std::string name;
12
13         template<typename T>
14         Symbol(const T &n): name(lexical_cast(n)) { }
15
16         template<typename T> operator T() const { return lexical_cast<T>(name); }
17 };
18
19 struct IntType
20 {
21         static const char signature = 'i';
22 #ifdef MSVC
23         typedef __int64 Store;
24 #else
25         typedef long long int Store;
26 #endif
27         typedef Store Load;
28 };
29
30 struct FloatType
31 {
32         static const char signature = 'f';
33         typedef double Store;
34 };
35
36 struct BoolType
37 {
38         static const char signature = 'b';
39         typedef bool Store;
40 };
41
42 struct StringType
43 {
44         static const char signature = 's';
45         typedef std::string Store;
46 };
47
48 struct SymbolType
49 {
50         // For backward compatibility
51         static const char signature = 'e';
52         typedef Symbol Store;
53 };
54
55 template<typename T>
56 struct TypeInfo: SymbolType { };
57
58 template<>
59 struct TypeInfo<short int>: IntType { };
60
61 template<>
62 struct TypeInfo<unsigned short int>: IntType { };
63
64 template<>
65 struct TypeInfo<int>: IntType { };
66
67 template<>
68 struct TypeInfo<unsigned int>: IntType { };
69
70 template<>
71 struct TypeInfo<long int>: IntType { };
72
73 template<>
74 struct TypeInfo<unsigned long int>: IntType { };
75
76 #ifdef MSVC
77 template<>
78 struct TypeInfo<__int64>: IntType { };
79
80 template<>
81 struct TypeInfo<unsigned __int64>: IntType { };
82 #else
83 template<>
84 struct TypeInfo<long long int>: IntType { };
85
86 template<>
87 struct TypeInfo<unsigned long long int>: IntType { };
88 #endif
89
90 template<>
91 struct TypeInfo<float>: FloatType { };
92
93 template<>
94 struct TypeInfo<double>: FloatType { };
95
96 template<>
97 struct TypeInfo<bool>: BoolType { };
98
99 template<>
100 struct TypeInfo<std::string>: StringType { };
101
102 template<typename T>
103 struct TypeInfo<const T>: TypeInfo<T> { };
104
105 template<typename T>
106 struct TypeInfo<T &>: TypeInfo<T> { };
107
108 } // namespace DataFile
109 } // namespace Msp
110
111 #endif