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, #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)


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

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

#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



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

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)


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

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

#ambiguous_name?Boolean

operations with ambiguous name lookup due to multi inheritance

Returns:

  • (Boolean)


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

def ambiguous_name?
    !!@ambiguous_name
end

#attribute?Boolean

Returns:

  • (Boolean)


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

def attribute?
    false
end

#constructor?Boolean

Returns:

  • (Boolean)


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

def constructor?
    !@return_type
end

#generate_signaturesObject



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

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)


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

def inherit?
    @base_class != @owner
end

#instance_method?Boolean

Returns:

  • (Boolean)


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

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

#operatorObject



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

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

#operator?Boolean

Returns:

  • (Boolean)


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

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

#owner=(obj) ⇒ Object



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

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



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

def parameter(idx)
    @parameters[idx]
end

#pretty_print(pp) ⇒ Object



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

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

#static?Boolean

Returns:

  • (Boolean)


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

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

#valid_flagsObject



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

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