OSSIA
Open Scenario System for Interactive Application
node_functions.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <ossia/network/base/address_scope.hpp>
3 #include <ossia/network/base/node.hpp>
5 
6 #include <functional>
7 
13 namespace ossia
14 {
15 namespace net
16 {
17 
25 OSSIA_EXPORT ossia::net::node_base*
26 find_node(node_base& dev, std::string_view parameter_base);
27 
36 OSSIA_EXPORT std::vector<ossia::net::node_base*>
37 find_nodes(node_base& dev, std::string_view pattern);
38 
46 OSSIA_EXPORT node_base& create_node(node_base& dev, std::string_view parameter_base);
47 
56 OSSIA_EXPORT std::vector<ossia::net::node_base*>
57 create_nodes(node_base& dev, std::string_view pattern);
58 
64 OSSIA_EXPORT node_base&
66 
67 parameter_base* find_or_create_parameter(
68  node_base& node, std::string_view address, std::string_view type);
79 OSSIA_EXPORT std::vector<parameter_base*> find_parameter_or_create_node(
80  node_base& node, std::string_view address, std::string_view type);
81 
85 OSSIA_EXPORT node_base*
86 find_or_create_node(node_base& dev, std::string_view parameter_base, bool create);
87 
89 void sanitize_name(std::string& name, const node_base::children_t& brethren);
90 
94 OSSIA_EXPORT ossia::value_with_unit get_value(const ossia::destination& addr);
95 
99 OSSIA_EXPORT void
100 push_value(const ossia::destination& addr, const ossia::value_with_unit&);
101 
102 template <typename Address>
103 auto create_parameter(ossia::net::node_base& root, std::string name)
104 {
105  auto& node = ossia::net::create_node(root, std::move(name));
106  auto addr = new Address(node);
107  node.set_parameter(std::unique_ptr<Address>(addr));
108  return addr;
109 }
110 
111 template <typename Address>
112 auto find_parameter_or_create_node(ossia::net::node_base& root, std::string_view name)
113 {
114  auto& node = ossia::net::find_or_create_node(root, std::move(name));
115  if(auto p = dynamic_cast<Address*>(node.get_parameter()))
116  {
117  return p;
118  }
119  else
120  {
121  auto addr = new Address{node};
122  node.set_parameter(std::unique_ptr<Address>(addr));
123  return addr;
124  }
125 }
126 OSSIA_EXPORT std::ostream& operator<<(std::ostream&, const ossia::net::parameter_base&);
127 
128 OSSIA_EXPORT
129 void expand_ranges(std::string& str);
130 
131 OSSIA_EXPORT
132 std::pair<std::vector<std::string>, bool> expand_address(std::string address);
133 
139 OSSIA_EXPORT
140 std::vector<ossia::net::node_base*>
141 list_all_children(ossia::net::node_base* node, unsigned int depth = 0, bool sort = true);
142 
143 OSSIA_EXPORT
144 void
146  ossia::net::node_base* node,
147  std::vector<ossia::net::node_base*>&out,
148  unsigned int depth,
149  bool sort);
150 
154 OSSIA_EXPORT
156  ossia::net::node_base* node,
157  const std::function<void(ossia::net::parameter_base&)>&);
158 
159 struct OSSIA_EXPORT fuzzysearch_result
160 {
161  double score{};
162  std::string oscname;
163  ossia::net::node_base* node{};
164 
165  friend bool
166  operator==(const fuzzysearch_result& lhs, const fuzzysearch_result& rhs) noexcept
167  {
168  return lhs.score == rhs.score && lhs.oscname == rhs.oscname && lhs.node == rhs.node;
169  }
170 };
171 
172 struct fuzzysearch_options
173 {
174  bool case_sensitive{true};
175 };
176 
177 OSSIA_EXPORT
178 void fuzzysearch(
179  const std::vector<ossia::net::node_base*>& node,
180  const std::vector<std::string>& patterns, std::vector<fuzzysearch_result>& results,
181  fuzzysearch_options = {});
182 
201 OSSIA_EXPORT
202 ossia::value_map_type to_map(const ossia::net::node_base& n) noexcept;
203 
204 }
205 }
The node_base class.
Definition: node.hpp:48
The parameter_base class.
Definition: ossia/network/base/parameter.hpp:48
Definition: git_info.h:7
OSSIA_EXPORT void push_value(const ossia::destination &addr, const ossia::value_with_unit &)
Send a value to a given destination.
Definition: ossia/network/base/parameter.cpp:151
OSSIA_EXPORT ossia::value_map_type to_map(const ossia::net::node_base &n) noexcept
Converts a node in a map of values.
OSSIA_EXPORT std::vector< ossia::net::node_base * > list_all_children(ossia::net::node_base *node, unsigned int depth=0, bool sort=true)
list_all_children : list all child nodes recursively
OSSIA_EXPORT std::vector< ossia::net::node_base * > create_nodes(node_base &dev, std::string_view pattern)
Create nodes according to a brace-expansion-like mechanism.
OSSIA_EXPORT node_base & find_or_create_node(node_base &dev, std::string_view parameter_base)
Find a node and create it if it does not exist.
OSSIA_EXPORT ossia::net::node_base * find_node(node_base &dev, std::string_view parameter_base)
Find a node in a device.
OSSIA_EXPORT ossia::value_with_unit get_value(const ossia::destination &addr)
Get the value associated with a destination.
Definition: ossia/network/base/parameter.cpp:144
OSSIA_EXPORT std::vector< parameter_base * > find_parameter_or_create_node(node_base &node, std::string_view address, std::string_view type)
Find a parameter and create it if it does not exist.
OSSIA_EXPORT void iterate_all_children(ossia::net::node_base *node, const std::function< void(ossia::net::parameter_base &)> &)
Iterates all the child parameters given a base node.
OSSIA_EXPORT std::vector< ossia::net::node_base * > find_nodes(node_base &dev, std::string_view pattern)
Find all nodes matching a pattern in a device.
OSSIA_EXPORT node_base & create_node(node_base &dev, std::string_view parameter_base)
Create a node in a device.
Definition: value_with_unit.hpp:13