Class: FFIDB::Struct

Inherits:
Object
  • Object
show all
Includes:
Symbolic
Defined in:
lib/ffidb/struct.rb

Instance Method Summary collapse

Methods included from Symbolic

#<=>, #enum?, #function?, #kind, #kind_weight, #to_yaml, #typedef?, #union?

Constructor Details

#initialize(name, fields = {}, comment = nil) ⇒ Struct

Returns a new instance of Struct.

Parameters:

  • name (Symbol, #to_sym)
  • fields (Map<Symbol, Type>) (defaults to: {})
  • comment (String, #to_s) (defaults to: nil)


13
14
15
# File 'lib/ffidb/struct.rb', line 13

def initialize(name, fields = {}, comment = nil)
  super(name.to_sym, fields || {}, comment&.to_s)
end

Instance Method Details

#opaque?Boolean

Returns:

  • (Boolean)


23
# File 'lib/ffidb/struct.rb', line 23

def opaque?() !self.fields || self.fields.empty? end

#struct?Boolean

Returns:

  • (Boolean)


19
# File 'lib/ffidb/struct.rb', line 19

def struct?() return true end

#to_hHash<Symbol, Type>

Returns:

  • (Hash<Symbol, Type>)


33
34
35
36
37
38
39
# File 'lib/ffidb/struct.rb', line 33

def to_h
  {
    name: self.name.to_s,
    comment: self.comment,
    fields: self.opaque? ? nil : self.fields&.transform_values { |t| t.to_s },
  }.delete_if { |k, v| v.nil? }
end

#to_sString

Returns:

  • (String)


27
28
29
# File 'lib/ffidb/struct.rb', line 27

def to_s
  "struct #{self.name}"
end