Parent

FFI::Struct

Public Class Methods

align() click to toggle source
     # File lib/ffi/struct.rb, line 117
117:     def self.align
118:       @layout.alignment
119:     end
alignment() click to toggle source
     # File lib/ffi/struct.rb, line 113
113:     def self.alignment
114:       @layout.alignment
115:     end
by_value() click to toggle source
     # File lib/ffi/struct.rb, line 141
141:     def self.by_value
142:       ::FFI::StructByValue.new(self)
143:     end
in() click to toggle source
     # File lib/ffi/struct.rb, line 133
133:     def self.in
134:       :buffer_in
135:     end
layout(*spec) click to toggle source
     # File lib/ffi/struct.rb, line 150
150:       def layout(*spec)
151:         return @layout if spec.size == 0
152: 
153:         builder = FFI::StructLayoutBuilder.new
154:         builder.union = self < Union
155:         if spec[0].kind_of?(Hash)
156:           hash_layout(builder, spec)
157:         else
158:           array_layout(builder, spec)
159:         end
160:         builder.size = @size if defined?(@size) && @size > builder.size
161:         cspec = builder.build
162:         @layout = cspec unless self == FFI::Struct
163:         @size = cspec.size
164:         return cspec
165:       end
members() click to toggle source
     # File lib/ffi/struct.rb, line 121
121:     def self.members
122:       @layout.members
123:     end
offset_of(name) click to toggle source
     # File lib/ffi/struct.rb, line 129
129:     def self.offset_of(name)
130:       @layout.offset_of(name)
131:     end
offsets() click to toggle source
     # File lib/ffi/struct.rb, line 125
125:     def self.offsets
126:       @layout.offsets
127:     end
out() click to toggle source
     # File lib/ffi/struct.rb, line 137
137:     def self.out
138:       :buffer_out
139:     end
size() click to toggle source
     # File lib/ffi/struct.rb, line 104
104:     def self.size
105:       defined?(@layout) ? @layout.size : defined?(@size) ? @size : 0
106:     end
size=(size) click to toggle source
     # File lib/ffi/struct.rb, line 108
108:     def self.size=(size)
109:       raise ArgumentError, "Size already set" if defined?(@size) || defined?(@layout)
110:       @size = size
111:     end

Protected Class Methods

callback(params, ret) click to toggle source
     # File lib/ffi/struct.rb, line 170
170:       def callback(params, ret)
171:         mod = enclosing_module
172:         FFI::CallbackInfo.new(find_type(ret, mod), params.map { |e| find_type(e, mod) })
173:       end
enclosing_module() click to toggle source
     # File lib/ffi/struct.rb, line 176
176:       def enclosing_module
177:         begin
178:           mod = self.name.split("::")[0..2].inject(Object) { |obj, c| obj.const_get(c) }
179:           mod.respond_to?(:find_type) ? mod : nil
180:         rescue Exception => ex
181:           nil
182:         end
183:       end
find_type(type, mod = nil) click to toggle source
     # File lib/ffi/struct.rb, line 185
185:       def find_type(type, mod = nil)
186:         if type.kind_of?(Class) && type < FFI::Struct
187:           FFI::Type::Struct.new(type)
188:         elsif type.is_a?(::Array)
189:           type
190:         elsif mod
191:           mod.find_type(type)
192:         end || FFI.find_type(type)
193:       end

Private Class Methods

array_layout(builder, spec) click to toggle source
     # File lib/ffi/struct.rb, line 212
212:       def array_layout(builder, spec)
213:         mod = enclosing_module
214:         i = 0
215:         while i < spec.size
216:           name, type = spec[i, 2]
217:           i += 2
218: 
219:           # If the next param is a Integer, it specifies the offset
220:           if spec[i].kind_of?(Integer)
221:             offset = spec[i]
222:             i += 1
223:           else
224:             offset = nil
225:           end
226:           if type.kind_of?(Class) && type < Struct
227:             builder.add_struct(name, type, offset)
228:           elsif type.kind_of?(::Array)
229:             builder.add_array(name, find_type(type[0], mod), type[1], offset)
230:           else
231:             builder.add_field(name, find_type(type, mod), offset)
232:           end
233:         end
234:       end
hash_layout(builder, spec) click to toggle source
     # File lib/ffi/struct.rb, line 198
198:       def hash_layout(builder, spec)
199:         raise "Ruby version not supported" if RUBY_VERSION =~ /1.8.*/
200:         mod = enclosing_module
201:         spec[0].each do |name,type|
202:           if type.kind_of?(Class) && type < Struct
203:             builder.add_struct(name, type)
204:           elsif type.kind_of?(::Array)
205:             builder.add_array(name, find_type(type[0], mod), type[1])
206:           else
207:             builder.add_field(name, find_type(type, mod))
208:           end
209:         end
210:       end

Public Instance Methods

align() click to toggle source
Alias for: alignment
alignment() click to toggle source
    # File lib/ffi/struct.rb, line 74
74:     def alignment
75:       self.class.alignment
76:     end
Also aliased as: align
clear() click to toggle source
    # File lib/ffi/struct.rb, line 95
95:     def clear
96:       pointer.clear
97:       self
98:     end
members() click to toggle source
    # File lib/ffi/struct.rb, line 83
83:     def members
84:       self.class.members
85:     end
offset_of(name) click to toggle source
    # File lib/ffi/struct.rb, line 79
79:     def offset_of(name)
80:       self.class.offset_of(name)
81:     end
offsets() click to toggle source
    # File lib/ffi/struct.rb, line 91
91:     def offsets
92:       self.class.offsets
93:     end
size() click to toggle source
    # File lib/ffi/struct.rb, line 70
70:     def size
71:       self.class.size
72:     end
to_ptr() click to toggle source
     # File lib/ffi/struct.rb, line 100
100:     def to_ptr
101:       pointer
102:     end
values() click to toggle source
    # File lib/ffi/struct.rb, line 87
87:     def values
88:       members.map { |m| self[m] }
89:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.