includefile(include/header)

COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::MemoryBridge)(3bobcat)(_CurYrs_)(libbobcat-dev__CurVers_)
                    (Memory Segments)

manpagename(FBB::MemoryBridge)(Memory Segments Data Structure)

manpagesynopsis()
    bf(#include <bobcat/memorybridge>)nl()
    Linking option: tt(-lbobcat )

manpagedescription()

    The class bf(FBB::MemoryBridge) provides the interface to the memory
segments used by Bobcat's tt(Memory...) classes. Bobcat's tt(MemoryBridge)
class accesses or modifies those segments via bf(FBB::MemoryAccess) wrapper
class objects. bf(FBB::MemoryAccess) objects are normally not directly defined
by user programs but only by bf(FBB::MemoryBridge) objects, controlling all
read and write operations to the shared memory blocks. 

Although multiple programs executed in parallel may access the same shared
memory bf(FBB::MemoryBridge) objects do not offer mutex facilities to prevent
those programs from accessing information while it's being modified. Such
mutex facilities could be made available using bf(flock)(2).

includefile(include/namespace)

manpagesection(INHERITS FROM)
    -

manpagesection(CONSTRUCTORS)

    itemization(
    itb(MemoryBridge())
       The default constructor defines a stub bf(MemoryBridge) object that
        cannot immediately be used to access memory segments. The class's
        move-assignment operator can be used to turn it into a usable object.

    itb(MemoryBridge(std::string const &bufSize, bool erase,
            size_t access = 0600))
       Constructs a bf(MemoryBridge) object. Its default capacity is specified
        by tt(bufSize) (cf. section tt(BUFSIZE)), using memory segments
        containing the stream's bytes.

        The access rights of the data stored in bf(MemoryStream) objects are
        defined by the tt(access) parameter, interpreted as an octal value,
        using the specifications used by (bf(chmod)(1)).

        The tt(erase) parameter is used to specify what happens to the memory
        segments once the bf(MemoryBridge) object goes out of scope. When
        specified as tt(false) the allocated memory segments are not destroyed
        when the object goes out of scope (and can be reaccessed until the
        computer is rebooted) using the memory object's tt(ID) (see the next
        constructor). When specified as tt(true) the memory segments are
        erased from memory when the object goes out of scope.nl()
        If construction fails, an tt(FBB::Exception) is thrown.

    itb(MemoryBridge(int id, bool erase))
       This constructor connects to a memory segment having ID
        tt(id).

        The tt(erase) parameter is used as it is used by the previous
        constructor.

        An tt(FBB::Exception) is thrown if construction fails (e.g., no
        memory segment having ID tt(id) exists),
    )

    The move constructor and move-assignment operator are available, the copy
    constructor and copy-assignment operator are not available.

manpagesection(BUFSIZE)

    includefile(bufsize.inc)

manpagesection(MEMBER FUNCTIONS)

    Most of the following members throw exceptions when called from a
bf(MemoryBridge) object that was initialized by its default constructor.

    itemization(
    itb(char *beginPtr() const)
       Returns a pointer to the first byte of the memory block
        (cf. bf(memoryblock)(3bobcat)) corresponding to the current offset
        (cf. member tt(offset()), below). 

    itb(std::streamsize blockBegin() const)
       Returns the offset of the  first byte of the memory block corresponding
        to the current offset.

    itb(std::streamsize blockEnd() const)
       Returns the offset just beyond the last byte of the memory block
        corresponding to the current offset.

    itb(std::streamsize blockSize() const)
       Returns the size of the used memory blocks.

    itb(std::streamsize bufLimits())
       Computes the values returned by tt(blockBegin) and tt(blockEnd)
        corresponding to the current offset.

    itb(char *endPtr() const)
       Returns a pointer to the memory block's byte corresponding to offset
        tt(blockEnd()).

    itb(char *endReadPtr() const)
       Returns a pointer to the position in the current memory block 
        corresponding to the last written byte in that block.

    itb(void extend())
       Extends the amount of memory blocks so that the current offsets is
        located in a memory block that's available when bytes are written into
        that block.
    
    itb(int id() const)
       The ID of the memory block (cf. bf(MemoryAccess)(3bobcat)) controlling
        access to the memory data blocks is returned.

    itb(void info(std::ostream &out))
       Information about the tt(MemoryBridge) is inserted into tt(out): the
        IDs of the memory data blocks, their sizes, the current maximum number
        of memory data blocks, the number of bytes that can be read from
        the memory segments, and its actual storage capacity.

    itb(void load())
       Loads (makes available) the memory block corresponding to the current
        tt(offset).

    itb(std::streamsize maxEnd() const)
       Returns the offset position corresponding to tt(blockEnd) of the
        current last available memory block. The value returned by this member
        can be updated to a larger value after calling tt(extend()).

    itb(std::streamsize offset() const)
       Returns the current absolute offset position.

    itb(void offset(std::streamsize pos) const)
       Sets the current absolute offset position to tt(pos).

    itb(char *offsetPtr() const)
       Returns a pointer to the byte of the memory block corresponding to 
        the current offset.

    itb(size_t read(char *dest, std::streamsize len))
       Copies at most tt(len) bytes from the tt(MemoryBridge's) data to
        tt(dest), returning the actual number of copied bytes. Reading always
        stops when reaching the value returned by tt(writtenUntil()) (see
        below).

    itb(void setErase(bool erase))
       This member is used to change the tt(erase) setting of a
        bf(MemoryBridge) object. It can be used by, e.g., forking programs
        where the program constructs a bf(MemoryBridge) object specifying
        tt(erase == false), but whose memory segments should be erased when
        the parent process ends but not also when the child process ends. This
        is accomplished by calling tt(setErase(true)) in the parent process.

    itb(std::streamsize showmanyc() const)
       Returns the number of characters that can be read from the current
        offset to the offset returned by tt(writtenUntil()).

    itb(void swap(MemoryBridge &other))
       The information of the current tt(MemoryBridge) object is swapped with
        the information of the tt(other) object.

    itb(bool truncate(std::streamsize offset))
       This member reduces or enlarges the available memory size of a
        bf(MemoryBridge) object to tt(size). If it's reduced then the memory
        segments' data bytes from tt(size) to its original size are set to 0:
        newly allocated memory sements are always initialized to 0 byte
        values.

    itb(size_t write(char *src, std::streamsize len))
       Copies tt(len) bytes from tt(src) to the tt(MemoryBridge's) data,
        starting at tt(offset), returning the actual number of copied
        bytes. Unless there's no more physical memory available writing
        succeeds. If the physical memory is exhausted an exception is thrown.

    itb(std::streamsize writtenUntil() const)
       Returns the highest offset of the byte that was ever written to the
        tt(MemoryBridge). 

    itb(void writtenUntil(std::streamsize offset) const)
       Updates the value returned by tt(writtenUntil()) to tt(offset) if
        tt(offset) is larger than that value.
    )


manpagesection(EXAMPLE)
    See the bf(memorystream)(3bobcat) man page.

manpagefiles()
    em(bobcat/memorybridge) - defines the class interface

manpageseealso()
    bf(bobcat)(7), bf(chmod)(1), bf(flock)(2),
        bf(memoryaccess)(3bobcat),
        bf(memorybuf)(3bobcat),
        bf(memoryreadme)(7bobcat),
        bf(memorystream)(3bobcat),

manpagebugs()
    None Reported.

includefile(include/trailer)
