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