]> git.tdb.fi Git - libs/datafile.git/blob - source/value.h
Remove some long-deprecated things
[libs/datafile.git] / source / value.h
1 #ifndef MSP_DATAFILE_VALUE_H_
2 #define MSP_DATAFILE_VALUE_H_
3
4 #include <vector>
5 #include <msp/core/attributes.h>
6 #include <msp/core/meta.h>
7 #include <msp/core/variant.h>
8 #include "type.h"
9
10 namespace Msp {
11 namespace DataFile {
12
13 class Value
14 {
15 private:
16         char sig;
17         Variant data;
18
19 public:
20         template<typename T>
21         Value(T d):
22                 sig(TypeInfo<T>::signature),
23                 data(static_cast<typename TypeInfo<T>::Store>(d))
24         { }
25
26         Value(Symbol d): sig(TypeInfo<Symbol>::signature), data(d) { }
27
28         template<typename T>
29         typename TypeInfo<T>::Load get() const
30         { return get_<typename TypeInfo<T>::Store>(); }
31
32         char get_signature() const { return sig; }
33 private:
34         template<typename T>
35         T get_() const;
36 };
37
38 template<typename T>
39 inline T Value::get_() const
40 {
41         return data.value<typename TypeInfo<T>::Store>();
42 }
43
44 template<>
45 inline FloatType::Store Value::get_<FloatType::Store>() const
46 {
47         if(sig==IntType::signature)
48                 return data.value<IntType::Store>();
49         else
50                 return data.value<FloatType::Store>();
51 }
52
53 } // namespace DataFile
54 } // namespace Msp
55
56 #endif