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 |
Base class for defining input and output binary streams.
Definition at line 83 of file binary_stream.hpp.
|
protected |
|
protected |
Constructor.
Initialize an empty binary stream with the assigned size.
[in] | size | is the requested stream size |
Definition at line 100 of file binary_stream.cpp.
|
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.
[in] | buffer | is the buffer that contains the data |
[in] | capacity | is the data capacity |
Definition at line 115 of file binary_stream.cpp.
|
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.
[in] | buffer | is the buffer that contains the data |
Definition at line 128 of file binary_stream.cpp.
char * bitpit::BinaryStream::data | ( | ) |
Get a pointer the internal data.
Definition at line 191 of file binary_stream.cpp.
const char * bitpit::BinaryStream::data | ( | ) | const |
Get a cnstant pointer the internal data.
Definition at line 201 of file binary_stream.cpp.
bool bitpit::BinaryStream::eof | ( | ) | const |
Returns true if end of file condition is met.
Definition at line 211 of file binary_stream.cpp.
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).
Definition at line 332 of file binary_stream.cpp.
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).
Definition at line 312 of file binary_stream.cpp.
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).
Definition at line 294 of file binary_stream.cpp.
std::size_t bitpit::BinaryStream::getSize | ( | ) | const |
Return the size of the stream, expressed in bytes.
Definition at line 243 of file binary_stream.cpp.
|
protected |
Open a binary stream initializing it with the data contained in the specified buffer.
[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.
|
protected |
Open a binary stream with the specified size.
[in] | size | is the buffer size |
Definition at line 152 of file binary_stream.cpp.
bool bitpit::BinaryStream::seekg | ( | std::size_t | pos | ) |
Set the cursor position within the stream.
[in] | pos | is the cursor new position |
Definition at line 175 of file binary_stream.cpp.
bool bitpit::BinaryStream::seekg | ( | std::streamoff | offset, |
std::ios_base::seekdir | way ) |
Set the cursor position within the stream.
[in] | offset | is the offset value, relative to the way parameter |
[in] | way | is the offset direction |
Definition at line 223 of file binary_stream.cpp.
|
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.
[in] | capacity | is the new size (in bytes) of the stream |
Definition at line 272 of file binary_stream.cpp.
|
virtual |
Set the size of the stream, expressed in bytes.
[in] | size | is the new size (in bytes) of the stream |
Reimplemented in bitpit::OBinaryStream.
Definition at line 253 of file binary_stream.cpp.
std::streampos bitpit::BinaryStream::tellg | ( | ) | const |
Returns the cursor position within the stream.
Definition at line 164 of file binary_stream.cpp.
|
protected |
Definition at line 106 of file binary_stream.hpp.
|
protected |
Definition at line 108 of file binary_stream.hpp.
|
protected |
Definition at line 107 of file binary_stream.hpp.