Object
Build a {StructLayout struct layout}.
List of number types
@param [String, Symbol] name name of the field @param [Array, DataConverter, Struct, StructLayout::Field, Symbol, Type] type type of the field @param [Numeric, nil] offset @return [self] Add a field to the builder. @note Setting offset to nil or -1 is equivalent to 0.
# File lib/ffi/struct_layout_builder.rb, line 107 def add(name, type, offset = nil) if offset.nil? || offset == -1 offset = @union ? 0 : align(@size, @packed ? [ @packed, type.alignment ].min : [ @min_alignment, type.alignment ].max) end # # If a FFI::Type type was passed in as the field arg, try and convert to a StructLayout::Field instance # field = type.is_a?(StructLayout::Field) ? type : field_for_type(name, offset, type) @fields << field @alignment = [ @alignment, field.alignment ].max unless @packed @size = [ @size, field.size + (@union ? 0 : field.offset) ].max return self end
@param name (see add) @param type (see add) @param [Numeric] count array length @param offset (see add) @return (see add) Add an array as a field to the builder.
# File lib/ffi/struct_layout_builder.rb, line 145 def add_array(name, type, count, offset = nil) add(name, Type::Array.new(type, count), offset) end
@param [Numeric] alignment Set alignment attribute with alignment only if it is greater than attribute value.
# File lib/ffi/struct_layout_builder.rb, line 45 def alignment=(align) @alignment = align if align > @alignment @min_alignment = align end
@return [StructLayout] Build and return the struct layout.
# File lib/ffi/struct_layout_builder.rb, line 151 def build # Add tail padding if the struct is not packed size = @packed ? @size : align(@size, @alignment) layout = StructLayout.new(@fields, size, @alignment) layout.__union! if @union layout end
Set packed attribute @overload packed=(packed)
@param [Fixnum] packed @return [packed] Set alignment and packed attributes to +packed+.
@overload packed=(packed)
@param packed @return [0,1] Set packed attribute.
# File lib/ffi/struct_layout_builder.rb, line 73 def packed=(packed) if packed.is_a?(Fixnum) @alignment = packed @packed = packed else @packed = packed ? 1 : 0 end end
@param [Numeric] size Set size attribute with size only if size is greater than attribute value.
# File lib/ffi/struct_layout_builder.rb, line 39 def size=(size) @size = size if size > @size end
Generated with the Darkfish Rdoc Generator 2.