Class: Fox::FXMemoryStream

Inherits:
FXStream show all
Defined in:
rdoc-sources/FXMemoryStream.rb,
lib/fox16/iterators.rb

Overview

A FXMemoryStream is a stream that reads from (or writes to) a buffer of bytes in memory. That buffer may “owned” by either the application code or by the stream object itself. In the latter case, the stream object will dispose of the buffer contents when the stream is closed.

Instance Attribute Summary collapse

Attributes inherited from FXStream

#container, #direction, #space, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FXStream

#bigEndian=, #bigEndian?, #bytesSwapped=, #bytesSwapped?, #close, #eof?, #error=, #flush, #getSpace, #setSpace

Constructor Details

#initialize(cont = nil) ⇒ FXMemoryStream

Construct a new memory stream with given container object. The container object is an object that will itself not be saved to or loaded from the stream, but which may be referenced by other objects. These references will be properly saved and restored.

Parameters:

cont

the container object, or nil if there is none Fox::FXObject.



22
23
# File 'rdoc-sources/FXMemoryStream.rb', line 22

def initialize(cont=nil) # :yields: theMemoryStream
end

Instance Attribute Details

#positionObject (readonly)

Returns the value of attribute position.



10
11
12
# File 'rdoc-sources/FXMemoryStream.rb', line 10

def position
  @position
end

Class Method Details

.open(save_or_load, data, cont = nil) ⇒ Object

Construct a new FXMemoryStream object with the specified data flow direction, data and container object. If an optional code block is given, it will be passed this memory stream as an argument, and the memory stream will automatically be closed when the block terminates. If no code block is provided, this method just returns the new memory stream in an opened state.

Raises FXStreamAllocError if some kind of memory allocation failed while initializing the stream.

Parameters:

save_or_load:: access mode, either FXStreamSave or FXStreamLoad [Integer] data:: memory buffer used for the stream, or nil if the buffer is to be initially empty [String]. cont:: the container object, or nil if there is none [FXObject]



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/fox16/iterators.rb', line 321

def FXMemoryStream.open(save_or_load, data, cont=nil) # :yields: theMemoryStream
  stream = FXMemoryStream.new(cont)
  if stream.open(save_or_load, data)
  	if block_given?
  	  begin
  	    yield stream
  	  ensure
  	    stream.close
  	  end
  	else
  	  stream
  	end
  else
    # FXFileStream#open returned false, so report error
  	raise FXStreamError.makeStreamError(stream.status)
  end
end

Instance Method Details

#giveBuffer(buffer) ⇒ Object

Give buffer (a string) to this stream, thus transferring ownership of the buffer from the caller to the stream object.



47
# File 'rdoc-sources/FXMemoryStream.rb', line 47

def giveBuffer(buffer); end

#open(save_or_load, data) ⇒ Object

Open memory stream for reading or writing. Returns true if successful, false otherwise.

Parameters:

save_or_load

access mode, either FXStreamSave or FXStreamLoad [Integer]

data

memory buffer to be used for the stream, or nil if the stream object should allocate its own buffer [String]



34
# File 'rdoc-sources/FXMemoryStream.rb', line 34

def open(save_or_load, data); end

#takeBufferObject

Take buffer away from stream, thus transferring ownership of the buffer from the stream object to the caller. Returns a string containing the buffer contents.



41
# File 'rdoc-sources/FXMemoryStream.rb', line 41

def takeBuffer; end