ValueConversion.hpp
1 #pragma once
2 #include <State/Value.hpp>
3 
4 #include <QChar>
5 #include <QString>
6 #include <QStringList>
7 #include <QVariant>
8 
9 namespace State
10 {
11 namespace convert
12 {
13 
14 template <typename To>
15 To value(const ossia::value& val)
16 {
17  static_assert(sizeof(To) == -1, "Type not supported.");
18 }
19 
20 template <>
21 SCORE_LIB_STATE_EXPORT QVariant value(const ossia::value& val);
22 template <>
23 SCORE_LIB_STATE_EXPORT int value(const ossia::value& val);
24 template <>
25 SCORE_LIB_STATE_EXPORT float value(const ossia::value& val);
26 template <>
27 SCORE_LIB_STATE_EXPORT bool value(const ossia::value& val);
28 template <>
29 SCORE_LIB_STATE_EXPORT double value(const ossia::value& val);
30 template <>
31 SCORE_LIB_STATE_EXPORT QString value(const ossia::value& val);
32 template <>
33 SCORE_LIB_STATE_EXPORT QChar value(const ossia::value& val);
34 template <>
35 SCORE_LIB_STATE_EXPORT std::string value(const ossia::value& val);
36 template <>
37 SCORE_LIB_STATE_EXPORT char value(const ossia::value& val);
38 template <>
39 SCORE_LIB_STATE_EXPORT vec2f value(const ossia::value& val);
40 template <>
41 SCORE_LIB_STATE_EXPORT vec3f value(const ossia::value& val);
42 template <>
43 SCORE_LIB_STATE_EXPORT vec4f value(const ossia::value& val);
44 template <>
45 SCORE_LIB_STATE_EXPORT list_t value(const ossia::value& val);
46 template <>
47 SCORE_LIB_STATE_EXPORT ossia::value_map_type value(const ossia::value& val);
48 
49 SCORE_LIB_STATE_EXPORT bool convert(const ossia::value& orig, ossia::value& toConvert);
50 
51 // Adornishments to allow to differentiate between different value types, e.g.
52 // 'a', ['a', 12], or "str" for a string.
53 SCORE_LIB_STATE_EXPORT QString toPrettyString(const ossia::value& val);
54 
55 // We require the type to crrectly read back (e.g. int / float / char)
56 // and as an optimization, since we may need it multiple times,
57 // we chose to leave the caller save it however he wants. Hence the specific
58 // API.
59 SCORE_LIB_STATE_EXPORT QString
60 textualType(const ossia::value& val); // For JSONValue serialization
61 SCORE_LIB_STATE_EXPORT ossia::value fromQVariant(const QVariant& val);
62 SCORE_LIB_STATE_EXPORT QString
63 prettyType(const ossia::value& val); // For display to the user, translated
64 SCORE_LIB_STATE_EXPORT
65 QString prettyType(ossia::val_type); // For display to the user, translated
66 SCORE_LIB_STATE_EXPORT const std::array<const QString, 11>&
67 ValuePrettyTypesArray(); // For display to the user, translated
68 SCORE_LIB_STATE_EXPORT const QStringList&
69 ValuePrettyTypesList(); // For display to the user, translated
70 SCORE_LIB_STATE_EXPORT const std::array<std::pair<QString, ossia::val_type>, 10>&
71 ValuePrettyTypesMap();
72 }
73 }
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33