code::LinearBuffer Class Reference

Detailed Description

LinearBuffer.h implements a class LinearBuffer that is a narrow interface to the ORPG lb library.

Objects of this class have to be specifically opened after creation. They are destroyed when they go out of scope. To prevent such destruction, allocate them using "new" and destroy them using "delete". LinearBuffers allow you to transfer files and messages across a LAN and are especially useful when creating distributed processes. LinearBuffer supports threading, mostly by setting mutex locks to ensure data integrity. Open, close, read and write are all thread-safe. OpenW and functions that depend on the file pointer position are not. Trying to read/write a closed LB will provide an error. To obtain the meaning of the various error codes, check the file lb.h .

The name "yak:.OPUP/AT.log" corresponds to a remote LB stored on yak in the user's home directory i.e. to ~/.OPUP/AT.log. The name "AT.log" corresponds the LB stored in the current directory on the current machine. The LinearBuffer class presents an unified interface to both local and remote LBs.

the length of the message and a negative integer (see LB_msg_info) on error

bool code::LinearBuffer::isOpen

(

)

const

Returns 1 if LB is open, 0 if not.

int code::LinearBuffer::latest

(

)

[inline]

Makes LB_NEXT point to the last message in the LB.

Returns zero on success and a negative integer (see LB_seek) on error. Use lock() in a threaded application to keep the LB pointer where you have moved it.

int code::LinearBuffer::moveLBptr

(

int

offset

)

[inline]

Moves the LB pointer n messages from the current.

Negative n moves it back and postitive n moves it forward.Returns zero on success and a negative integer (see LB_seek) on error. Use lock() in a threaded application to keep the LB pointer where you have moved it

A new LB is created if it doesn't already exist; if an LB of the same name already exists, the existing data is not clobbered. Instead, a safer version of the open is performed. This function is not thread-safe. Pass in the expected numbers for number of messages and average size.

Returns:

0 on success and a negative integer on failure. For the meaning of these error codes, look at the documentation for LB_open.

The LB created is of the maximum size possible with an average of 512 bytes per message. (i.e. SHRT_MAX and 512 are passed to the openW method).

Reads message of specified id and returns the length of read-in message if successful.

The msg buffer should be large enough to hold msglen bytes. On failure, it returns a negative integer. For the meaning of these error codes, look at the documentation for LB_read. When the error to be suppressed is encountered, it returns zero.

Read using LB_NEXT is not thread-safe. Read using a message id is.

int code::LinearBuffer::rewind

(

)

[inline]

Makes LB_NEXT point to the first message in the LB.

Returns zero on success and a negative integer (see LB_seek) on error. Use lock() in a threaded application to keep the LB pointer where you have moved it.

int code::LinearBuffer::seek

(

LB_id_t

id,

int

offset

)

[inline]

Move the LB pointer to the specified message in the LB.

Don't use this unless you know what you're doing. rewind(), latest(), and moveLBptr() are better for common use. Use lock() in a threaded application to keep the LB pointer where you have moved it.

void code::LinearBuffer::write

(

int

messageId,

const void *

buffer,

int

bufferLength,

int *

setme_error = 0

)

Same as write() except that the buffer overwrites the message messageId.

The replacing message should be the same size as the old one. Returns message id of the writen message on success and a negative number (see LB_write) on error.

void code::LinearBuffer::write

(

const void *

buffer,

int

bufferLength,

int *

setme_error = 0

)

Writes the buffer out to the LB as the latest message.

Returns message id of the writen message on success and a negative number (see LB_write) on error.