OSSIA
Open Scenario System for Interactive Application
value_traits.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <ossia/network/value/value.hpp>
3 
7 namespace ossia
8 {
9 
10 template <typename T>
11 struct value_trait;
12 
13 template <>
14 struct value_trait<ossia::impulse>
15 {
16  using ossia_type = ossia::impulse;
17  using value_type = void;
18  static const constexpr auto ossia_enum = val_type::IMPULSE;
19  static const constexpr bool is_numeric = false;
20  static const constexpr bool is_array = false;
21 };
22 
23 template <>
24 struct value_trait<int32_t>
25 {
26  using ossia_type = int32_t;
27  using value_type = int32_t;
28  static const constexpr auto ossia_enum = val_type::INT;
29  static const constexpr bool is_numeric = true;
30  static const constexpr bool is_array = false;
31 };
32 
33 template <>
34 struct value_trait<float>
35 {
36  using ossia_type = float;
37  using value_type = float;
38  static const constexpr auto ossia_enum = val_type::FLOAT;
39  static const constexpr bool is_numeric = true;
40  static const constexpr bool is_array = false;
41 };
42 
43 template <>
44 struct value_trait<bool>
45 {
46  using ossia_type = bool;
47  using value_type = bool;
48  static const constexpr auto ossia_enum = val_type::BOOL;
49  static const constexpr bool is_numeric = true;
50  static const constexpr bool is_array = false;
51 };
52 
53 template <>
54 struct value_trait<char>
55 {
56  using ossia_type = int;
57  using value_type = char;
58  static const constexpr auto ossia_enum = val_type::INT;
59  static const constexpr bool is_numeric = true;
60  static const constexpr bool is_array = false;
61 };
62 
63 template <>
64 struct value_trait<value_map_type>
65 {
66  using ossia_type = value_map_type;
67  using value_type = value_map_type;
68  static const constexpr auto ossia_enum = val_type::MAP;
69  static const constexpr bool is_numeric = false;
70  static const constexpr bool is_array = true;
71 };
72 
73 template <>
74 struct value_trait<std::string>
75 {
76  using ossia_type = std::string;
77  using value_type = std::string;
78  static const constexpr auto ossia_enum = val_type::STRING;
79  static const constexpr bool is_numeric = false;
80  static const constexpr bool is_array = false;
81 };
82 
83 template <>
84 struct value_trait<std::vector<ossia::value>>
85 {
86  using ossia_type = std::vector<ossia::value>;
87  using value_type = std::vector<value>;
88  static const constexpr auto ossia_enum = val_type::LIST;
89  static const constexpr bool is_numeric = false;
90  static const constexpr bool is_array = true;
91 };
92 
93 template <>
94 struct value_trait<ossia::vec2f>
95 {
96  using ossia_type = ossia::vec2f;
97  using value_type = std::array<float, 2>;
98  static const constexpr auto ossia_enum = val_type::VEC2F;
99  static const constexpr bool is_numeric = false;
100  static const constexpr bool is_array = true;
101 };
102 
103 template <>
104 struct value_trait<ossia::vec3f>
105 {
106  using ossia_type = ossia::vec3f;
107  using value_type = std::array<float, 3>;
108  static const constexpr auto ossia_enum = val_type::VEC3F;
109  static const constexpr bool is_numeric = false;
110  static const constexpr bool is_array = true;
111 };
112 
113 template <>
114 struct value_trait<ossia::vec4f>
115 {
116  using ossia_type = ossia::vec4f;
117  using value_type = std::array<float, 4>;
118  static const constexpr auto ossia_enum = val_type::VEC4F;
119  static const constexpr bool is_numeric = false;
120  static const constexpr bool is_array = true;
121 };
122 
123 template <>
124 struct value_trait<ossia::value>
125 {
126  using ossia_type = ossia::value;
127  using value_type = ossia::value;
128  static const constexpr bool is_numeric = false;
129  static const constexpr bool is_array = false;
130 };
131 
136 OSSIA_EXPORT
137 bool is_numeric(const ossia::value& v);
138 
143 OSSIA_EXPORT
144 bool is_array(const ossia::value& v);
145 }
The value class.
Definition: value.hpp:173
ossia_type
Definition: ossia-c.h:376
Definition: git_info.h:7
@ IMPULSE
array<float, 4>
@ VEC3F
array<float, 2>
@ LIST
std::string
@ VEC4F
array<float, 3>
@ MAP
std::vector<value>
@ BOOL
ossia::impulse
bool is_array(const ossia::value &val)
is_numeric True if the value is of an array type (list, vec...)
Definition: value.cpp:631
bool is_numeric(const ossia::value &val)
is_numeric True if the value is of a numeric type (int, bool, float, char...)
Definition: value.cpp:624