Class: Rbind::ROperation

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

Direct Known Subclasses

RCastOperation, RGetter, RSetter

Instance Attribute Summary collapse

Attributes included from Logger

#log

Attributes inherited from RBase

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

Instance Method Summary collapse

Methods included from Logger

extend_object

Methods inherited from RBase

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

Constructor Details

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

Returns a new instance of ROperation.



16
17
18
19
20
21
22
# File 'lib/rbind/core/roperation.rb', line 16

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

Instance Attribute Details

#ambiguous_nameObject

Returns the value of attribute ambiguous_name.



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

def ambiguous_name
  @ambiguous_name
end

#base_classObject

Returns the value of attribute base_class.



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

def base_class
  @base_class
end

#blockingObject

Returns the value of attribute blocking.



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

def blocking
  @blocking
end

#cparametersObject

Returns the value of attribute cparameters.



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

def cparameters
  @cparameters
end

#cplusplus_aliasObject

Returns the value of attribute cplusplus_alias.



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

def cplusplus_alias
  @cplusplus_alias
end

#indexObject

index if overloaded



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

def index
  @index
end

#parametersObject

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#return_typeObject

Returns the value of attribute return_type.



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

def return_type
  @return_type
end

#staticObject

Returns the value of attribute static.



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

def static
  @static
end

Instance Method Details

#==(other) ⇒ Object



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

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)


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

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

#add_parameter(para, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rbind/core/roperation.rb', line 34

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)


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

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)


158
159
160
# File 'lib/rbind/core/roperation.rb', line 158

def attribute?
    false
end

#blocking?Boolean

Returns:

  • (Boolean)


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

def blocking?
    !!@blocking
end

#constructor?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/rbind/core/roperation.rb', line 152

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)


26
27
28
# File 'lib/rbind/core/roperation.rb', line 26

def cplusplus_alias?
    !!@cplusplus_alias
end

#generate_docObject

generates documentation based on the method signature



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

def generate_doc

end

#generate_signaturesObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/rbind/core/roperation.rb', line 99

def generate_signatures
    ROperation.log.debug "ROperation: generate signature for #{return_type}: #{return_type.signature}" unless constructor?
    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)


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

def inherit?
    @base_class != @owner
end

#instance_method?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/rbind/core/roperation.rb', line 124

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

#operatorObject



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

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

#operator?Boolean

Returns:

  • (Boolean)


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

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

#owner=(obj) ⇒ Object



138
139
140
141
142
143
144
145
# File 'lib/rbind/core/roperation.rb', line 138

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

#parameter(idx) ⇒ Object



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

def parameter(idx)
    @parameters[idx]
end

#pretty_print(pp) ⇒ Object



162
163
164
165
166
167
168
# File 'lib/rbind/core/roperation.rb', line 162

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

#static?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/rbind/core/roperation.rb', line 89

def static?
    !instance_method?
end

#to_staticObject



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

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