Class: FFIDB::Type
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Integer
- #array? ⇒ Boolean
- #array_pointer? ⇒ Boolean
- #array_size ⇒ Integer
- #array_type ⇒ Type
- #atomic? ⇒ Boolean
- #bool? ⇒ Boolean
- #const_qualified? ⇒ Boolean
- #enum? ⇒ Boolean
- #enum_pointer? ⇒ Boolean
- #floating_point? ⇒ Boolean
- #function_pointer? ⇒ Boolean
-
#initialize(spec) ⇒ Type
constructor
A new instance of Type.
- #inspect ⇒ String
- #integer? ⇒ Boolean
- #name ⇒ Symbol
- #pointer? ⇒ Boolean
- #signed_integer? ⇒ Boolean
- #struct? ⇒ Boolean
- #struct_pointer? ⇒ Boolean
- #tag ⇒ Symbol
- #to_h ⇒ Hash<Symbol, Object>
- #to_s ⇒ String
- #union? ⇒ Boolean
- #union_pointer? ⇒ Boolean
- #unsigned_integer? ⇒ Boolean
- #void? ⇒ Boolean
Constructor Details
#initialize(spec) ⇒ Type
Returns a new instance of Type.
17 18 19 |
# File 'lib/ffidb/type.rb', line 17 def initialize(spec) super(spec.to_s) end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Integer
24 |
# File 'lib/ffidb/type.rb', line 24 def <=>(other) self.spec <=> other.spec end |
#array? ⇒ Boolean
137 138 139 |
# File 'lib/ffidb/type.rb', line 137 def array? self.spec.include?('[') end |
#array_pointer? ⇒ Boolean
172 173 174 |
# File 'lib/ffidb/type.rb', line 172 def array_pointer? self.spec.end_with?('[]') end |
#array_size ⇒ Integer
151 152 153 154 155 |
# File 'lib/ffidb/type.rb', line 151 def array_size if self.array? (/\[([^\]]+)\]/ =~ self.spec) && $1.to_i end end |
#array_type ⇒ Type
143 144 145 146 147 |
# File 'lib/ffidb/type.rb', line 143 def array_type if self.array? self.class.for(self.spec.gsub(/\s+(\[[^\]]+\])/, '')) end end |
#atomic? ⇒ Boolean
51 52 53 |
# File 'lib/ffidb/type.rb', line 51 def atomic? self.bool? || self.integer? || self.floating_point? || self.pointer? || nil # TODO end |
#bool? ⇒ Boolean
63 64 65 |
# File 'lib/ffidb/type.rb', line 63 def bool? self.spec == '_Bool' end |
#const_qualified? ⇒ Boolean
45 46 47 |
# File 'lib/ffidb/type.rb', line 45 def const_qualified? self.spec.start_with?('const ') end |
#enum? ⇒ Boolean
69 70 71 |
# File 'lib/ffidb/type.rb', line 69 def enum? !(self.pointer?) && (self.spec == 'enum' || self.spec.start_with?('enum ')) end |
#enum_pointer? ⇒ Boolean
178 179 180 |
# File 'lib/ffidb/type.rb', line 178 def enum_pointer? self.pointer? && self.spec.start_with?('enum ') end |
#floating_point? ⇒ Boolean
128 129 130 131 132 133 |
# File 'lib/ffidb/type.rb', line 128 def floating_point? case self.spec when 'float', 'double', 'long double' then true else false end end |
#function_pointer? ⇒ Boolean
196 197 198 |
# File 'lib/ffidb/type.rb', line 196 def function_pointer? self.spec.include?('(*)') end |
#inspect ⇒ String
214 215 216 |
# File 'lib/ffidb/type.rb', line 214 def inspect "#{self.class}(#{self.spec.inspect})" end |
#integer? ⇒ Boolean
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ffidb/type.rb', line 87 def integer? case self.spec when 'char', 'short', 'int', 'long', 'long long' then true when 'unsigned char', 'unsigned short', 'unsigned int', 'unsigned long', 'unsigned long long' then true when 'size_t', 'wchar_t' then true # <stddef.h> when 'ssize_t', 'off_t' then true # <sys/types.h> when /^u?int\d+_t$/ then true else false end end |
#name ⇒ Symbol
39 40 41 |
# File 'lib/ffidb/type.rb', line 39 def name self.spec.gsub(/\s*\*+$/, '').to_sym # TODO end |
#pointer? ⇒ Boolean
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ffidb/type.rb', line 159 def pointer? self.spec.end_with?('*') || self.array_pointer? || self.function_pointer? || case self.spec when 'intptr_t', 'uintptr_t' then true when 'va_list' then true else false end end |
#signed_integer? ⇒ Boolean
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ffidb/type.rb', line 100 def signed_integer? return false unless self.integer? case self.spec when 'char', 'short', 'int', 'long', 'long long' then true when 'wchar_t' then nil # <stddef.h> when 'ssize_t' then true # <sys/types.h> when /^int\d+_t$/ then true else false end end |
#struct? ⇒ Boolean
75 76 77 |
# File 'lib/ffidb/type.rb', line 75 def struct? !(self.pointer?) && (self.spec == 'struct' || self.spec.start_with?('struct ') || self.spec.start_with?('const struct ')) end |
#struct_pointer? ⇒ Boolean
184 185 186 |
# File 'lib/ffidb/type.rb', line 184 def struct_pointer? self.pointer? && (self.spec.start_with?('struct ') || self.spec.start_with?('const struct ')) end |
#tag ⇒ Symbol
28 29 30 31 32 33 34 35 |
# File 'lib/ffidb/type.rb', line 28 def tag case self.spec.gsub(/^const /, '') when 'enum', /^enum\s+/ then :enum when 'struct', /^struct\s+/ then :struct when 'union', /^union\s+/ then :union else nil end end |
#to_h ⇒ Hash<Symbol, Object>
208 209 210 |
# File 'lib/ffidb/type.rb', line 208 def to_h {spec: self.spec} end |
#to_s ⇒ String
202 203 204 |
# File 'lib/ffidb/type.rb', line 202 def to_s self.spec end |
#union? ⇒ Boolean
81 82 83 |
# File 'lib/ffidb/type.rb', line 81 def union? !(self.pointer?) && (self.spec.start_with?('union ') || self.spec.start_with?('const union ')) end |
#union_pointer? ⇒ Boolean
190 191 192 |
# File 'lib/ffidb/type.rb', line 190 def union_pointer? self.pointer? && (self.spec.start_with?('union ') || self.spec.start_with?('const union ')) end |
#unsigned_integer? ⇒ Boolean
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ffidb/type.rb', line 113 def unsigned_integer? return false unless self.integer? return true if self.spec.start_with?('u') case self.spec when 'unsigned char', 'unsigned short', 'unsigned int', 'unsigned long', 'unsigned long long' then true when 'size_t' then true # <stddef.h> when 'wchar_t' then nil # <stddef.h> when 'off_t' then true # <sys/types.h> when /^uint\d+_t$/ then true else false end end |
#void? ⇒ Boolean
57 58 59 |
# File 'lib/ffidb/type.rb', line 57 def void? self.spec == 'void' end |