]> git.tdb.fi Git - libs/datafile.git/blob - source/type.h
Drop copyright and license notices from source files
[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         typedef long long int Store;
23 };
24
25 struct FloatType
26 {
27         static const char signature = 'f';
28         typedef double Store;
29 };
30
31 struct BoolType
32 {
33         static const char signature = 'b';
34         typedef bool Store;
35 };
36
37 struct StringType
38 {
39         static const char signature = 's';
40         typedef std::string Store;
41 };
42
43 struct SymbolType
44 {
45         // For backward compatibility
46         static const char signature = 'e';
47         typedef Symbol Store;
48 };
49
50 template<typename T>
51 struct TypeInfo: SymbolType { };
52
53 template<>
54 struct TypeInfo<short int>: IntType { };
55
56 template<>
57 struct TypeInfo<unsigned short int>: IntType { };
58
59 template<>
60 struct TypeInfo<int>: IntType { };
61
62 template<>
63 struct TypeInfo<unsigned int>: IntType { };
64
65 template<>
66 struct TypeInfo<long int>: IntType { };
67
68 template<>
69 struct TypeInfo<unsigned long int>: IntType { };
70
71 template<>
72 struct TypeInfo<long long int>: IntType { };
73
74 template<>
75 struct TypeInfo<unsigned long long int>: IntType { };
76
77 template<>
78 struct TypeInfo<float>: FloatType { };
79
80 template<>
81 struct TypeInfo<double>: FloatType { };
82
83 template<>
84 struct TypeInfo<bool>: BoolType { };
85
86 template<>
87 struct TypeInfo<std::string>: StringType { };
88
89 template<typename T>
90 struct TypeInfo<const T>: TypeInfo<T> { };
91
92 template<typename T>
93 struct TypeInfo<T &>: TypeInfo<T> { };
94
95 } // namespace DataFile
96 } // namespace Msp
97
98 #endif