Class: Doxyparser::Function

Inherits:
Member show all
Defined in:
lib/nodes/function.rb

Overview

A C/C++ function with its parameters und return type

Instance Attribute Summary

Attributes inherited from Member

#args, #definition, #location, #params, #static, #type

Attributes inherited from Node

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

Instance Method Summary collapse

Methods inherited from Member

#file

Methods inherited from Node

#escaped_name, #initialize

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 Method Details

#==(another) ⇒ Object



56
57
58
59
# File 'lib/nodes/function.rb', line 56

def == another
  super
  self.args == another.args
end

#constructor?Boolean

Returns true if the function is a constructor of a Struct or Class.

Returns:

  • (Boolean)

    true if the function is a constructor of a Struct or Class



7
8
9
# File 'lib/nodes/function.rb', line 7

def constructor?
  @basename == parent.basename
end

#destructor?Boolean

Returns true if the function is a destructor of a Struct or Class.

Returns:

  • (Boolean)

    true if the function is a destructor of a Struct or Class



12
13
14
# File 'lib/nodes/function.rb', line 12

def destructor?
  @basename.start_with? %Q{~}
end

#eql?(another) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/nodes/function.rb', line 61

def eql?(another)
  super
  self.args == another.args
end

#getter_forString

Finds the name of the -hypothetical- property this method refers to in case this Doxyparser::Function complies with the ‘getter’ naming convention and has no parameters.

Getter examples for ‘myProperty’ are: getMyProperty, get_myProperty, GetMyProperty, Get_MyProperty, etc Getter examples for ‘booleanProp’ are: isBooleanProp, is_booleanProp, get_booleanProp, etc

Returns:

  • (String)

    name of the property



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nodes/function.rb', line 21

def getter_for    	
	return nil if @type.name == 'void'
	
  if @params.empty? || (@params.size == 1 && @params[0].type.name.strip == 'void')
    if @basename.start_with?('get') || @basename.start_with?('Get')
      ret = @basename.gsub(/^get[_]?(\w)/i) { |match| $1.downcase }
      ret.prepend('_') if ret =~ %r{^\d}
      return ret
    end
    if @type.name == 'bool'
      if @basename.start_with?('is') || @basename.start_with?('Is')
        ret = @basename.gsub(/^is[_]?(\w)/i) { |match| $1.downcase }
        ret.prepend('_') if ret =~ %r{^\d}
      	return ret
      end
    end
  end
  return nil
end

#setter_forString

with the ‘setter’ naming convention and has no return value (void).

Setter examples for ‘myProperty’ are: setMyProperty, set_myProperty, SetMyProperty, Set_MyProperty, etc

Returns:

  • (String)

    name of the property



45
46
47
48
49
50
51
52
53
54
# File 'lib/nodes/function.rb', line 45

def setter_for
  if (@type.name == 'void') && (@params.size == 1 && @params[0].type.name.strip != 'void')
    if @basename.start_with?('set') || @basename.start_with?('Set')
      ret = @basename.gsub(/^set[_]?(\w)/i) { |match| $1.downcase }
      ret.prepend('_') if ret =~ %r{^\d}
      return ret
    end
  end
  return nil
end

#to_sObject



70
71
72
# File 'lib/nodes/function.rb', line 70

def to_s
  super + @args
end

#to_strObject



66
67
68
# File 'lib/nodes/function.rb', line 66

def to_str
  super + @args
end