Class: Rbind::RTypeAnnotation

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rbind/core/rtype_annotation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, options = Hash.new) ⇒ RTypeAnnotation

Returns a new instance of RTypeAnnotation.



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

def initialize(type,options=Hash.new)
    super(type)
    @options = options
end

Instance Attribute Details

#constObject

Returns the value of attribute const.



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

def const
  @const
end

Instance Method Details

#const?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/rbind/core/rtype_annotation.rb', line 32

def const?
    if @options.has_key? :const
        !!@options[:const]
    else
        super
    end
end

#csignature(sig = nil) ⇒ Object



119
120
121
# File 'lib/rbind/core/rtype_annotation.rb', line 119

def csignature(sig=nil)
    generate_signatures[1]
end

#generate_signaturesObject



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/rbind/core/rtype_annotation.rb', line 123

def generate_signatures
    str_pre = ""
    str_post = ""

    str_pre = "const " if const?
    str_post += "&" if ref?
    str_post += "*" * @options[:ptr] if ptr?
    __getobj__.generate_signatures.map do |s|
        str_pre + s + str_post
    end
end

#ownership?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
# File 'lib/rbind/core/rtype_annotation.rb', line 48

def ownership?
    if @options.has_key? :ownership
        !!@options[:ownership]
    else
        super
    end
end

#ptr?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
# File 'lib/rbind/core/rtype_annotation.rb', line 77

def ptr?
    if @options.has_key? :ptr
        @options[:ptr] != 0
    else
        super
    end
end

#raw?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/rbind/core/rtype_annotation.rb', line 111

def raw?
    false
end

#ref?Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
# File 'lib/rbind/core/rtype_annotation.rb', line 99

def ref?
    if @options.has_key? :ref
        !!@options[:ref]
    else
        super
    end
end

#remove_annotation(key) ⇒ Object



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

def remove_annotation(key)
    opt = @options.clone
    opt.delete(key)
    if opt.empty?
        __getobj__
    else
        RTypeAnnotation.new(__getobj__,opt)
    end
end

#remove_constObject



44
45
46
# File 'lib/rbind/core/rtype_annotation.rb', line 44

def remove_const
    remove_annotation(:const)
end

#remove_ownershipObject



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

def remove_ownership
    remove_annotation(:ownership)
end

#remove_ptrObject



85
86
87
88
89
90
91
92
93
# File 'lib/rbind/core/rtype_annotation.rb', line 85

def remove_ptr
    return self if !ptr?
    val = @options[:ptr]-1
    if val == 0
        remove_annotation(:ptr)
    else
        to_annotation(:ptr,val)
    end
end

#remove_refObject



107
108
109
# File 'lib/rbind/core/rtype_annotation.rb', line 107

def remove_ref
    remove_annotation :ref
end

#signature(sig = nil) ⇒ Object



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

def signature(sig=nil)
    generate_signatures[0]
end

#to_annotation(key, val) ⇒ Object



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

def to_annotation(key,val)
    if @options.has_key?(key) && @options[key] == val
        self
    else
        opt = @options.clone
        opt[key] = val
        RTypeAnnotation.new(__getobj__,opt)
    end
end

#to_constObject



40
41
42
# File 'lib/rbind/core/rtype_annotation.rb', line 40

def to_const
    to_annotation(:const,true)
end

#to_ownership(val = true) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/rbind/core/rtype_annotation.rb', line 56

def to_ownership(val=true)
    if ptr?
        to_annotation(:ownership,val)
    else
        super
    end
end

#to_ptrObject



68
69
70
71
72
73
74
75
# File 'lib/rbind/core/rtype_annotation.rb', line 68

def to_ptr
    val = if ptr?
              @options[:ptr]+1
            else
                1
            end
    to_annotation(:ptr,val)
end

#to_refObject



95
96
97
# File 'lib/rbind/core/rtype_annotation.rb', line 95

def to_ref
    to_annotation :ref,true
end