Base class for defining input and output binary streams. More...

Public Member Functions | |
char * | data () |
const char * | data () const |
bool | eof () const |
std::size_t | getCapacity () const |
int | getChunkCount () |
int | getChunkSize () |
std::size_t | getSize () const |
bool | seekg (std::size_t pos) |
bool | seekg (std::streamoff offset, std::ios_base::seekdir way) |
virtual void | setSize (std::size_t size) |
std::streampos | tellg () const |
Protected Member Functions | |
BinaryStream () | |
BinaryStream (const char *buffer, std::size_t capacity) | |
BinaryStream (const std::vector< char > &buffer) | |
BinaryStream (std::size_t capacity) | |
void | open (const char *buffer, std::size_t capacity) |
void | open (std::size_t capacity) |
void | setCapacity (std::size_t capacity) |
Protected Attributes | |
std::vector< char > | m_buffer |
std::size_t | m_pos |
std::size_t | m_size |
Detailed Description
Base class for defining input and output binary streams.
Definition at line 83 of file binary_stream.hpp.
Constructor & Destructor Documentation
◆ BinaryStream() [1/4]
|
protected |
◆ BinaryStream() [2/4]
|
protected |
Constructor.
Initialize an empty binary stream with the assigned size.
- Parameters
-
[in] size is the requested stream size
Definition at line 100 of file binary_stream.cpp.
◆ BinaryStream() [3/4]
|
protected |
Constructor.
Initialize a binary stream with the data contained in the specified buffer. The data is copied from the input buffer to the internal buffer.
- Parameters
-
[in] buffer is the buffer that contains the data [in] capacity is the data capacity
Definition at line 115 of file binary_stream.cpp.
◆ BinaryStream() [4/4]
|
protected |
Constructor.
Initialize a binary stream with the data contained in the specified buffer. The data is copied from the input buffer to the internal buffer.
- Parameters
-
[in] buffer is the buffer that contains the data
Definition at line 128 of file binary_stream.cpp.
Member Function Documentation
◆ data() [1/2]
char * bitpit::BinaryStream::data | ( | ) |
Get a pointer the internal data.
- Returns
- A pointer to the internal data.
Definition at line 191 of file binary_stream.cpp.
◆ data() [2/2]
const char * bitpit::BinaryStream::data | ( | ) | const |
Get a cnstant pointer the internal data.
- Returns
- A constant pointer to the internal data.
Definition at line 201 of file binary_stream.cpp.
◆ eof()
bool bitpit::BinaryStream::eof | ( | ) | const |
Returns true if end of file condition is met.
- Returns
- Returns true if end of file condition is met, false otherwise.
Definition at line 211 of file binary_stream.cpp.
◆ getCapacity()
std::size_t bitpit::BinaryStream::getCapacity | ( | ) | const |
Returns the size of the storage space currently allocated for the stream, expressed in bytes.
Capacity is not necessarily equal to the stream size; it can be equal or greater. The extra space can not be used for storing data, but can be used to guarantee a minimum internal storage size.
Notice that this capacity does not suppose a limit on the size of the stream. When this capacity is exhausted and more is needed, it is automatically expanded by the (reallocating it storage space).
- Returns
- The size of the storage space currently allocated for the stream, expressed in bytes.
Definition at line 332 of file binary_stream.cpp.
◆ getChunkCount()
int bitpit::BinaryStream::getChunkCount | ( | ) |
Get the number of chuncks contained in the stream.
The stream will automaticall adjust its capacity to always fit an integer number of chunks.
NOTE: by design the number of chunk needs to be an integer. The reason being that this parameter has to be passed to some function that expects an integer number (i.e., MPI functions can only send/receive an integer number of items).
- Returns
- The number of chuncks contained in the stream.
Definition at line 312 of file binary_stream.cpp.
◆ getChunkSize()
int bitpit::BinaryStream::getChunkSize | ( | ) |
Get chunk size value
NOTE: by design the number of chunk needs to be an integer. The reason being that this parameter has to be passed to some function that expects an integer number (i.e., MPI functions can only build new data-types composed by an integer number of items).
- Returns
- The chunk size.
Definition at line 294 of file binary_stream.cpp.
◆ getSize()
std::size_t bitpit::BinaryStream::getSize | ( | ) | const |
Return the size of the stream, expressed in bytes.
- Returns
- The size of the stream, expressed in bytes.
Definition at line 243 of file binary_stream.cpp.
◆ open() [1/2]
|
protected |
Open a binary stream initializing it with the data contained in the specified buffer.
- Parameters
-
[in] buffer is the buffer that contains the data [in] size is the size (in bytes) of the data
Definition at line 140 of file binary_stream.cpp.
◆ open() [2/2]
|
protected |
Open a binary stream with the specified size.
- Parameters
-
[in] size is the buffer size
Definition at line 152 of file binary_stream.cpp.
◆ seekg() [1/2]
bool bitpit::BinaryStream::seekg | ( | std::size_t | pos | ) |
Set the cursor position within the stream.
- Parameters
-
[in] pos is the cursor new position
- Returns
- Returns true if new position is valid, false otherwise.
Definition at line 175 of file binary_stream.cpp.
◆ seekg() [2/2]
bool bitpit::BinaryStream::seekg | ( | std::streamoff | offset, |
std::ios_base::seekdir | way ) |
Set the cursor position within the stream.
- Parameters
-
[in] offset is the offset value, relative to the way parameter [in] way is the offset direction
- Returns
- Returns rue if new position is valid, false otherwise.
Definition at line 223 of file binary_stream.cpp.
◆ setCapacity()
|
protected |
Requests that the stream capacity be at least the specified number of bytes.
The function will guarantee that the capacity of the buffer will always contain an integer number of chunks and that the number of chunks will fit in an 'int' type of variable. To obtain this, when the requested capacity is greater than the maximum integer value, the buffer is allocated in chunks of 2^n bytes, where n is choosen to obtain a number of chunks that fits in an 'int' type of variable.
- Parameters
-
[in] capacity is the new size (in bytes) of the stream
Definition at line 272 of file binary_stream.cpp.
◆ setSize()
|
virtual |
Set the size of the stream, expressed in bytes.
- Parameters
-
[in] size is the new size (in bytes) of the stream
Reimplemented in bitpit::OBinaryStream.
Definition at line 253 of file binary_stream.cpp.
◆ tellg()
std::streampos bitpit::BinaryStream::tellg | ( | ) | const |
Returns the cursor position within the stream.
- Returns
- Returns the cursor position within the stream.
Definition at line 164 of file binary_stream.cpp.
Member Data Documentation
◆ m_buffer
|
protected |
Definition at line 106 of file binary_stream.hpp.
◆ m_pos
|
protected |
Definition at line 108 of file binary_stream.hpp.
◆ m_size
|
protected |
Definition at line 107 of file binary_stream.hpp.
The documentation for this class was generated from the following files:
- src/containers/binary_stream.hpp
- src/containers/binary_stream.cpp
