module OroGen::Gen::RTT_CPP::OpaqueHandling
Common implementation of opaque-related methods. It gets included in Project and Typekit
Public Instance Methods
Finds the opaque (or opaque-containing) type for which the given type is an intermediate
@return [Type,nil] the type, or nil if 'type' is not used as an
intermediate
# File lib/orogen/gen/typekit.rb, line 389 def find_opaque_for_intermediate(type) type = find_type(type.name) if m_type?(type) # Yuk begin if @intermediate_to_opaque && (result = @intermediate_to_opaque[type.name]) result elsif type.name =~ /_m$/ find_type(type.name.gsub(/_m$/, '')) else raise Typelib::NotFound end rescue Typelib::NotFound # This is a pretty expensive operation and is seldom # needed, so avoid doing it unnecessarily @intermediate_to_opaque ||= Hash.new @indexed_intermediates ||= Set.new registry.each do |t| if !@indexed_intermediates.include?(t) && t.contains_opaques? @indexed_intermediates << t @intermediate_to_opaque[intermediate_type_name_for(t)] = t end end @intermediate_to_opaque[type.name] end elsif opaque_def = opaques.find { |spec| find_type(spec.intermediate, true).eql? type } opaque_def.type end end
Checks if a type is used as an intermediate
# File lib/orogen/gen/typekit.rb, line 461 def intermediate_type?(type) !!find_opaque_for_intermediate(type) end
Gets the intermediate type for a given type
@param [Type,String] type_def the type or type name @return [Type] the type of the intermediate, or 'type_def' itself
if 'type_def' is not an opaque
@raises Typelib::NotFound if the expected intermediate type cannot
be found
# File lib/orogen/gen/typekit.rb, line 455 def intermediate_type_for(type_def) typename = intermediate_type_name_for(type_def) return find_type(typename, true) end
Computes the name of the type that should be used as an intermediate for the given type
@param [String,Type] type_def the type or type name @param [Boolean] is_normalized if true, the provided type name is
supposed to be normalized. Otherwise, an (expensive) normalization will be computed if it cannot be found as-is in the typekit's registry
@return [String] the normalized name of the intermediate type, or
the type's name if 'type' is not an opaque
# File lib/orogen/gen/typekit.rb, line 428 def intermediate_type_name_for(type_def, is_normalized = false) type = find_type(type_def, is_normalized) if type.opaque? opaque_specification(type_def).intermediate elsif type.contains_opaques? if type < Typelib::ArrayType "#{intermediate_type_name_for(type.deference)}[#{type.length}]" elsif type < Typelib::ContainerType "#{type.container_kind}<#{intermediate_type_name_for(type.deference)}>" else path = Typelib.split_typename(type.name) path.map! do |p| p.gsub(/[<>\[\], \/]/, '_') end "/" + path.join("/") + "_m" end else type.name end end
Checks if a type is an oroGen-generated type used as an intermediate
# File lib/orogen/gen/typekit.rb, line 467 def m_type?(type) typename = type.name if type.name =~ /_m$/ return true end if type.respond_to?(:deference) while type.respond_to?(:deference) type = type.deference end m_type?(type) else false end end
Get the opaque definition for a given type
@param [Type,String] the type or type name @return [OpaqueDefinition]
# File lib/orogen/gen/typekit.rb, line 373 def opaque_specification(type_def) type = find_type(type_def) raise "#{type} is unknown" unless type raise "#{type} is not opaque" unless type.opaque? if result = opaques.find { |opaque_def| opaque_def.type.eql? type } result else raise InternalError, "#{self}#opaque_specification called for type #{type.name}, but could not find the corresponding opaque specification" end end