Class: Fiddle::CUnionEntity
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
CStructEntity,
Pointer
|
|
|
Instance Chain:
self,
CStructEntity,
Pointer
|
|
| Inherits: |
Fiddle::CStructEntity
|
| Defined in: | ext/fiddle/lib/fiddle/struct.rb |
Overview
A C union wrapper
Class Method Summary
-
.malloc(types, func = nil)
Allocates a C union the
typesprovided. -
.size(types)
Returns the size needed for the union with the given
types.
CStructEntity - Inherited
| .malloc | Allocates a C struct with the |
| .new | Wraps the C pointer |
| .size | Returns the offset for the packed sizes for the given |
Pointer - Inherited
Instance Attribute Summary
Pointer - Inherited
Instance Method Summary
-
#set_ctypes(types)
Calculate the necessary offset and for each union member with the given
types
CStructEntity - Inherited
| #[] | Fetch struct member |
| #[]= | Set struct member |
| #assign_names | Set the names of the |
| #set_ctypes | Calculates the offsets and sizes for the given |
Pointer - Inherited
| #+ | Returns a new pointer instance that has been advanced |
| #+@ | Returns a new Pointer instance that is a dereferenced pointer for this pointer. |
| #- | Returns a new pointer instance that has been moved back |
| #-@ | Returns a new Pointer instance that is a reference pointer for this pointer. |
| #<=> | Returns -1 if less than, 0 if equal to, 1 if greater than |
| #== | Returns true if |
| #[] | Returns integer stored at index. |
| #[]= | Set the value at |
| #eql? | Alias for Pointer#==. |
| #inspect | Returns a string formatted with an easily readable representation of the internal state of the pointer. |
| #ptr | Alias for Pointer#+@. |
| #ref | Alias for Pointer#-@. |
| #to_i | Returns the integer memory location of this pointer. |
| #to_int | Alias for Pointer#to_i. |
| #to_s | Returns the pointer contents as a string. |
| #to_str | Returns the pointer contents as a string. |
| #to_value | Cast this pointer to a ruby object. |
Constructor Details
This class inherits a constructor from Fiddle::CStructEntity
Class Method Details
.malloc(types, func = nil)
Allocates a C union the types provided.
When the instance is garbage collected, the C function func is called.
.size(types)
Returns the size needed for the union with the given types.
Fiddle::CUnionEntity.size(
[ Fiddle::TYPE_DOUBLE,
Fiddle::TYPE_INT,
Fiddle::TYPE_CHAR,
Fiddle::TYPE_VOIDP ]) #=> 8
Instance Method Details
#set_ctypes(types)
Calculate the necessary offset and for each union member with the given types
# File 'ext/fiddle/lib/fiddle/struct.rb', line 236
def set_ctypes(types) @ctypes = types @offset = Array.new(types.length, 0) @size = self.class.size types end