Module: OroGen::Gen::RTT_CPP::OpaqueHandling
Overview
Common implementation of opaque-related methods. It gets included in Project and Typekit
Instance Method Summary collapse
-
#find_opaque_for_intermediate(type) ⇒ Type?
Finds the opaque (or opaque-containing) type for which the given type is an intermediate.
-
#intermediate_type?(type) ⇒ Boolean
Checks if a type is used as an intermediate.
-
#intermediate_type_for(type_def) ⇒ Type
Gets the intermediate type for a given type.
-
#intermediate_type_name_for(type_def, is_normalized = false) ⇒ String
Computes the name of the type that should be used as an intermediate for the given type.
-
#m_type?(type) ⇒ Boolean
Checks if a type is an oroGen-generated type used as an intermediate.
-
#opaque_specification(type_def) ⇒ OpaqueDefinition
Get the opaque definition for a given type.
Instance Method Details
#find_opaque_for_intermediate(type) ⇒ Type?
Finds the opaque (or opaque-containing) type for which the given type is an intermediate
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/orogen/gen/typekit.rb', line 390 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 |
#intermediate_type?(type) ⇒ Boolean
Checks if a type is used as an intermediate
462 463 464 |
# File 'lib/orogen/gen/typekit.rb', line 462 def intermediate_type?(type) !!find_opaque_for_intermediate(type) end |
#intermediate_type_for(type_def) ⇒ Type
Gets the intermediate type for a given type
456 457 458 459 |
# File 'lib/orogen/gen/typekit.rb', line 456 def intermediate_type_for(type_def) typename = intermediate_type_name_for(type_def) return find_type(typename, true) end |
#intermediate_type_name_for(type_def, is_normalized = false) ⇒ String
Computes the name of the type that should be used as an intermediate for the given type
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/orogen/gen/typekit.rb', line 429 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 |
#m_type?(type) ⇒ Boolean
Checks if a type is an oroGen-generated type used as an intermediate
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/orogen/gen/typekit.rb', line 468 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 |
#opaque_specification(type_def) ⇒ OpaqueDefinition
Get the opaque definition for a given type
374 375 376 377 378 379 380 381 382 383 |
# File 'lib/orogen/gen/typekit.rb', line 374 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 |