node: provide an API to fetch port by name

Retrieve the port from a node by its name.
This commit is contained in:
Stéphane Cerveau 2022-02-22 11:41:55 +01:00 committed by Stéphane Cerveau
parent 8c9cb35928
commit 46889d86d0

View file

@ -196,6 +196,19 @@ impl Node {
private.ports.borrow().get(&id).cloned() private.ports.borrow().get(&id).cloned()
} }
/// Get the port with the specified port name inside the node.
///
/// Returns `None` if the node is not in the graphview.
pub fn port_by_name(&self, name: &str) -> Option<Port> {
let private = imp::Node::from_obj(self);
for port in private.ports.borrow().values() {
if port.name() == name {
return Some(port.clone());
}
}
None
}
/// Check if we can remove a port dependending on PortPrensence attribute /// Check if we can remove a port dependending on PortPrensence attribute
/// ///
pub fn can_remove_port(&self, id: u32) -> bool { pub fn can_remove_port(&self, id: u32) -> bool {
@ -239,14 +252,14 @@ impl Node {
/// Retrieves the unique name composed with the node name and its id /// Retrieves the unique name composed with the node name and its id
/// ///
pub fn unique_name(&self) -> String { pub fn unique_name(&self) -> String {
let private = imp::Node::from_instance(self); let private = imp::Node::from_obj(self);
private.unique_name.borrow().clone() private.unique_name.borrow().clone()
} }
/// Update the unique name /// Update the unique name
/// ///
pub fn set_unique_name(&self, unique_name: &str) { pub fn set_unique_name(&self, unique_name: &str) {
let private = imp::Node::from_instance(self); let private = imp::Node::from_obj(self);
private.unique_name.replace(unique_name.to_string()); private.unique_name.replace(unique_name.to_string());
} }