Class: Rubex::DataType::CPtr
- Inherits:
-
Object
- Object
- Rubex::DataType::CPtr
show all
- Includes:
- Helpers
- Defined in:
- lib/rubex/data_type/c_ptr.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
The data type that this pointer is pointing to.
Instance Method Summary
collapse
Methods included from Helpers
#==, #c_function_ptr?, #char_ptr?
Constructor Details
#initialize(type) ⇒ CPtr
Returns a new instance of CPtr.
8
9
10
|
# File 'lib/rubex/data_type/c_ptr.rb', line 8
def initialize(type)
@type = type
end
|
Instance Attribute Details
#type ⇒ Object
The data type that this pointer is pointing to.
6
7
8
|
# File 'lib/rubex/data_type/c_ptr.rb', line 6
def type
@type
end
|
Instance Method Details
#<=>(_other) ⇒ Object
66
67
68
|
# File 'lib/rubex/data_type/c_ptr.rb', line 66
def <=>(_other)
-1
end
|
#base_type ⇒ Object
39
40
41
42
|
# File 'lib/rubex/data_type/c_ptr.rb', line 39
def base_type
return @type unless @type.is_a?(self.class)
@type.base_type
end
|
16
17
18
|
# File 'lib/rubex/data_type/c_ptr.rb', line 16
def cptr?
true
end
|
#from_ruby_object(arg) ⇒ Object
from a Ruby function get a pointer to some value.
56
57
58
59
|
# File 'lib/rubex/data_type/c_ptr.rb', line 56
def from_ruby_object(arg)
return "StringValueCStr(#{arg})" if @type.char?
arg
end
|
12
13
14
|
# File 'lib/rubex/data_type/c_ptr.rb', line 12
def p_formatter
'%s' if char_ptr?
end
|
#ptr_level ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/rubex/data_type/c_ptr.rb', line 44
def ptr_level
temp = @type
ptr = '*'
while temp.cptr?
ptr << '*'
temp = @type.type
end
ptr
end
|
#to_ruby_object(arg) ⇒ Object
61
62
63
64
|
# File 'lib/rubex/data_type/c_ptr.rb', line 61
def to_ruby_object(arg)
return "rb_str_new2(#{arg})" if @type.char?
arg
end
|
#to_s ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/rubex/data_type/c_ptr.rb', line 20
def to_s
base_type = @type.base_type
if base_type.c_function?
ptr = ptr_level
str = "#{base_type.type} (#{ptr} #{base_type.c_name})"
str << '(' + base_type.arg_list.map { |e| e.type.to_s }.join(',') + ')'
else
t = @type
str = '*'
if t.cptr?
str << '*'
t = t.type
end
str.prepend t.to_s
str
end
end
|