classwork.ppIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers Classes hierarchy graph
|
Class AStringStream
Unit
classwork
Declaration
type AStringStream = class(AStream, CanStream, CanPrint)
Description
This class allows an AnsiString to be read from and written to as though it was a stream. It is useful in those instances when buffering data in memory is desired, particularly because the class is capable of streaming its contents to and from another stream.
The stream supports reading, writing, and seeking. Read and write operations always occur at the location specified by AStringStream.position; this value can be changed by first calling AStringStream.setPosition.
Regardless of how the parent unit is compiled (with or without AnsiString s as the default string type), this class will always operate on an AnsiString .
Hierarchy
Overview
Fields
Methods
Description
Fields
|
myName: string; |
Stores the name of the stream.
|
|
myString: AnsiString; |
Stores the string data used by the stream.
|
|
myPosition: TStreamOffset; |
Stores the current position within the stream.
|
Methods
|
constructor new(const str: AnsiString = ''); reintroduce; virtual; |
Construct a new stream instance.
If str is provided, its value is used as the initial content of the stream. str is not written to the stream; it is simply assigned as the content, which provides a quick way to buffer a string and then iterate over its contents.
|
|
function init: boolean; override; |
Initializer
|
|
function read(const count: TStreamIOSize; var dest): TStreamIOSize; override; |
Read count bytes from the stream and store them in dest . See AStream.read for more information on this method.
Returns
The total number of bytes read from the stream. |
|
function write(const count: TStreamIOSize; const source): TStreamIOSize; override; |
Write count bytes from source to the stream. See AStream.write for more information on this method.
Note that no checks are made on the data to ensure that what is written will display well on text-based devices.
Returns
The total number of bytes written to the stream. |
|
procedure clear; virtual; |
Clear the stream. The contents of the underlying string are discarded, and AStringStream.position and AStringStream.length are both reset to zero (0). Subsequent attempts to read from the stream without first writing content to it will fail silently, and AStream.hasEnded will return True .
|
|
function shallowCopyFrom(const Other: AnObject): boolean; override; |
Construct a shallow copy of the other object.
This method overrides the behavior inherited from AnObject.shallowCopyFrom: it calls that method, then checks to see whether Other is an instance of AStringStream. If so, it copies the value of
from Other to Self , overwriting any values in Self . The end result in this case is a string stream that is an exact copy of Other .
|
|
function writeTo(const Dest: AStream): TStreamIOSize; virtual; |
Writes the content of the stream to Dest . See CanStream.writeTo for more information on this method.
This method calls AStream.writeString on Dest , which means the length and checksum of the underlying string are also written.
Returns
The total number of bytes written to Dest , which will include the length and checksum information for the underlying string. |
|
function readFrom(const Source: AStream): TStreamIOSize; virtual; |
Reads the contents of the stream from Source . See CanStream.readFrom for more information on this method.
This method calls AStream.readString on Source , which means that it will first read the length and checksum of the underlying string.
Returns
The total number of bytes read from Source , which will include the length and checksum information for the underlying string. |
|
function toString: string; override; |
Constructs and returns a string representation of the stream, suitable for output to a text-based device. See CanPrint.toString for more information on this method.
This method simply returns the value of AStringStream.text, which is the underlying content of the stream.
|
|
function printTo(const Dest: ATextOutputStream; prefix: AnsiString = ''; suffix: AnsiString = ''): TStreamIOSize; virtual; |
Print a string representation of the stream to Dest . See CanPrint.printTo for more information on this method.
This method simply prints the value returned by a call to AStringStream.toString to Dest .
Returns
The total number of bytes printed to Dest . |
|
function name: string; override; |
Retrieve the name of the stream.
This method overrides the behavior inherited from AnObject.name: instead of return the class name of the stream, it returns the name set by a previous call to AStringStream.setName. If no such call has been made, an empty string is returned.
|
|
function setName(const newName: string): string; virtual; |
Set the name of the stream.
This method allows the caller to set the name that is reported when AStringStream.name is called. This behavior is intended to allow a descriptive name to be given to instances of AStringStream for display in debug and diagnostic messages.
Returns
The previous value of AStringStream.name. |
|
function position: TStreamOffset; override; |
Retrieve the current position within the stream. This is the location at which the next read or write operation will occur.
See AStream.position for more information on this method.
|
|
function setPosition(newPosition: TStreamOffset): TStreamOffset; override; |
Set the current position within the stream. This is the location at which the next read or write operation will occur.
See AStream.setPosition for more information on this method.
Returns
The previous position within the stream. |
|
function length: TStreamLength; override; |
Retrieve the current size of the stream, in bytes. See AStream.length for more information on this method.
This method returns the length of the underlying string, as determined by a call to System.length .
|
|
function text: AnsiString; virtual; |
Retrieve the content of the stream. The string returned by this routine will contain all values written to the stream, or the content of the string specified by a call to AStringStream.setText.
|
|
function setText(const newText: AnsiString): AnsiString; virtual; |
Set the content of the stream. The current content of the stream will be discarded in favor of the value specified by newText . AStream.position will be reset to zero (0), and AStream.length will return the length of newText .
Returns
The old content of the stream. |
Generated by PasDoc 0.13.0 on 2015-06-23 19:40:11
|