Module: Orocos::PortsSearchable
- Included in:
- Log::Replay, TaskContextBase
- Defined in:
- lib/orocos/ports_searchable.rb
Overview
The PortsSearchable mixin provides collection classes with several methods for searching ports.
The class must provide a method port which must return an array of all avalilable Port instances
Instance Method Summary collapse
-
#find_all_input_ports(type, port_name) ⇒ Object
Searches for an input port object that matches the type and name specification.
-
#find_all_output_ports(type, port_name) ⇒ Object
Searches for an output object in that matches the type and name specification.
-
#find_all_ports(type, port_name = nil) ⇒ Object
Searches for a port object that matches the type and name specification.
-
#find_input_port(type, port_name = nil) ⇒ Object
Searches for a input port object that matches the type and name specification.
-
#find_output_port(type, port_name = nil) ⇒ Object
Searches for an output port object that matches the type and name specification.
-
#find_port(type, port_name = nil) ⇒ Object
Searches for a port object that matches the type and name specification.
Instance Method Details
#find_all_input_ports(type, port_name) ⇒ Object
Searches for an input port object that matches the type and name
specification. type
is either a string or a Typelib::Type
class, port_name
is either a string or a regular expression.
This is a helper method used in various places
38 39 40 |
# File 'lib/orocos/ports_searchable.rb', line 38 def find_all_input_ports(type, port_name) find_all_ports(type,port_name).delete_if { |port| !port.respond_to?(:writer) } end |
#find_all_output_ports(type, port_name) ⇒ Object
Searches for an output object in that matches the type and name
specification. type
is either a string or a Typelib::Type
class, port_name
is either a string or a regular expression.
This is a helper method used in various places
47 48 49 |
# File 'lib/orocos/ports_searchable.rb', line 47 def find_all_output_ports(type, port_name) find_all_ports(type,port_name).delete_if { |port| !port.respond_to?(:reader) } end |
#find_all_ports(type, port_name = nil) ⇒ Object
Searches for a port object that matches the type and name specification.
type
is either a string or a Typelib::Type class,
port_name
is either a string or a regular expression.
This is a helper method used in various places
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/orocos/ports_searchable.rb', line 13 def find_all_ports(type, port_name=nil) candidates = ports.dup # Filter out on type if type type_name = if !type.respond_to?(:to_str) type.name else type.to_str end candidates.delete_if { |port| port.type.name != type_name } end # Filter out on name if port_name candidates.delete_if { |port| !(port_name === port.name) } end candidates end |
#find_input_port(type, port_name = nil) ⇒ Object
Searches for a input port object that matches the type and name
specification. type
is either a string or a Typelib::Type
class, port_name
is either a string or a regular expression.
This is a helper method used in various places
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/orocos/ports_searchable.rb', line 78 def find_input_port(type, port_name=nil) candidates = find_all_input_ports(type, port_name) if candidates.size > 1 type_name = if !type.respond_to?(:to_str) type.name else type.to_str end if port_name raise ArgumentError, "#{type_name} is provided by multiple input ports #{port_name}: #{candidates.map(&:name).join(", ")}" else raise ArgumentError, "#{type_name} is provided by multiple input ports: #{candidates.map(&:name).join(", ")}" end else candidates.first end end |
#find_output_port(type, port_name = nil) ⇒ Object
Searches for an output port object that matches the type and name
specification. type
is either a string or a Typelib::Type
class, port_name
is either a string or a regular expression.
This is a helper method used in various places
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/orocos/ports_searchable.rb', line 99 def find_output_port(type, port_name=nil) candidates = find_all_output_ports(type, port_name) if candidates.size > 1 type_name = if !type.respond_to?(:to_str) type.name else type.to_str end if port_name raise ArgumentError, "#{type_name} is provided by multiple output ports #{port_name}: #{candidates.map(&:name).join(", ")}" else raise ArgumentError, "#{type_name} is provided by multiple output ports: #{candidates.map(&:name).join(", ")}" end else candidates.first end end |
#find_port(type, port_name = nil) ⇒ Object
Searches for a port object that matches the type and name specification.
type
is either a string or a Typelib::Type class,
port_name
is either a string or a regular expression.
This is a helper method used in various places
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/orocos/ports_searchable.rb', line 56 def find_port(type, port_name=nil) candidates = find_all_ports(type, port_name) if candidates.size > 1 type_name = if !type.respond_to?(:to_str) type.name else type.to_str end if port_name raise ArgumentError, "#{type_name} is provided by multiple ports #{port_name}: #{candidates.map(&:name).join(", ")}" else raise ArgumentError, "#{type_name} is provided by multiple ports: #{candidates.map(&:name).join(", ")}" end else candidates.first end end |