OSSIA
Open Scenario System for Interactive Application
behavior.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 
5 
6 #include <memory>
7 #include <stdexcept>
8 #include <vector>
9 
13 namespace ossia
14 {
15 
16 template <typename X, typename Y>
17 class curve;
18 
19 struct behavior;
20 struct behavior_variant_type
21 {
22 public:
23  struct dummy_t
24  {
25  };
26  union Impl
27  {
28  std::shared_ptr<ossia::curve_abstract> m_value0;
29 
30  std::vector<ossia::behavior> m_value1;
31 
32  dummy_t m_dummy;
33  Impl()
34  : m_dummy{}
35  {
36  }
37  ~Impl() { }
38  };
39 
40  enum Type : int8_t
41  {
42  Type0,
43  Type1,
44  Npos
45  };
46 
47  void destruct_impl();
48  Impl m_impl;
49  Type m_type;
50 
51 public:
52  static const constexpr auto npos = Npos;
53  [[nodiscard]] int which() const;
54 
55  operator bool() const;
56  template <typename T>
57  const T* target() const;
58  template <typename T>
59  T* target();
60  template <typename T>
61  const T& get() const;
62  template <typename T>
63  T& get();
64 
65  template <typename T>
66  static Type matching_type();
67  behavior_variant_type();
68  ~behavior_variant_type();
69  behavior_variant_type(const std::shared_ptr<ossia::curve_abstract>& v);
70  behavior_variant_type(std::shared_ptr<ossia::curve_abstract>&& v);
71  behavior_variant_type(const std::vector<ossia::behavior>& v);
72  behavior_variant_type(std::vector<ossia::behavior>&& v);
73  behavior_variant_type(const behavior_variant_type& other);
74  behavior_variant_type(behavior_variant_type&& other) noexcept;
75  behavior_variant_type& operator=(const behavior_variant_type& other);
76  behavior_variant_type& operator=(behavior_variant_type&& other) noexcept;
77 };
84 struct OSSIA_EXPORT behavior final
85 {
86  behavior_variant_type v;
87 
88  behavior() = default;
89  behavior(const behavior&) = default;
90  behavior(behavior&&) = default;
91  behavior& operator=(const behavior&) = default;
92  behavior& operator=(behavior&&) = default;
93 
94  behavior(std::shared_ptr<ossia::curve_abstract> c)
95  : v{std::move(c)}
96  {
97  }
98  template <typename T, typename U>
99  behavior(std::shared_ptr<ossia::curve<T, U>> c)
100  : v{curve_ptr{std::move(c)}}
101  {
102  }
103  behavior(std::vector<ossia::behavior> c)
104  : v{std::move(c)}
105  {
106  }
107 
111  void reset();
112 
113  operator bool() const { return bool(v); }
114 
115  template <typename T>
116  const T& get() const
117  {
118  return v.get<T>();
119  }
120 
121  template <typename T>
122  T& get()
123  {
124  return v.get<T>();
125  }
126 
127  template <typename T>
128  const T* target() const noexcept
129  {
130  return v.target<T>();
131  }
132 
133  template <typename T>
134  T* target() noexcept
135  {
136  return v.target<T>();
137  }
138 
139  template <typename Visitor>
140  auto apply(Visitor&& vis) -> decltype(auto);
141 
142  template <typename Visitor>
143  auto apply(Visitor&& vis) const -> decltype(auto);
144 };
145 #include <ossia/editor/curve/behavior_variant_impl.hpp>
146 
147 template <typename Visitor>
148 inline auto behavior::apply(Visitor&& vis) -> decltype(auto)
149 {
150  return ossia::apply(std::forward<Visitor>(vis), this->v);
151 }
152 
153 template <typename Visitor>
154 inline auto behavior::apply(Visitor&& vis) const -> decltype(auto)
155 {
156  return ossia::apply(std::forward<Visitor>(vis), this->v);
157 }
158 
159 template <typename Functor>
160 auto apply(Functor&& functor, const behavior& var) -> decltype(auto)
161 {
162  return ossia::apply(std::forward<Functor>(functor), var.v);
163 }
164 template <typename Functor>
165 auto apply(Functor&& functor, behavior& var) -> decltype(auto)
166 {
167  return ossia::apply(std::forward<Functor>(functor), var.v);
168 }
169 template <typename Functor>
170 auto apply(Functor&& functor, behavior&& var) -> decltype(auto)
171 {
172  return ossia::apply(std::forward<Functor>(functor), std::move(var.v));
173 }
174 template <typename Functor>
175 auto apply_nonnull(Functor&& functor, const behavior& var) -> decltype(auto)
176 {
177  return ossia::apply_nonnull(std::forward<Functor>(functor), var.v);
178 }
179 template <typename Functor>
180 auto apply_nonnull(Functor&& functor, behavior& var) -> decltype(auto)
181 {
182  return ossia::apply_nonnull(std::forward<Functor>(functor), var.v);
183 }
184 template <typename Functor>
185 auto apply_nonnull(Functor&& functor, behavior&& var) -> decltype(auto)
186 {
187  return ossia::apply_nonnull(std::forward<Functor>(functor), std::move(var.v));
188 }
189 
190 }
Definition: git_info.h:7
val_type matching_type(const unit_t &u)
underlying_type Get the implementation type of an unit
Definition: dataspace_visitors.cpp:198