Iris Whole Slide Imaging
|
Private implementation of the reference counted data object used to wrap datablocks. More...
#include <IrisBuffer.hpp>
Public Member Functions | |
__INTERNAL__Buffer (BufferReferenceStrength) noexcept | |
__INTERNAL__Buffer (BufferReferenceStrength, size_t capacity) noexcept | |
__INTERNAL__Buffer (BufferReferenceStrength, const void *const data, size_t bytes) noexcept | |
__INTERNAL__Buffer (const __INTERNAL__Buffer &)=delete | |
__INTERNAL__Buffer & | operator= (const __INTERNAL__Buffer &)=delete |
operator void *const () const | |
Returns pointer to the beginning of the underlying data block. | |
operator bool () const | |
Operator to see if the buffer reference is valid. | |
BufferReferenceStrength | get_strength () const |
Get the reference strength to the underlying data wrapped by the buffer. | |
Result | change_strength (BufferReferenceStrength strength_to_assign) |
Change the strength of the underlying reference. | |
void * | data () const |
Returns pointer to the beginning of the underlying data block. | |
void * | end () const |
Returns a pointer to the next unwritten location in the buffer. | |
Result | prepare (size_t amount_of_bytes_to_prepare) |
Extends the capacity of the buffer without affecting the size. | |
void * | append (size_t append_by_bytes) |
Expands the size of the buffer without writing data into the expanded space. | |
Result | append (void *data, size_t size) |
Appends the end of the buffer by copying data into the buffer. | |
size_t | size () const |
Returns the current size of the buffer. | |
Result | set_size (size_t buffer_valid_size_bytes) |
Set the size object. | |
size_t | capacity () const |
Returns the total capacity of the buffer (used and unused) | |
size_t | available_bytes () const |
Returns the remaining bytes within the buffer that are unused. | |
Result | resize (size_t expected_size_bytes) |
Resize the underlying datablock. | |
Result | shrink_to_fit () |
Shrinks the underlying data block to fit the used space. | |
Private implementation of the reference counted data object used to wrap datablocks.
It can either strong reference or weak reference the underlying data. The buffer can also shift between weak and strong referrences if chosen; however, this is very dangerous obviously and you need to ensure you are tracking if you have switched from weak to strong or vice versa.
void * Iris::__INTERNAL__Buffer::append | ( | size_t | append_by_bytes | ) |
Expands the size of the buffer without writing data into the expanded space.
This expands the buffer size without actually writing any data into the new buffer space. This is useful for streaming data where you may be aware of the size of incoming data but need a space for that data (off the network card) to be copied. If this expansion goes beyond available_bytes(), the data-block will be expanded similarly to prepare(size_t).
append_by_bytes | the number of bytes by which to expand the buffer |
Result Iris::__INTERNAL__Buffer::append | ( | void * | data, |
size_t | size ) |
Appends the end of the buffer by copying data into the buffer.
This works similarly to append(size_t) but performs a copy transaction, copying the C-style array into the end of the current block.
data | C-style pointer to data array |
size | Size of data in bytes |
size_t Iris::__INTERNAL__Buffer::available_bytes | ( | ) | const |
Returns the remaining bytes within the buffer that are unused.
This value is equivalent to capacity() - size().
size_t Iris::__INTERNAL__Buffer::capacity | ( | ) | const |
Returns the total capacity of the buffer (used and unused)
Result Iris::__INTERNAL__Buffer::change_strength | ( | BufferReferenceStrength | strength_to_assign | ) |
Change the strength of the underlying reference.
If switching to STRONG reference, this buffer will become responsible for the freeing of the underlying data. Whatever mallocated the data is NO LONGER RESPONSIBLE for FREEING the underlying data. If switched to WEAK reference, the buffer will give up the responsibility to free the data and it now becomes the responsibility of the program to avoid a memory leak.
strength_to_assign | REFERENCE_WEAK or REFERENCE_STRONG |
void * Iris::__INTERNAL__Buffer::data | ( | ) | const |
void * Iris::__INTERNAL__Buffer::end | ( | ) | const |
Returns a pointer to the next unwritten location in the buffer.
This has no effect on the size of the buffer. If the buffer needs to be resized use the append(size_t) method to expand the buffer.
BufferReferenceStrength Iris::__INTERNAL__Buffer::get_strength | ( | ) | const |
Get the reference strength to the underlying data wrapped by the buffer.
Iris::__INTERNAL__Buffer::operator bool | ( | ) | const |
Operator to see if the buffer reference is valid.
Iris::__INTERNAL__Buffer::operator void *const | ( | ) | const |
Returns pointer to the beginning of the underlying data block.
Result Iris::__INTERNAL__Buffer::prepare | ( | size_t | amount_of_bytes_to_prepare | ) |
Extends the capacity of the buffer without affecting the size.
This extends the amount of data that the buffer can hold and may lead to a resizing of the data block backing the buffer but without actually expanding the size of the committed data. This is useful if you know how much data to expect but do not have that data yet. If you wish to expand the size as well, see append().
amount_of_bytes_to_prepare | the number of bytes by which to expand the buffer |
Result Iris::__INTERNAL__Buffer::resize | ( | size_t | expected_size_bytes | ) |
Resize the underlying datablock.
This is fundamentally different from calling set_size(size_t) as it actually changes the size of the backing data block by the kernel. Calling this method can invalidate the underlying data pointer.
expected_size_bytes |
Result Iris::__INTERNAL__Buffer::set_size | ( | size_t | buffer_valid_size_bytes | ) |
Set the size object.
Assign the internal size of the complete buffer to the given size in bytes. If you are simply adding some number of bytes to the buffer, use append(size) instead.
buffer_valid_size_bytes | size in bytes to set the buffer's internal tracker |
Result Iris::__INTERNAL__Buffer::shrink_to_fit | ( | ) |
Shrinks the underlying data block to fit the used space.
This is equivalent to calling resize(size()). This will not invalidate any pointers and is generally a safe way to reduce space consumption by buffers.
size_t Iris::__INTERNAL__Buffer::size | ( | ) | const |
Returns the current size of the buffer.
This is distinct from the buffer capacity