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);
142 
146 OSSIA_EXPORT
148  ossia::net::node_base* node,
149  const std::function<void(ossia::net::parameter_base&)>&);
150 
151 struct OSSIA_EXPORT fuzzysearch_result
152 {
153  double score{};
154  std::string oscname;
155  ossia::net::node_base* node{};
156 
157  friend bool
158  operator==(const fuzzysearch_result& lhs, const fuzzysearch_result& rhs) noexcept
159  {
160  return lhs.score == rhs.score && lhs.oscname == rhs.oscname && lhs.node == rhs.node;
161  }
162 };
163 
164 struct fuzzysearch_options
165 {
166  bool case_sensitive{true};
167 };
168 
169 OSSIA_EXPORT
170 void fuzzysearch(
171  const std::vector<ossia::net::node_base*>& node,
172  const std::vector<std::string>& patterns, std::vector<fuzzysearch_result>& results,
173  fuzzysearch_options = {});
174 
193 OSSIA_EXPORT
194 ossia::value_map_type to_map(const ossia::net::node_base& n) noexcept;
195 
196 }
197 }
The node_base class.
Definition: network/base/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 * > 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 std::vector< ossia::net::node_base * > list_all_children(ossia::net::node_base *node, unsigned int depth=0)
list_all_children : list all child nodes recursively
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