Class: Rbind::ROperation

Inherits:
RBase
  • Object
show all
Defined in:
lib/rbind/core/roperation.rb

Direct Known Subclasses

RGetter, RSetter

Instance Attribute Summary collapse

Attributes inherited from RBase

#alias, #auto_alias, #cname, #csignature, #doc, #extern_package_name, #ignore, #name, #namespace, #owner, #signature, #version

Instance Method Summary collapse

Methods inherited from RBase

basename, #binding, #delete!, #extern?, #full_name, #ignore?, #map_to_namespace, namespace, #namespace?, normalize, #rename, #specialize_ruby, split_name, to_cname, #to_s

Constructor Details

#initialize(name, return_type = nil, *args) ⇒ ROperation

Returns a new instance of ROperation.



13
14
15
16
17
18
# File 'lib/rbind/core/roperation.rb', line 13

def initialize(name,return_type=nil,*args)
    super(name)
    @return_type = return_type
    @parameters = args.flatten
    @cplusplus_alias = true
end

Instance Attribute Details

#ambiguous_nameObject

Returns the value of attribute ambiguous_name.



8
9
10
# File 'lib/rbind/core/roperation.rb', line 8

def ambiguous_name
  @ambiguous_name
end

#base_classObject

Returns the value of attribute base_class.



7
8
9
# File 'lib/rbind/core/roperation.rb', line 7

def base_class
  @base_class
end

#cparametersObject

Returns the value of attribute cparameters.



6
7
8
# File 'lib/rbind/core/roperation.rb', line 6

def cparameters
  @cparameters
end

#cplusplus_aliasObject

Returns the value of attribute cplusplus_alias.



11
12
13
# File 'lib/rbind/core/roperation.rb', line 11

def cplusplus_alias
  @cplusplus_alias
end

#indexObject

index if overloaded



9
10
11
# File 'lib/rbind/core/roperation.rb', line 9

def index
  @index
end

#parametersObject

Returns the value of attribute parameters.



5
6
7
# File 'lib/rbind/core/roperation.rb', line 5

def parameters
  @parameters
end

#return_typeObject

Returns the value of attribute return_type.



4
5
6
# File 'lib/rbind/core/roperation.rb', line 4

def return_type
  @return_type
end

#staticObject

Returns the value of attribute static.



10
11
12
# File 'lib/rbind/core/roperation.rb', line 10

def static
  @static
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/rbind/core/roperation.rb', line 41

def ==(other)
    return false if other.class != self.class
    return false unless name == other.name
    @parameters.each_with_index do |p,i|
        return false if p != other.parameters[i]
    end
    true
end

#abstract?Boolean

for now returns true if the owner class has no constructor

Returns:

  • (Boolean)


63
64
65
# File 'lib/rbind/core/roperation.rb', line 63

def abstract?
    !base_class.operation(base_class.name,false)
end

#add_parameter(para, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rbind/core/roperation.rb', line 26

def add_parameter(para,&block)
    para = if para.is_a? String
        raise "No owner. Cannot create parameter" unless owner
        para = RParameter.new(para,owner.void)
        owner.instance_exec(para,&block) if block
        para
    else
        para
    end
    if @parameters.find{|p| p.name == para.name}
        raise RuntimeError,"duplicate parameter name #{para}"
    end
    @parameters << para
end

#ambiguous_name?Boolean

operations with ambiguous name lookup due to multi inheritance

Returns:

  • (Boolean)


68
69
70
# File 'lib/rbind/core/roperation.rb', line 68

def ambiguous_name?
    !!@ambiguous_name
end

#attribute?Boolean

returns true if the method is a setter or getter generated for a class attribute

Returns:

  • (Boolean)


149
150
151
# File 'lib/rbind/core/roperation.rb', line 149

def attribute?
    false
end

#constructor?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/rbind/core/roperation.rb', line 143

def constructor?
    !@return_type
end

#cplusplus_alias?Boolean

indicates if an alias method shall be added having the same name style like the c++ method

Returns:

  • (Boolean)


22
23
24
# File 'lib/rbind/core/roperation.rb', line 22

def cplusplus_alias?
    !!@cplusplus_alias
end

#generate_docObject

generates documentation based on the method signature



139
140
141
# File 'lib/rbind/core/roperation.rb', line 139

def generate_doc

end

#generate_signaturesObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rbind/core/roperation.rb', line 91

def generate_signatures
    s = "#{return_type.signature} " unless constructor?
    s = "#{s}#{full_name}(#{parameters.map(&:signature).join(", ")})"

    cs = if constructor?
            owner.to_ptr.csignature if owner
        else
            if return_type.basic_type?
                return_type.csignature
            else
                return_type.to_single_ptr.csignature
            end
        end
    paras = cparameters.map do |p|
        if p.type.basic_type?
            p.csignature
        else
            p.to_single_ptr.csignature
        end
    end.join(", ")
    cs = "#{cs} #{cname}(#{paras})"
    [s,cs]
end

#inherit?Boolean

returns true if the operations is in inherit from one of the base classes

Returns:

  • (Boolean)


52
53
54
# File 'lib/rbind/core/roperation.rb', line 52

def inherit?
    @base_class != @owner
end

#instance_method?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/rbind/core/roperation.rb', line 115

def instance_method?
    owner.is_a?(RClass) && !constructor? && !@static
end

#operatorObject



72
73
74
75
# File 'lib/rbind/core/roperation.rb', line 72

def operator
    name =~ /operator ?(.*)/
    $1
end

#operator?Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/rbind/core/roperation.rb', line 56

def operator?
    op = operator
    op && op != '[]' && op != '()'
end

#owner=(obj) ⇒ Object



129
130
131
132
133
134
135
136
# File 'lib/rbind/core/roperation.rb', line 129

def owner=(obj)
    super
    @base_class ||=obj
    @parameters.each do |para|
        para.owner = self
    end
    self
end

#parameter(idx) ⇒ Object



77
78
79
# File 'lib/rbind/core/roperation.rb', line 77

def parameter(idx)
    @parameters[idx]
end

#pretty_print(pp) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/rbind/core/roperation.rb', line 153

def pretty_print(pp)
    if cname
        pp.text "#{signature} --> #{cname}"
    else
        pp.text signature
    end
end

#static?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/rbind/core/roperation.rb', line 81

def static?
    !instance_method?
end

#to_staticObject



85
86
87
88
89
# File 'lib/rbind/core/roperation.rb', line 85

def to_static
    op = self.dup
    op.static = true
    op
end