OSSIA
Open Scenario System for Interactive Application
node_functions.hpp File Reference

Detailed Description

Various utilities to work with a node hierarchy.

Go to the source code of this file.

Namespaces

 ossia
 

Functions

OSSIA_EXPORT ossia::net::node_baseossia::net::find_node (node_base &dev, std::string_view parameter_base)
 Find a node in a device. More...
 
OSSIA_EXPORT std::vector< ossia::net::node_base * > ossia::net::find_nodes (node_base &dev, std::string_view pattern)
 Find all nodes matching a pattern in a device. More...
 
OSSIA_EXPORT node_base & ossia::net::create_node (node_base &dev, std::string_view parameter_base)
 Create a node in a device. More...
 
OSSIA_EXPORT std::vector< ossia::net::node_base * > ossia::net::create_nodes (node_base &dev, std::string_view pattern)
 Create nodes according to a brace-expansion-like mechanism. More...
 
OSSIA_EXPORT node_base & ossia::net::find_or_create_node (node_base &dev, std::string_view parameter_base)
 Find a node and create it if it does not exist. More...
 
parameter_base * ossia::net::find_or_create_parameter (node_base &node, std::string_view address, std::string_view type)
 
OSSIA_EXPORT std::vector< parameter_base * > ossia::net::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. More...
 
OSSIA_EXPORT node_base * ossia::net::find_or_create_node (node_base &dev, std::string_view parameter_base, bool create)
 Calls find_node or create_node according to the value create
 
void ossia::net::sanitize_name (std::string &name, const node_base::children_t &brethren)
 Get a valid name for a given node.
 
OSSIA_EXPORT ossia::value_with_unit ossia::net::get_value (const ossia::destination &addr)
 Get the value associated with a destination.
 
OSSIA_EXPORT void ossia::net::push_value (const ossia::destination &addr, const ossia::value_with_unit &)
 Send a value to a given destination.
 
template<typename Address >
auto ossia::net::create_parameter (ossia::net::node_base &root, std::string name)
 
template<typename Address >
auto ossia::net::find_parameter_or_create_node (ossia::net::node_base &root, std::string_view name)
 
OSSIA_EXPORT std::ostream & ossia::net::operator<< (std::ostream &, const ossia::net::parameter_base &)
 
OSSIA_EXPORT void ossia::net::expand_ranges (std::string &str)
 
OSSIA_EXPORT std::pair< std::vector< std::string >, bool > ossia::net::expand_address (std::string address)
 
OSSIA_EXPORT std::vector< ossia::net::node_base * > ossia::net::list_all_children (ossia::net::node_base *node, unsigned int depth=0, bool sort=true)
 list_all_children : list all child nodes recursively More...
 
OSSIA_EXPORT void ossia::net::list_all_children (ossia::net::node_base *node, std::vector< ossia::net::node_base * > &out, unsigned int depth, bool sort)
 
OSSIA_EXPORT void ossia::net::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 void ossia::net::fuzzysearch (const std::vector< ossia::net::node_base * > &node, const std::vector< std::string > &patterns, std::vector< fuzzysearch_result > &results, fuzzysearch_options={})
 
OSSIA_EXPORT ossia::value_map_type ossia::net::to_map (const ossia::net::node_base &n) noexcept
 Converts a node in a map of values. More...
 

Function Documentation

◆ find_node()

OSSIA_EXPORT ossia::net::node_base* ossia::net::find_node ( node_base dev,
std::string_view  parameter_base 
)

Find a node in a device.

The address is in OSC format, e.g. /foo/bar.

Returns
null if the node was not found.

◆ find_nodes()

OSSIA_EXPORT std::vector<ossia::net::node_base*> ossia::net::find_nodes ( node_base dev,
std::string_view  pattern 
)

Find all nodes matching a pattern in a device.

The address is in OSC pattern match format, e.g. /foo.[0-5]/bar*

Note
If the pattern is known beforehand and may be reused, prefer storing a traversal::path and using the functions in path.hpp.

◆ create_node()

OSSIA_EXPORT node_base& ossia::net::create_node ( node_base dev,
std::string_view  parameter_base 
)

Create a node in a device.

If the node already exists, a new instance will be created. Hence there is no guarantee that the created node name is the same than the one requested; the output should be checked.

◆ create_nodes()

OSSIA_EXPORT std::vector<ossia::net::node_base*> ossia::net::create_nodes ( node_base dev,
std::string_view  pattern 
)

Create nodes according to a brace-expansion-like mechanism.

Only [] and { } are possible. e.g. /foo/{bar,baz}.[0-9][0-9].

See also
ossia::net::is_brace_expansion

◆ find_or_create_node()

OSSIA_EXPORT node_base& ossia::net::find_or_create_node ( node_base dev,
std::string_view  parameter_base 
)

Find a node and create it if it does not exist.

If the node exists, it will be returned, else a new node will be created.

◆ find_parameter_or_create_node()

OSSIA_EXPORT std::vector<parameter_base*> ossia::net::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.

Find a node matching the address, if it already has a parameter create a new one (with name incremented by 1), if not create parameter It some matching nodes does not exist, they will be created with a parameter

Parameters
node
address
typeof the parameter
Returns
vector of created parameters

◆ list_all_children()

OSSIA_EXPORT std::vector<ossia::net::node_base*> ossia::net::list_all_children ( ossia::net::node_base node,
unsigned int  depth = 0,
bool  sort = true 
)

list_all_children : list all child nodes recursively

Parameters
node: starting point
Returns
list : vector of children sorted by name then by priority

◆ to_map()

OSSIA_EXPORT ossia::value_map_type ossia::net::to_map ( const ossia::net::node_base n)
noexcept

Converts a node in a map of values.

e.g. given the tree

/foo/bar: 10
/foo/baz
/foo/baz/bux: [1.3, 5.]

then to_map(foo) gives something more or less like:

map{ { "bar", 10 }, { "baz", map{ { "bux", vector{1.3, 5} } } } }