C3D Toolkit
Kernel - 117982, Vision - 2.9.2.2
|
Memory stream buffer. More...
#include <io_memory_buffer.h>
Classes | |
struct | FileStackEntry |
Stack of FileSpaces. More... | |
Public Member Functions | |
membuf () | |
Constructor. | |
virtual | ~membuf () |
Destructor. | |
bool | isEmpty () const |
Is the buffer empty? | |
size_t | toMemory (const char *&memory, size_t addSize=0) const |
Write to contiguous memory. The function implies a well-defined interpretation of the input values, so it should not be called with uninitialized arguments. More... | |
bool | fromMemory (const char *memory) |
Read from the contiguous memory. | |
size_t | getMemLen () const |
Compute the necessary length of the contiguous memory block for a buffer. | |
reader & | read (reader &in) |
Prepare read stream. | |
writer & | write (writer &out) const |
Prepare write stream. | |
void | clean () |
Clear the buffer. More... | |
virtual void | closeBuff () |
Close the buffer. | |
![]() | |
iobuf (uint16 clusterSize) | |
Constructor. | |
virtual | ~iobuf () |
Destructor. | |
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 | del (FileSpace &file) |
Free space allocated for the file. | |
bool | truncate (FileSpace &file, size_t from) |
Truncate the file. More... | |
bool | speedOnClose () const |
Is to be ordered while closing. | |
void | speedOnClose (bool s) |
Set the flag of ordering while closing. | |
virtual void | free (size_t c) |
Free the cluster. | |
![]() | |
iobuf_Seq (uint16 clusterSize) | |
Constructor. | |
virtual | ~iobuf_Seq () |
Destructor. | |
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. | |
Cluster * | Add () |
Add a given element to the end of the array. | |
Cluster * | Add (const Cluster &e) |
Get the number of elements in array. | |
Cluster & | operator[] (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. | |
bool | openSys (uint8 om) |
Open the system file. | |
virtual void | close () |
Close the file. | |
ClusterReference | getCurrentClusterPos () |
Get current position in the buffer. | |
FileSpace & | sysFile () |
Get access to the system file. | |
FileSpace * | openedFile () 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 VersionContainer & | GetVersionsContainer () 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 | |
virtual int | setup () |
Set the buffer for the next cluster. | |
virtual int | flush () |
Flush the buffer. | |
void | PrepareToRead (const VersionContainer &vers) |
Initialize all the fields before reading. | |
virtual FileSpace * | enterFileSpace (uint8 level) |
Set new FileSpace for writing an object of given level. | |
virtual FileSpace * | enterFileSpace (const ClusterReference &ref, bool updateStack) |
Set position for writing/reading by given ClusterReference. If updateStack = true, push previous position to the File Spaces stack. | |
virtual FileSpace * | enterFileSpace (const ClusterReference &ref, FileSpace *file, bool updateStacke) |
Set position for writing/reading by given FileSpace and ClusterReference. Warning: in this case, ClusterReference.clusterIndex is an index in the array of cluster indices in FileSpace! If updateStack = true, push previous position to the File Spaces stack. | |
virtual FileSpace * | returnToPreviousFileSpace () |
Pop the previous FileSpace from the stack and set it up for writing/reading. | |
![]() | |
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. | |
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 | |
size_t | maxRegCount |
The maximum number of registered facilities. | |
std::vector< FileSpace * > | filesPool |
Keep all used FileSpaces (except sys, which is defined in iobuf_Seq). When using the extended format, objects of each level are saved to a separate FileSpace. Index of FileSpace in the vector corresponds to the level of the object in the model. | |
std::map< size_t, std::pair< FileSpace *, size_t > > | fileClusterIndexCache |
Cache for clusters data in FileSpace. map: cluster index in cluster array iobuf_Seq -> FileSpace data (pointer to FileSpace and index in array of cluster indices in FileSpace). | |
![]() | |
FileSpace | freed |
List of released clusters. | |
![]() | |
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< FileSpace > | files |
List of files contained in iobuf_Seq (the first element is the address of 'sys'). | |
FileSpace * | curr |
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. | |
Friends | |
reader & | operator>> (reader &in, membuf *&ptr) |
Read operator. | |
reader & | operator>> (reader &in, membuf &ref) |
Read operator. | |
writer & | operator<< (writer &out, const membuf *ptr) |
Write operator. | |
writer & | operator<< (writer &out, const membuf &ref) |
Write operator. | |
Memory stream buffer.
Memory stream buffer.
Stream memory buffer is intended for using in read and write streams. Besides the instruments needed for the buffer, it has functions for packing to a contiguous memory block, what allows to transfer files to another application via the memory.
size_t membuf::toMemory | ( | const char *& | memory, |
size_t | addSize = 0 |
||
) | const |
Write to contiguous memory. The function implies a well-defined interpretation of the input values, so it should not be called with uninitialized arguments.
[in,out] | memory | - memory to write to. If memory == nullptr, then memory is allocated. |
[in] | addSize | - size of memory, which should be allocated additionally when allocating memory. The meaning of addSize depends on the initial value of the parameter 'memory': if memory != nullptr (i.e. the memory is already allocated), then addSize should be equal to memory size (addSize >= getMemLen() !!!). if memory == nullptr, then addSize defines a number of bytes to be added (and zeroed) at the beginning when allocating memory. |
void membuf::clean | ( | ) |
Clear the buffer.
Close the buffer.