class OroGen::Spec::ConfigurationObject
Representation of a task's attribute or property
Attributes
The property's default value
The property name
An operation that can be used to set the property. This is non-nil only for dynamic properties.
@return [Spec::Operation,nil]
The task on which this property is attached
The property type, as a Typelib::Type object from the underlying project's type registry
Public Class Methods
Create a new property with the given name, type and default value
# File lib/orogen/spec/configuration_object.rb, line 39 def initialize(task, name, type, default_value) name = name.to_s if name !~ /^\w+$/ raise ArgumentError, "property names need to be valid C++ identifiers, i.e. contain only alphanumeric characters and _ (got #{name})" end type = task.project.find_interface_type(type) OroGen.validate_toplevel_type(type) @dynamic = false @task, @name, @type, @default_value = task, name, type, default_value @setter_operation = nil @doc = nil end
Public Instance Methods
# File lib/orogen/spec/configuration_object.rb, line 53 def dynamic @setter_operation = task.find_operation("__orogen_set#{name.capitalize}") if !@setter_operation @setter_operation = task.operation("__orogen_set#{name.capitalize}"). returns("bool"). argument("value", type_name). doc("Dynamic Property setter of #{name}") end self end
If this property coudl be set Dynamic this returns true
# File lib/orogen/spec/configuration_object.rb, line 18 def dynamic?; !!@setter_operation end
# File lib/orogen/spec/configuration_object.rb, line 82 def each_interface_type return enum_for(__method__) if !block_given? yield type end
The type name as registered on RTT
# File lib/orogen/spec/configuration_object.rb, line 31 def orocos_type_name type.name end
# File lib/orogen/spec/configuration_object.rb, line 65 def pretty_print(pp) default = if value = self.default_value ", default: #{value}" end if doc first_line = true doc.split("\n").each do |line| pp.breakable if !first_line first_line = false pp.text "# #{line}" end pp.breakable end pp.text "#{name}:#{type.name}#{default}" end
Converts this model into a representation that can be fed to e.g. a JSON dump, that is a hash with pure ruby key / values.
The generated hash has the following keys:
name: the attribute name type: the type (as marshalled with Typelib::Type#to_h) dynamic: boolean value indicating whether this can be set dynamically or not doc: the documentation string default: the default value. Not present if there is none.
@return [Hash]
# File lib/orogen/spec/configuration_object.rb, line 107 def to_h result = Hash[ name: name, type: type.to_h, dynamic: !!dynamic?, doc: (doc || "")] if value = self.default_value if value.respond_to?(:to_simple_value) result[:default] = value.to_simple_value else result[:default] = value end end result end
The name of the type this property is using, for consistency with the
type attribute
# File lib/orogen/spec/configuration_object.rb, line 28 def type_name; type.name end