Class: SDL2::RWops

Inherits:
Struct
  • Object
show all
Defined in:
lib/sdl2/rwops.rb,
lib/sdl2/rwops.rb

Overview

“This is the read/write operation structure – very basic”

size    - " Return the size of the file in this rwops, or -1 if unkown
seek    - "Seek to \c offset relative to \c whence, one of stdio's whence values:
            RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
            return the final offset in the data stream, or -1 on error.
read    - "Read up to \c maxnum objects each of size \c size from the data
            stream to the area pointed at by \c ptr.
            Return the number of objects read, or 0 at error or end of file.
write   - "Write eactly \c num objects each of size \c size from the area
            pointed at by \c ptr to data stream.
            Return the number of objects written, or 0 at error or end of file.
close   - "Close and free an allocated SDL_RWops structure.
            Return 0 if successful or -1 on write error when flushing data.

Defined Under Namespace

Classes: AndroidIO, Hidden, Mem, STDIO, Unkown, WindowsIO

Constant Summary collapse

SEEK_SET =

“Seek from the beginning of data”

0
SEEK_CUR =

“Seek relative to current read point”

1
SEEK_END =

“Seek relative to the end of data”

2

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#==, cast, create, #free, #initialize, #to_s, #update_members

Methods included from StructHelper

#member_readers, #member_writers

Constructor Details

This class inherits a constructor from SDL2::Struct

Class Method Details

.from_file(file_name, mode) ⇒ Object

Create RWOps from file name



109
110
111
# File 'lib/sdl2/rwops.rb', line 109

def self.from_file(file_name, mode)
  SDL2.rw_from_file!(file_name, mode)
end

.release(pointer) ⇒ Object

Release this structure using SDL_FreeRW



93
94
95
# File 'lib/sdl2/rwops.rb', line 93

def self.release(pointer)
  SDL2.free_rw(pointer)
end

Instance Method Details

#closeObject

“Close and free an allocated SDL_RWops structure.”

"\return 0 if successful or -1 on write error when flushing data."


155
156
157
# File 'lib/sdl2/rwops.rb', line 155

def close
  self[:close].call(self)
end

#read(pointer, size, n) ⇒ Object

“Read up to c maxnum objects each of size c size from the data

stream to the area pointed at by \c ptr."
"\return the number of objects read, or 0 at error or end of file."


139
140
141
# File 'lib/sdl2/rwops.rb', line 139

def read(pointer, size, n)
  self[:read].call(self, pointer, size, n)
end

#seek(offset, whence) ⇒ Object

“Seek to c offset in the data stream, or -1 on error.” “return the number of objects read, or 0 at error or end of file”



124
125
126
# File 'lib/sdl2/rwops.rb', line 124

def seek(offset, whence)
  self[:seek].call(self, offset, whence)
end

#sizeObject

“Return the size of the file in this rwops, or -1 if unkown”



117
118
119
# File 'lib/sdl2/rwops.rb', line 117

def size
  self[:size].call
end

#tellObject

BadQuanta: “I suppose this returns the current position” SDL_rwops.h:186.



131
132
133
# File 'lib/sdl2/rwops.rb', line 131

def tell
  self[:seek].call(self, 0, SEEK_CUR)
end

#write(pointer, size, n) ⇒ Object

“Write exactly c num objects each of size c size from the area

pointed at by \c ptr to data stream."

"\return the number of objects written, or 0 at error or end of file."


148
149
150
# File 'lib/sdl2/rwops.rb', line 148

def write(pointer, size, n)
  self[:write].call(self, pointer, size, n)
end