Top Description Inners Fields Constructors Methods
org.jruby.ext.ffi

public final Class StructLayout

extends Type
Class Inheritance
Annotations
@JRubyClass
name:StructLayout
parent:Object
Imports
java.nio.ByteBuffer, .ByteOrder, java.util.ArrayList, .Arrays, .Collection, .Collections, .HashMap, .List, .Map, org.jruby.Ruby, .RubyArray, .RubyClass, .RubyHash, .RubyInteger, .RubyModule, .RubyObject, .RubyString, .RubySymbol, org.jruby.anno.JRubyClass, .JRubyMethod, org.jruby.api.Access, .Convert, .Create, org.jruby.internal.runtime.methods.DynamicMethod, org.jruby.runtime.Arity, .Block, .ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.callsite.CachingCallSite, .FunctionalCachingCallSite, org.jruby.util.ByteList

Defines the memory layout for a native structure.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
pack-priv static class
public static class
public static class
pack-priv static class
public static class
pack-priv static class
StructLayout.EnumFieldIO

Enum (maps :foo => 1, :bar => 2, etc)

public static class
pack-priv static interface
public static class
pack-priv static class
public static class
pack-priv static class
pack-priv static class
public static class
StructLayout.Member

A struct member.

pack-priv static class
pack-priv static class
public static class
pack-priv static class
StructLayout.NumberFieldIO

Primitive (byte, short, int, long, float, double) types are all handled by a PrimitiveMember type.

public static class
pack-priv static class
public static interface
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final int
cacheableFieldCount

The number of cacheable fields in this struct

pack-priv static final String
CLASS_NAME

The name to use to register this class in the JRuby runtime

private final List<IRubyObject>
fieldNames

The ordered list of field names (as symbols)

private final List<StructLayout.Field>
fields

The ordered list of fields

private final StructLayout.Member[]
private final boolean
private final Map<IRubyObject, StructLayout.Member>
memberMap

The name:offset map for this struct

private final Collection<StructLayout.Member>
members

The ordered list of fields

pack-priv static final StructLayout.Storage
private final int
referenceFieldCount

The number of reference fields in this struct

Inherited from org.jruby.ext.ffi.Type:
alignmentnativeTypesize

Constructor Summary

AccessConstructor and Description
private
StructLayout(ThreadContext
The current thread context.
context
,
RubyClass klass, Collection<IRubyObject>
The fields map for this struct.
fields
,
int
the total size of the struct.
size
,
int
The minimum alignment required when allocating memory.
alignment
)

Creates a new StructLayout instance.

Method Summary

Modifier and TypeMethod and Description
public IRubyObject
aref(ThreadContext context, IRubyObject fieldName)

public static RubyClass
public boolean
equals(Object
object to compare
o
)

Overrides org.jruby.RubyObject.equals.

This override does not do a "checked" dispatch.

public IRubyObject
public IRubyObject

Returns:

A ruby value for the native value of the struct member.
get
(ThreadContext context, IRubyObject
The address of the structure in memory.
ptr
,
IRubyObject
The name of the member.
name
)

Gets the value of the struct member corresponding to name.

private static MemoryOp
pack-priv final int
pack-priv final int
pack-priv final StructLayout.Field

Returns:

A Member descriptor.
getField
(ThreadContext context, IRubyObject
The name of the struct field.
name
)

Returns a Field descriptor for a struct field.

public final int
public final Collection<StructLayout.Field>
pack-priv final StructLayout.Member

Returns:

A Member descriptor.
getMember
(ThreadContext context, IRubyObject
The name of the struct field.
name
)

Returns a Member descriptor for a struct field.

public final Collection<StructLayout.Member>
pack-priv final int
pack-priv final int
public final int
pack-priv final IRubyObject
public int
hashCode()

Overrides org.jruby.RubyObject.hashCode.

This override does not do "checked" dispatch since Object usually has #hash defined.

public final boolean
public IRubyObject

Returns:

a RubyArray containing the names of all members.
members
(ThreadContext context)

Gets a ruby array of the names of all members of this struct.

public static final IRubyObject
private static int
nextIndex(int idx, int length)

public IRubyObject
offset_of(ThreadContext context, IRubyObject fieldName)

public IRubyObject

Returns:

a RubyArray containing the offsets of all members.
offsets
(ThreadContext context)

Gets a ruby array of the offsets of all members of this struct.

public IRubyObject

Returns:

A ruby value for the native value of the struct member.
put
(ThreadContext context, IRubyObject
The address of the structure in memory.
ptr
,
IRubyObject
The name of the member.
name
,
IRubyObject value)

Sets the native value of the struct member corresponding to name.

pack-priv final void
private static int
symbolIndex(IRubyObject name, int length)

public IRubyObject
Inherited from org.jruby.ext.ffi.Type:
alignmentcreateTypeClassgetNativeAlignmentgetNativeAlignmentgetNativeSizegetNativeSizegetNativeTypegetTypeClasssize