OSSIA
Open Scenario System for Interactive Application
flat_vec_state.hpp
1 #pragma once
3 #include <ossia/detail/apply.hpp>
4 #include <ossia/detail/small_vector.hpp>
5 #include <ossia/editor/state/detail/state_execution_visitor.hpp>
7 
8 namespace ossia
9 {
10 struct flat_vec_state
11 {
12  using vec_type = ossia::small_vector<ossia::state_element, 16>;
13  using iterator = typename vec_type::iterator;
14  using const_iterator = typename vec_type::const_iterator;
15  ossia::small_vector<ossia::state_element, 16> m_children;
16  void add(const ossia::state_element& other) noexcept { m_children.push_back(other); }
17  void add(ossia::state_element&& other) noexcept
18  {
19  m_children.push_back(std::move(other));
20  }
21 
22  void remove(const_iterator other) noexcept { m_children.erase(other); }
23 
24  void remove(const state_element& e) { ossia::remove_erase(m_children, e); }
25 
26  template <typename T>
27  auto find(const T& val) noexcept
28  {
29  return ossia::find(m_children, val);
30  }
31 
32  void launch() noexcept
33  {
34  for(auto& state : m_children)
35  {
36  ossia::apply(state_execution_visitor{}, std::move(state));
37  }
38  }
39 
40  auto reserve(std::size_t n) noexcept { return m_children.reserve(n); }
41  auto clear() noexcept { return m_children.clear(); }
42  auto begin() noexcept { return m_children.begin(); }
43  auto end() noexcept { return m_children.end(); }
44  auto begin() const noexcept { return m_children.begin(); }
45  auto end() const noexcept { return m_children.end(); }
46 
47  auto size() const noexcept { return m_children.size(); }
48 };
49 
50 struct mono_state
51 {
53  void add(const ossia::state_element& other) { e = other; }
54  void add(ossia::state_element&& other) { e = std::move(other); }
55  template <typename T>
56  void remove(const T& other)
57  {
58  }
59 
60  template <typename T>
61  auto find(const T&)
62  {
63  return e ? &e : nullptr;
64  }
65 
66  auto end() const { return nullptr; }
67 };
68 
69 #if defined(OSSIA_SMALL_VECTOR)
70 inline ossia::state_element& get_state_element(ossia::flat_vec_state::iterator iterator)
71 {
72  return *iterator;
73 }
74 #endif
75 }
Definition: git_info.h:7
void launch(state_element &e)
launch Launch a state_element
Definition: state_element.cpp:18
ossia::nullable_variant< message, state, piecewise_message, piecewise_vec_message< 2 >, piecewise_vec_message< 3 >, piecewise_vec_message< 4 > > state_element
Definition: state_element_fwd.hpp:28