]> git.tdb.fi Git - libs/datafile.git/blob - source/value.h
Cosmetic changes
[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 typedef DEPRECATED std::vector<Value> ValueArray;
39
40 template<typename T>
41 inline T Value::get_() const
42 {
43         return data.value<typename TypeInfo<T>::Store>();
44 }
45
46 template<>
47 inline FloatType::Store Value::get_<FloatType::Store>() const
48 {
49         if(sig==IntType::signature)
50                 return data.value<IntType::Store>();
51         else
52                 return data.value<FloatType::Store>();
53 }
54
55 } // namespace DataFile
56 } // namespace Msp
57
58 #endif