OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
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
13namespace ossia
14{
15namespace net
16{
17
25OSSIA_EXPORT ossia::net::node_base*
26find_node(node_base& dev, std::string_view parameter_base);
27
36OSSIA_EXPORT std::vector<ossia::net::node_base*>
37find_nodes(node_base& dev, std::string_view pattern);
38
46OSSIA_EXPORT node_base& create_node(node_base& dev, std::string_view parameter_base);
47
56OSSIA_EXPORT std::vector<ossia::net::node_base*>
57create_nodes(node_base& dev, std::string_view pattern);
58
64OSSIA_EXPORT node_base&
65find_or_create_node(node_base& dev, std::string_view parameter_base);
66
67parameter_base* find_or_create_parameter(
68 node_base& node, std::string_view address, std::string_view type);
79OSSIA_EXPORT std::vector<parameter_base*> find_parameter_or_create_node(
80 node_base& node, std::string_view address, std::string_view type);
81
85OSSIA_EXPORT node_base*
86find_or_create_node(node_base& dev, std::string_view parameter_base, bool create);
87
89void sanitize_name(std::string& name, const node_base::children_t& brethren);
90
94OSSIA_EXPORT ossia::value_with_unit get_value(const ossia::destination& addr);
95
99OSSIA_EXPORT void
100push_value(const ossia::destination& addr, const ossia::value_with_unit&);
101
102template <typename Address>
103auto 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
111template <typename Address>
112auto 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}
126OSSIA_EXPORT std::ostream& operator<<(std::ostream&, const ossia::net::parameter_base&);
127
128OSSIA_EXPORT
129void expand_ranges(std::string& str);
130
131OSSIA_EXPORT
132std::pair<std::vector<std::string>, bool> expand_address(std::string address);
133
139OSSIA_EXPORT
140std::vector<ossia::net::node_base*>
141list_all_children(ossia::net::node_base* node, unsigned int depth = 0, bool sort = true);
142
143OSSIA_EXPORT
144void
145list_all_children(
147 std::vector<ossia::net::node_base*>&out,
148 unsigned int depth,
149 bool sort);
150
154OSSIA_EXPORT
155void iterate_all_children(
157 const std::function<void(ossia::net::parameter_base&)>&);
158
159struct 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
172struct fuzzysearch_options
173{
174 bool case_sensitive{true};
175};
176
177OSSIA_EXPORT
178void 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
201OSSIA_EXPORT
202ossia::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
Definition value_with_unit.hpp:13