ObjectiveLib  1.0.0
Public Member Functions | Static Public Member Functions | Protected Attributes
OLObjectOutStream Class Reference

A stream that is capable of writing objects and classes. More...

#import <ObjectiveLib/ObjectOutStream.h>

Inheritance diagram for OLObjectOutStream:
Inheritance graph
[legend]

List of all members.

Public Member Functions

(void) - replaceObject:withObject:
 Replace all instances of an object.
(void) - writeBool:
 Write a boolean value to the stream.
(void) - writeClass:
 Write a class.
(void) - writeDouble:
 Write a double value to the stream.
(void) - writeFloat:
 Write a float value to the stream.
(void) - writeHeader
 Write the object stream header.
(void) - writeInt16:
 Write a 16-bite integer value to the stream.
(void) - writeInt32:
 Write a 32-bit integer value to the stream.
(void) - writeInt64:
 Write a 64-bit integer value to the stream.
(void) - writeInt:
 Write a integer value to the stream.
(void) - writeObject:
 Write an object.
Initializers and Deallocators
(id) - initWithOutStream:
 Initialize the stream.
(void) - dealloc
 Finalize the stream and deallocate any allocated memory.
NSCoder Support

Support the streaming of objects that adopt the NSCoding protocol

(void) - encodeBytes:length:
 Encode a buffer of data.
(void) - encodeDataObject:
 Encode a data object.
(void) - encodeObject:
 Encode an object.
(void) - encodeValueOfObjCType:at:
 Encode a value of a specified Objective-C type.
(unsigned) - systemVersion
 Return the current system version.
(unsigned) - versionForClassName:
 Return the current version of a class.

Static Public Member Functions

(id) + streamWithOutStream:
 Create and return a new stream.

Protected Attributes

OLPointerRefTable * pointerMap
 The map of pointers to object, selectors and classes that assoicates them with handles.
OLObjectReplaceTable * replacementMap
 The map of objects and their replacements.

Detailed Description

A stream that is capable of writing objects and classes.

In addition to having the ability to write objects and classes, OLObjectOutStream tags every type written to the stream, which is then verified when OLObjectInStream reads the value. If a certain type is expected but another type is found, an exception is raised to indicate the inconsistency. Also, objects and classes are tracked as they are written, and when an object or class is written that already appears in the stream, a handle is written that refers to the instance already written. This improves performance and reduces the size of the resulting data.

See also:
OLObjectInStream

Member Function Documentation

- (void) dealloc

Finalize the stream and deallocate any allocated memory.

Reimplemented from OLLayeredOutStream.

- (void) encodeBytes: (const void *)  address
length: (unsigned)  numBytes 

Encode a buffer of data.

This method is included solely to support objects that already support the NSCoding protocol, and relies on the lower-level message writeBytes:count: (OLLayeredOutStream). There is nothing to be gained by choosing to call this method explicitly over the preferred method writeBytes:count: (OLLayeredOutStream).

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
addressthe address of the data to write
numBytesthe number of bytes to write

Reimplemented from OLOutStream.

- (void) encodeDataObject: (NSData *)  data

Encode a data object.

This method is included solely to support objects that already support the NSCoding protocol, and relies on the lower-level message writeBytes:count: (OLLayeredOutStream). There is nothing to be gained by choosing to call this method explicitly over the preferred method writeBytes:count: (OLLayeredOutStream).

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
datathe data object to write

Reimplemented from OLOutStream.

- (void) encodeObject: (id)  object

Encode an object.

The object will be written unless this object has already been written to the stream, in which case a reference to it will be written. This method forwards object to writeObject:, so there is nothing to be gained by using this method instead of that one.

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
objectthe object to write

Reimplemented from OLOutStream.

- (void) encodeValueOfObjCType: (const char *)  valueType
at: (const void *)  address 

Encode a value of a specified Objective-C type.

Write a value of an arbitrary type to the stream. Note that in order to preserve platform-independence in the resulting stream, constraints are placed on how the data are written. Types that otherwise have indeterminate sizes will always be normalized to sizes chosen by ObjectiveLib. The sizes written are as follows:

TypeSize
char1
short2
int4
long4
long long8
Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
valueTypethe type of the value at address
addressthe location of the value

Reimplemented from OLOutStream.

- (id) initWithOutStream: (OLOutStream *)  underStream

Initialize the stream.

underStream becomes the next lower stream in the stream stack.

Parameters:
underStreamthe stream under the new one in the stream stack
Returns:
a reference to this stream

Reimplemented from OLLayeredOutStream.

- (void) replaceObject: (id)  obj
withObject: (id)  rep 

Replace all instances of an object.

After receiving this message the stream will always replace any occurrence of obj with rep.

Parameters:
objthe object to replace
repthe replacement object
+ (id) streamWithOutStream: (OLOutStream *)  underStream

Create and return a new stream.

The underStream becomes the next lower stream in the stream stack.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
underStreamthe stream under the new one in the stream stack
Returns:
a reference to the newly created stream
- (unsigned) systemVersion

Return the current system version.

The version refers to the version of the ObjectiveLib streaming system.

Returns:
the system version
- (unsigned) versionForClassName: (NSString *)  className

Return the current version of a class.

The name of the class is used to look up its version in the Objective-C runtime system. This version is returned.

Note:
If no class by the given name can be found in the runtime, then the value NSNotFound is returned.
Parameters:
classNamethe name of the class
Returns:
the version of the class
- (void) writeBool: (BOOL)  value

Write a boolean value to the stream.

The value is written in a platform-independent way and can be read using readBool (OLInStream). Specifically, the value is written as a single byte with a value of 1 if value is YES (or non-zero), and as a single byte with a value of 0 if value is NO (or zero).

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
valuethe boolean value to write

Reimplemented from OLOutStream.

- (void) writeClass: (Class)  cls

Write a class.

The class will be written unless this class has already been written to the stream, in which case a reference to it will be written.

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
clsthe class to write
- (void) writeDouble: (double)  value

Write a double value to the stream.

The double is written in a platform-independent way and can be read using readDouble (OLInStream). Specifically, the value is written as an 8-byte array in network byte order.

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
valuethe double value to write

Reimplemented from OLOutStream.

- (void) writeFloat: (float)  value

Write a float value to the stream.

The float is written in a platform-independent way and can be read using readFloat (OLInStream). Specifically, the value is written as a 4-byte array in network byte order.

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
valuethe float value to write

Reimplemented from OLOutStream.

- (void) writeHeader

Write the object stream header.

This method can be overridden to write a custom header to the object stream. It will be called in due course, so it is never necessary to call this method.

Note:
Subclasses that override this method should call the superclass' method before writing any additional data.
Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
- (void) writeInt16: (uint16_t)  value

Write a 16-bite integer value to the stream.

The integer is written in a platform-independent way and can be read using readInt16 (OLInStream). Specifically, the value is written as a 2-byte array in network byte order.

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
valuethe integer value to write

Reimplemented from OLOutStream.

- (void) writeInt32: (uint32_t)  value

Write a 32-bit integer value to the stream.

The integer is written in a platform-independent way and can be read using readInt32 (OLInStream). Specifically, the value is written as a 4-byte array in network byte order.

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
valuethe integer value to write

Reimplemented from OLOutStream.

- (void) writeInt64: (uint64_t)  value

Write a 64-bit integer value to the stream.

The integer is written in a platform-independent way and can be read using readInt64 (OLInStream). Specifically, the value is written as an 8-byte array in network byte order.

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
valuethe integer value to write

Reimplemented from OLOutStream.

- (void) writeInt: (unsigned)  value

Write a integer value to the stream.

The integer is written in a platform-independent way and can be read using readInt (OLInStream). Specifically, the value is written as a 4-byte array in network byte order.

Note:
Regardless of the size of the type int on the platform being used, the value written will always be exactly four bytes long.
Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
valuethe integer value to write

Reimplemented from OLOutStream.

- (void) writeObject: (id)  object

Write an object.

The object will be written unless this object has already been written to the stream, in which case a reference to it will be written.

Precondition:
object must support either the OLStreamable protocol or the NSCoding protocol. If both protocols are found, then preference is given to the methods from OLStreamable.
Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
objectthe object to write

Member Data Documentation

- (OLPointerRefTable*) pointerMap [protected]

The map of pointers to object, selectors and classes that assoicates them with handles.

- (OLObjectReplaceTable*) replacementMap [protected]

The map of objects and their replacements.


The documentation for this class was generated from the following file:

ObjectiveLibGenerated Sat Feb 15 2014 07:45:35, © 2004-2007 Will Mason