Module: CTypes::Helpers
- Extended by:
- Helpers
- Included in:
- CTypes, Bitfield::Builder, Helpers, Importers::CastXML::Loader, Struct::Builder, Union::Builder
- Defined in:
- lib/ctypes/helpers.rb
Instance Method Summary collapse
-
#array(type, size = nil, terminator: nil) ⇒ Object
create an Array type.
-
#bitfield(type = nil, bits = nil) { ... } ⇒ Object
create a Bitfield type.
-
#bitmap(type = nil, bits = nil) ⇒ Object
create a Bitmap type.
-
#enum(type = nil, values = nil) ⇒ Object
create an Enum type.
-
#string(size = nil, trim: true) ⇒ Object
create a String type.
-
#struct(attributes = nil) { ... } ⇒ Object
create a Struct type.
-
#union(members = nil) { ... } ⇒ Object
create a Union type.
Instance Method Details
#array(type, size = nil, terminator: nil) ⇒ Object
create an Array type
153 154 155 |
# File 'lib/ctypes/helpers.rb', line 153 def array(type, size = nil, terminator: nil) Array.new(type:, size:, terminator:) end |
#bitfield(type = nil, bits = nil) { ... } ⇒ Object
create a Bitfield type
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/ctypes/helpers.rb', line 170 def bitfield(type = nil, bits = nil, &block) if bits.nil? && !block bits = type type = nil end Class.new(Bitfield) do if bits layout do bytes(type.size) if type bits.each do |name, size| unsigned name, size end end else layout(&block) end end end |
#bitmap(type = nil, bits = nil) ⇒ Object
create a Bitmap type
61 62 63 64 65 66 67 68 69 |
# File 'lib/ctypes/helpers.rb', line 61 def bitmap(type = nil, bits = nil, &) if bits.nil? bits = type type = uint32 end bits = enum(bits, &) unless bits.is_a?(Enum) Bitmap.new(type: type, bits: bits) end |
#enum(type = nil, values = nil) ⇒ Object
create an Enum type
41 42 43 |
# File 'lib/ctypes/helpers.rb', line 41 def enum(type = nil, values = nil, &) Enum.new(type, values, &) end |
#string(size = nil, trim: true) ⇒ Object
create a String type
79 80 81 |
# File 'lib/ctypes/helpers.rb', line 79 def string(size = nil, trim: true) String.new(size:, trim:) end |
#struct(attributes = nil) { ... } ⇒ Object
create a Struct type
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ctypes/helpers.rb', line 97 def struct(attributes = nil, &block) Class.new(Struct) do if attributes layout do attributes.each do |name, type| attribute name, type end end else layout(&block) end end end |
#union(members = nil) { ... } ⇒ Object
create a Union type
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/ctypes/helpers.rb', line 126 def union(members = nil, &block) Class.new(Union) do if members layout do members.each do |name, type| member name, type end end else layout(&block) end end end |