Class: DL::Importable::Internal::Memory

Class | DL::Importable::Internal::Memory
In: | dl/lib/dl/struct.rb
Parent: | Object

### Methods

new size to_ptr

### Public Class methods

new(ptr, names, ty, len, enc, dec)

[Source]

    # File dl/lib/dl/struct.rb, line 22
            def initialize(ptr, names, ty, len, enc, dec)
              @ptr = ptr
              @names = names
              @ty    = ty
              @len   = len
              @enc   = enc
              @dec   = dec

              # define methods
              @names.each{|name|
                instance_eval [
                  "def #{name}",
                  "  v = @ptr[\"#{name}\"]",
                  "  if( @len[\"#{name}\"] )",
                  "    v = v.collect{|x| @dec[\"#{name}\"] ? @dec[\"#{name}\"].call(x) : x }",
                  "  else",
                  "    v = @dec[\"#{name}\"].call(v) if @dec[\"#{name}\"]",
                  "  end",
                  "  return v",
                  "end",
                  "def #{name}=(v)",
                  "  if( @len[\"#{name}\"] )",
                  "    v = v.collect{|x| @enc[\"#{name}\"] ? @enc[\"#{name}\"].call(x) : x }",
                  "  else",
                  "    v = @enc[\"#{name}\"].call(v) if @enc[\"#{name}\"]",
                  "  end",
                  "  @ptr[\"#{name}\"] = v",
                  "  return v",
                  "end",
                ].join("\n")
              }
            end

### Public Instance methods

size()

[Source]

    # File dl/lib/dl/struct.rb, line 59
            def size
              return @ptr.size
            end

to_ptr()

[Source]

    # File dl/lib/dl/struct.rb, line 55
            def to_ptr
              return @ptr
            end

[Validate]