Class: FFI::Struct
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb
Direct Known Subclasses
ManagedStruct, Union, INotify::Native::Event, Inotify::Event, Sys::Uname::UnameFFIStruct, Timeval
Defined Under Namespace
Classes: ManagedStructConverter
Class Method Summary collapse
-
.alignment ⇒ Fixnum
Struct alignment.
- .auto_ptr ⇒ Object
- .by_ref(flags = :inout) ⇒ Object
- .by_value ⇒ Object
- .in ⇒ Object
- .layout(*spec) ⇒ StructLayout
- .members ⇒ Object
-
.offset_of(name) ⇒ Numeric
Get the offset of a field.
-
.offsets ⇒ Array<Array(Symbol, Numeric)>
Get an array of tuples (field name, offset of the field).
- .out ⇒ Object
- .ptr(flags = :inout) ⇒ Object
-
.size ⇒ Numeric
Get struct size.
-
.size=(size) ⇒ size
set struct size.
- .val ⇒ Object
Instance Method Summary collapse
-
#align ⇒ Fixnum
Struct alignment.
-
#alignment ⇒ Fixnum
Struct alignment.
-
#clear ⇒ self
Clear the struct content.
- #members ⇒ Object
-
#offset_of(name) ⇒ Numeric
Get the offset of a field.
-
#offsets ⇒ Array<Array(Symbol, Numeric)>
Get an array of tuples (field name, offset of the field).
-
#size ⇒ Numeric
Get struct size.
-
#to_ptr ⇒ AbstractMemory
Get Pointer to struct content.
-
#values ⇒ Array
Get array of values from Struct fields.
Class Method Details
.alignment ⇒ Fixnum
Returns Struct alignment.
104 105 106 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 104 def self.alignment @layout.alignment end |
.auto_ptr ⇒ Object
165 166 167 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 165 def self.auto_ptr @managed_type ||= Type::Mapped.new(ManagedStructConverter.new(self)) end |
.by_ref(flags = :inout) ⇒ Object
143 144 145 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 143 def self.by_ref(flags = :inout) self.ptr(flags) end |
.by_value ⇒ Object
139 140 141 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 139 def self.by_value self.val end |
.in ⇒ Object
123 124 125 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 123 def self.in ptr(:in) end |
.layout ⇒ StructLayout .layout(*spec) ⇒ StructLayout
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 205 def layout(*spec) warn "[DEPRECATION] Struct layout is already defined for class #{self.inspect}. Redefinition as in #{caller[0]} will be disallowed in ffi-2.0." if defined?(@layout) return @layout if spec.size == 0 builder = StructLayoutBuilder.new builder.union = self < Union builder.packed = @packed if defined?(@packed) builder.alignment = @min_alignment if defined?(@min_alignment) if spec[0].kind_of?(Hash) hash_layout(builder, spec) else array_layout(builder, spec) end builder.size = @size if defined?(@size) && @size > builder.size cspec = builder.build @layout = cspec unless self == Struct @size = cspec.size return cspec end |
.members ⇒ Object
109 110 111 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 109 def self.members @layout.members end |
.offset_of(name) ⇒ Numeric
Get the offset of a field.
119 120 121 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 119 def self.offset_of(name) @layout.offset_of(name) end |
.offsets ⇒ Array<Array(Symbol, Numeric)>
Get an array of tuples (field name, offset of the field).
114 115 116 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 114 def self.offsets @layout.offsets end |
.out ⇒ Object
127 128 129 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 127 def self.out ptr(:out) end |
.ptr(flags = :inout) ⇒ Object
131 132 133 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 131 def self.ptr(flags = :inout) @ref_data_type ||= Type::Mapped.new(StructByReference.new(self)) end |
.size ⇒ Numeric
Get struct size
91 92 93 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 91 def self.size defined?(@layout) ? @layout.size : defined?(@size) ? @size : 0 end |
.size=(size) ⇒ size
set struct size
98 99 100 101 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 98 def self.size=(size) raise ArgumentError, "Size already set" if defined?(@size) || defined?(@layout) @size = size end |
.val ⇒ Object
135 136 137 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 135 def self.val @val_data_type ||= StructByValue.new(self) end |
Instance Method Details
#align ⇒ Fixnum
Returns Struct alignment.
53 54 55 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 53 def alignment self.class.alignment end |
#alignment ⇒ Fixnum
Returns Struct alignment.
50 51 52 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 50 def alignment self.class.alignment end |
#clear ⇒ self
Clear the struct content.
78 79 80 81 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 78 def clear pointer.clear self end |
#members ⇒ Object
61 62 63 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 61 def members self.class.members end |
#offset_of(name) ⇒ Numeric
Get the offset of a field.
56 57 58 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 56 def offset_of(name) self.class.offset_of(name) end |
#offsets ⇒ Array<Array(Symbol, Numeric)>
Get an array of tuples (field name, offset of the field).
72 73 74 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 72 def offsets self.class.offsets end |
#size ⇒ Numeric
Get struct size
45 46 47 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 45 def size self.class.size end |
#to_ptr ⇒ AbstractMemory
Get Pointer to struct content.
85 86 87 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 85 def to_ptr pointer end |
#values ⇒ Array
Get array of values from Struct fields.
67 68 69 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/struct.rb', line 67 def values members.map { |m| self[m] } end |