C3D Toolkit  Kernel - 117982, Vision -

Stream buffer. More...

#include <io_buffer.h>

+ Inheritance diagram for iobuf_Seq:
+ Collaboration diagram for iobuf_Seq:

Public Member Functions

 iobuf_Seq (uint16 clusterSize)
virtual ~iobuf_Seq ()
void Reserve (size_t n, bool addAdditionalSpace=true)
 < Reserve space for a given number of elements. More...
void Flush ()
 Free the whole memory.
void HardFlush ()
 Free the unnecessary memory.
void Adjust ()
 Add an element to the end of the array.
ClusterAdd ()
 Add a given element to the end of the array.
ClusterAdd (const Cluster &e)
 Get the number of elements in array.
Clusteroperator[] (size_t loc) const
 Access by index operator. More...
int gc ()
 Get the next byte from the buffer.
size_t getn (void *, size_t)
 Get the next n bytes from the buffer elementwise.
size_t getln (void *, size_t)
 Get the next n bytes from the buffer by copying the storage area.
int pc (uint8 c)
 Get the next byte from the buffer but don't shift the pointer to the next one. More...
size_t putn (const void *, size_t)
 Put the next n bytes to the buffer elementwise.
size_t putln (const void *, size_t)
 Put the next n bytes to the buffer by copying the storage area.
void advance ()
 If current buffer exhausted, advance pointer to the next one.
bool good () const
 Whether the buffer state is correct.
bool eof () const
 Is the end of file reached?
uint32 state () const
 Get the buffer state.
void setState (io::state add)
 Add the buffer state.
void clearState (io::state sub)
 Remove the buffer state.
io::pos size () const
 Calculate the current file size.
io::pos tell () const
 Returns the current position in the file.
void lseek (size_t pos=SYS_MAX_T)
 Set current position in the buffer.
bool attach (FileSpace &file, bool check=true)
 Attach the file to the buffer with or without checking.
virtual bool open (FileSpace &file, uint8 om, const VersionContainer &, bool fullCheck=true)
 Open the file if it is one's own file. The flag fullCheck == false switches off excessive checks (for the sake of performance).
bool openSys (uint8 om)
 Open the system file.
virtual void close ()
 Close the file.
virtual void closeBuff ()
 Close the buffer.
virtual FileSpaceenterFileSpace (uint8)
 Set FileSpace with given index for writing (create if necessary).
virtual FileSpaceenterFileSpace (const ClusterReference &, bool)
 Set position for for writing/reading by given ClusterReference. If saveCurr = true, save previous position.
virtual FileSpaceenterFileSpace (const ClusterReference &, FileSpace *, bool)
 Set position for writing/reading by given FileSpace and ClusterReference. Warning: in this function, ClusterReference.clusterIndex should contain an index in array of cluster indices in FileSpace! If saveCurr = true, save previous position.
virtual FileSpacereturnToPreviousFileSpace ()
 Set previous FileSpace for writing/reading.
ClusterReference getCurrentClusterPos ()
 Get current position in the buffer.
FileSpacesysFile ()
 Get access to the system file.
FileSpaceopenedFile () const
 Get access to the open file.
virtual size_t DOSFileLen () const
 The storage data size (of the file on the disk).
virtual const TCHAR * DOSFileName () const
 Storage name (of file on the disk).
bool fresh () const
 Is the buffer fresh?
void fresh (bool f)
 Set the state of buffer freshness.
bool modified () const
 Is the buffer modified?
void modified (bool m)
 Set the state of modified buffer.
uint8 mode () const
 Get the buffer mode.
void mode (uint8 m)
 Set the buffer mode.
bool IsInMode () const
 Is in the reading mode?
bool IsOutMode () const
 Is in the writing mode?
bool IsInOrOutMode () const
 Is in the reading or writing mode?
bool deleteIfEmpty () const
 Is the empty file to be deleted?
void deleteIfEmpty (bool s)
 Set the flag of deleting the empty file.
bool deleteOnClose () const
 Is the file to be deleted while closing the buffer?
void deleteOnClose (bool s)
 Set the flag of deleting the file while closing the buffer.
void SetVersionsByStorage ()
 Set the current version to be equal to the storage version.
VERSION MathVersion () const
 Return the main version (of the mathematical kernel).
VERSION AppVersion (size_t ind=-1) const
 Return the additional version (of the target application).
const VersionContainerGetVersionsContainer () const
 Get the buffer versions.
VERSION GetStorageVersion ()
 Get the storage version.
VERSION GetFormatVersion () const
 Get the format version.
void SetFormatVersion (VERSION version)
 Set the format version.

Protected Member Functions

int underflow ()
 Called when the whole buffer are read, but it is necessary to continue reading.
int overflow (uint8 ch)
 Called when the buffer is full but it is necessary to continue writing.
virtual int setup ()=0
 Set the next buffer.
virtual int flush ()=0
 Flush the buffer.
void checkEof ()
 Set the end of file if necessary.
size_t avail () const
 Get the number of unprocessed bytes in the buffer.
size_t waiting () const
 Get the number of processed bytes in the buffer.
bool mine (FileSpace &)
 Check if the file is mine.
void SetVersionsContainer (const VersionContainer &vers)
 Set the version of open file.
VERSION SetStorageVersion (VERSION)
 Set the storage version.

Protected Attributes

uint8 * base
 Pointer to the beginning of the buffer.
uint8 * ptr
 Pointer to the next byte.
uint8 * end
 Pointer to the end of the file.
VERSION storageVers
 The storage version (must be before 'curFileVers').
VersionContainer curFileVers
 Version of the current open file (stream).
VERSION formatVersion
 The format version.
FileSpace sys
 System file.
PArray< FileSpacefiles
 List of files contained in iobuf_Seq (the first element is the address of 'sys').
 Current open file (stream).
size_t part
 Current cluster in the current open file.
uint16 clusterSize
 Cluster size.
uint8 bufferMode
 Buffer mode.
uint8 curFileMode
 Mode of opening the current file.
bool modifiedFlag
 The buffer has been modified.
bool freshFlag
 Is the buffer fresh.


class tape

Detailed Description

Stream buffer.

Stream buffer - the base class.
Buffer iobuf_Seq and its descendants are used for read and write operations in the interest of the stream (class tape).
Classes iobuf_Seq, tape, Catalog and their descendants should be considered together.

  • Storage - file on the disk or memory space.
  • Catalog - catalog inside the storage.
  • File - file inside the storage.
    Class iobuf_Seq contains a cluster array.
    Class Cluster is structured information about the cluster (its beginning and length). It is used for operations with disk, in this case the beginning is a shift, and for operations with memory, in this case the beginning is an address in memory. All the operations of reading and writing are performed clusterwise using the index in the array of clusters iobuf_Seq.
    Class FileSpace is a place allocated for the file, is an array of indices in the array of clusters. It is just what we call 'file' here.
    Attention: from this place the word 'cluster' should be read as index of cluster in the array iobuf_Seq of clusters.

    The most important data fields of iobuf_Seq:
    FileSpace sys - "system" file. It is opened in the constructor of the class tape.
    1. If the class iobuf_Seq is directly used by class tape (for instance: writer potok( "file.ext" ); or reader * potok = new reader( "file.ext" ), then the file sys contains the information which were written to file.ext.
    2. If the class iobuf_Seq is used by class Catalog, then file sys contains the structure of catalogs and files inside Catalog (it is read in the constructor of class Catalog).
      PArray<FileSpace> files - the list of files contained in iobuf_Seq. The first element is always the address of sys. While writing Catalog, the contents of files is written to sys, except the first element, naturally.
      uint32 stateFlag - the buffer state. It is considered that all the read-write operations set this flag when it is necessary and check its state before the real execution. The following functions work with this flag: iobuf_Seq::good, iobuf_Seq::eof, iobuf_Seq::state, iobuf_Seq::setState, iobuf_Seq::clearState; tape::good, tape::eof, tape::state; Catalog::good, Catalog::goodeof, Catalog::goodstate.
      VERSION storageVers - the storage version.
      VERSION curFileVers - version of the current open file (stream).
      In the common case the storage version and the version of any file in the storage can be different.
      uint8 bufferMode - A possible buffer mode.
      uint8 curFileMode - Mode of the current file opening.
      In the common case the storage mode and the mode of open file in this storage can be different. Constraint - if the buffer mode is io::in, then an attempt to open the file for writing (io::out) doesn't result in opening.
      uint8 * base - Pointer to the beginning of the buffer in memory.
      uint8 * ptr - Pointer to the next symbol in memory.
      uint8 * end - Pointer to the end of buffer in the memory.
      When working with the disk, pointers are set to a fixed memory block the sections of file are loaded to while reading. When working with the memory, 'membuf' set them to the memory allocated for the cluster.

      The most important functions of iobuf_Seq:
      Function setup() - set the next cluster to 'buffer' (variables 'base', 'ptr', 'end'). Called from functions 'overflow' (while writing) and 'underflow' (while reading) when the current buffer is over. These functions are in turn called from functions of reading-writing of symbols from the stream (gc(), getn(), getln(), pc(), putn(), putln()).

Function flush() - flush the buffer. Called before getting the next cluster. Do nothing while reading. When writing, when working with the disk, saves the previos cluster on the disk, and, when working with the memory, stores the size of the last filled cluster.
Read operations are performed inside the file which is open at the moment, no read after end of the file.

Member Function Documentation

◆ Reserve()

void iobuf_Seq::Reserve ( size_t  n,
bool  addAdditionalSpace = true 

< Reserve space for a given number of elements.

Set the number of elements to null.

◆ operator[]()

Cluster& iobuf_Seq::operator[] ( size_t  loc) const

Access by index operator.

Reserve space for a given number of FileSpace.

◆ pc()

int iobuf_Seq::pc ( uint8  c)

Get the next byte from the buffer but don't shift the pointer to the next one.

Put byte to the buffer.

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