abstract struct Novika::FFI::StructView

Overview

Base type of the value side of structs.

Implements Indexable and Indexable::Mutable over the fields in the struct, allowing you to iterate, read, and change them (with some casting from and to ForeignValue though.)

Included Modules

Direct Known Subclasses

Defined in:

novika/ffi.cr

Constructors

Instance Method Summary

Instance methods inherited from module Novika::FFI::ForeignValue

box : Pointer(Void) box, must_be_of(type : ForeignType) must_be_of, to_form? : Form | Nil to_form?, write_to!(base : Pointer(Void)) : Pointer(Void) write_to!

Constructor Detail

def self.new(layout : Novika::FFI::StructLayout, handle : Pointer(Void)) #

[View source]

Instance Method Detail

def ==(other : StructView) #

[View source]
def [](id : String) #

Returns the value of a field with the given identifier. Dies if there is no such field.


[View source]
def []=(id : String, value : ForeignValue) #

Assigns value to a field with the given identifier.


[View source]
def []?(id : String) #

Returns the value of a field with the given identifier, or nil if there is no such field.


[View source]
def address(*args, **options) #

Returns the pointer address of the struct this view refers to.


[View source]
def address(*args, **options, &) #

Returns the pointer address of the struct this view refers to.


[View source]
def has_field?(*args, **options) #

[View source]
def has_field?(*args, **options, &) #

[View source]
def hash(hasher) #
Description copied from module Indexable(Novika::FFI::ForeignValue)

See Object#hash(hasher)


[View source]
def layout : StructLayout #

Returns this view's struct layout.


[View source]
def size #
Description copied from module Indexable(Novika::FFI::ForeignValue)

Returns the number of elements in this container.


[View source]
def to_form? : Form | Nil #
Description copied from module Novika::FFI::ForeignValue

Determines the best form type to represent this foreign value, then builds and returns a form of that type.

Returns nil if value is nothing.


[View source]
def to_s(io) #

[View source]
def unsafe_fetch(index : Int) #
Description copied from module Indexable(Novika::FFI::ForeignValue)

Returns the element at the given index, without doing any bounds check.

Indexable makes sure to invoke this method with index in 0...size, so converting negative indices to positive ones is not needed here.

Clients never invoke this method directly. Instead, they access elements with #[](index) and #[]?(index).

This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.


[View source]
def unsafe_put(index : Int, value : ForeignValue) #
Description copied from module Indexable::Mutable(Novika::FFI::ForeignValue)

Sets the element at the given index to value, without doing any bounds check.

Indexable::Mutable makes sure to invoke this method with index in 0...size, so converting negative indices to positive ones is not needed here.

Clients never invoke this method directly. Instead, they modify elements with #[]=(index, value).

This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.


[View source]