Class: Doxyparser::Type

Inherits:
Node
  • Object
show all
Defined in:
lib/nodes/type.rb

Overview

Type of the parameters and return value of a Function. Parent Type of a Class or Struct. Supports type parameters (aka. generics)

Instance Attribute Summary collapse

Attributes inherited from Node

#basename, #dir, #doc, #name, #node, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#==, #eql?, #initialize, #to_s, #to_str

Methods included from Util

#del_prefix_class, #del_prefix_file, #del_spaces, #do_filter, #escape_all, #escape_class_name, #escape_const_ref_ptr, escape_const_ref_ptr, #escape_file_name, #escape_template, home_dir, #match, read_file, write_file

Constructor Details

This class inherits a constructor from Doxyparser::Node

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Doxyparser::Node

Instance Attribute Details

#escaped_nameObject (readonly)

Name of this Doxyparser::Type without any reference/pointer symbols ‘* &’ or ‘const’ modifiers



8
9
10
# File 'lib/nodes/type.rb', line 8

def escaped_name
  @escaped_name
end

Class Method Details

.nested_typenames(typename) ⇒ Array<String>

Returns the names for types nested in the parameter.

	The 'main' type is always included, so for templates two or more names will be returned.

Example: for mymap<std::string, MyClass, 4> the result is: [mymap, std::string, MyClass]

Parameters:

  • typename (String)

    Type name

Returns:

  • (Array<String>)

    Names of nested types



36
37
38
39
40
41
42
43
# File 'lib/nodes/type.rb', line 36

def self.nested_typenames(typename)
	escaped_typename = Doxyparser::Util.escape_const_ref_ptr(typename)
  escaped_typename.split(%r{[<,>]}).map{ |s|
  	 Doxyparser::Util.escape_const_ref_ptr(s)
  }.reject { |s| 
  		s.nil? || !valid_type?(s) 
  }
end

.template?(typename) ⇒ Boolean

Returns true if the given type name has type parameters, false otherwise.

Parameters:

  • typename (String)

    Type name

Returns:

  • (Boolean)

    true if the given type name has type parameters, false otherwise



52
53
54
# File 'lib/nodes/type.rb', line 52

def self.template?(typename)
  typename.include? '<'
end

Instance Method Details

#name=(new_name) ⇒ Object

Setter for the name of this Doxyparser::Type. Use at your own risk!



57
58
59
60
61
# File 'lib/nodes/type.rb', line 57

def name=(new_name)
	@name = new_name
	@escaped_name = escape_const_ref_ptr(@name)
  @basename = del_prefix_class(escape_template(@escaped_name))
end

#nested_local_typesArray<Type>

If this Doxyparser::Type has type parameters (aka. template params) finds nested Doxyparser::Types

  for other {Class}es or {Struct}s parsed by Doxyparser.
	The 'main' type is always included, so for templates two or more types will be returned.

Example: for MyNamespace::map<std::string, MyClass> the result is: [MyNamespace::map, MyNamespace::MyClass]

Returns:

  • (Array<Type>)

    Nested types



15
16
17
18
19
20
# File 'lib/nodes/type.rb', line 15

def nested_local_types
  return [] if @node.nil?
  refs = @node.xpath("ref")
  return [] if refs.nil? || refs.empty?
  refs.map { |r| Type.new(node: r, dir: @dir) }
end

#nested_typenamesArray<String>

If this Doxyparser::Type has type parameters (aka. template params), returns the names for types nested in this type’s name

	The 'main' type is always included, so for templates two or more names will be returned.

Example: for MyNamespace::map<std::string, MyClass, 4> the result is: [MyNamespace::map, std::string, MyClass]

Returns:

  • (Array<String>)

    Names of nested types



27
28
29
# File 'lib/nodes/type.rb', line 27

def nested_typenames
  Type.nested_typenames(@escaped_name)
end

#template?Boolean

Returns true if this type has type parameters, false otherwise.

Returns:

  • (Boolean)

    true if this type has type parameters, false otherwise



46
47
48
# File 'lib/nodes/type.rb', line 46

def template?
  Type.template?(@escaped_name)
end