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, #flags, #ignore, #name, #namespace, #owner, #signature, #version

Instance Method Summary collapse

Methods inherited from RBase

#add_flag, basename, #binding, #full_name, #ignore?, #map_to_namespace, namespace, #namespace?, normalize, to_cname, #validate_flags

Constructor Details

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

Returns a new instance of ROperation.

Raises:

  • (ArgumentError)


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

def initialize(name,return_type,*args)
    super(name)
    raise ArgumentError ,"wrong type #{return_type}" if return_type && !return_type.is_a?(RDataType)
    @return_type = return_type
    @parameters = args.flatten
    @parameters.each do |para|
        raise ArgumentError ,"wrong parameter type#{para}" if !para.is_a?(RParameter)
    end
    @cparameters = @parameters
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

#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

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/rbind/core/roperation.rb', line 22

def ==(other)
    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)


43
44
45
# File 'lib/rbind/core/roperation.rb', line 43

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

#ambiguous_name?Boolean

operations with ambiguous name lookup due to multi inheritance

Returns:

  • (Boolean)


48
49
50
# File 'lib/rbind/core/roperation.rb', line 48

def ambiguous_name?
    !!@ambiguous_name
end

#attribute?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/rbind/core/roperation.rb', line 117

def attribute?
    false
end

#constructor?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/rbind/core/roperation.rb', line 113

def constructor?
    !@return_type
end

#generate_signaturesObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rbind/core/roperation.rb', line 69

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_ptr.csignature
            end
        end
    paras = cparameters.map do |p|
        if p.type.basic_type?
            p.csignature
        else
            tp = p.to_ptr
            "#{tp.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)


32
33
34
# File 'lib/rbind/core/roperation.rb', line 32

def inherit?
    @base_class != @owner
end

#instance_method?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/rbind/core/roperation.rb', line 94

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

#operatorObject



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

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

#operator?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/rbind/core/roperation.rb', line 36

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

#owner=(obj) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rbind/core/roperation.rb', line 98

def owner=(obj)
    super
    @base_class ||=obj
    @cparameters = if instance_method?
                       p = RParameter.new("rbind_obj",obj,nil,:IO)
                       [p] +  @parameters
                   else
                       @parameters
                   end
    @parameters.each do |para|
        para.owner = self
    end
    self
end

#parameter(idx) ⇒ Object



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

def parameter(idx)
    @parameters[idx]
end

#pretty_print(pp) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/rbind/core/roperation.rb', line 121

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

#static?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/rbind/core/roperation.rb', line 65

def static?
    @flags.include?(:S)
end

#valid_flagsObject



61
62
63
# File 'lib/rbind/core/roperation.rb', line 61

def valid_flags
    super << :S << :explicit
end