![]() |
Max OS 0.3
|
Wrapper class for a region of bytes in memor in an attempt to add some memory safety. Automatically allocates the size specified and frees it once done, adds boundary to I/O. More...
#include <buffer.h>
Public Member Functions | |
| Buffer (size_t size, bool update_offset=true) | |
| Creates a buffer of the specified size. | |
| Buffer (void *source, size_t size, bool update_offset=true) | |
| Creates a buffer pointing to a source. | |
| ~Buffer () | |
| Destroy the buffer, freeing the memory. | |
| uint8_t * | raw () const |
| The raw pointer to the bytes stored in memory, use is not recommended. | |
| void | clear () |
| Fulls the buffer with 0's and resets the offset. | |
| void | full (uint8_t byte, size_t offset=0, size_t amount=0) |
| Full the buffer with a specified byte at an offset. | |
| void | set_offset (size_t offset) |
| Set the offset for where operations should begin from. | |
| size_t | capacity () const |
| The max bytes the buffer can currently store. | |
| void | resize (size_t size) |
| Grow the buffer to fit a new size. | |
| void | write (uint8_t byte) |
| Safely writes a byte to the buffer at the current offset. | |
| void | write (size_t offset, uint8_t byte) |
| Safely writes a byte to the buffer at the specified offset. | |
| uint8_t | read () |
| Safely reads a byte from the buffer at the current offset. | |
| uint8_t | read (size_t offset) |
| Safely reads a byte from the buffer at the specified offset. | |
| void | copy_from (const Buffer *buffer) |
| Copies all the bytes from another buffer into this buffer. | |
| void | copy_from (const Buffer *buffer, size_t length) |
| Copies a range of bytes from another buffer into this buffer. | |
| void | copy_from (const Buffer *buffer, size_t length, size_t offset) |
| Copies a range of bytes from another buffer into this buffer at a specified offset. | |
| void | copy_from (const Buffer *buffer, size_t length, size_t offset, size_t offset_other) |
| Copies a range of bytes from another buffer into this buffer at a specified offset for both. | |
| void | copy_from (const void *source, size_t length) |
| Copies a range of bytes from a source into this buffer. | |
| void | copy_from (const void *source, size_t length, size_t offset) |
| Copies a range of bytes from a source into this buffer at a specified offset. | |
| void | copy_to (Buffer *buffer) |
| Copies all the bytes from this buffer into another buffer. | |
| void | copy_to (Buffer *buffer, size_t length) |
| Writes a range of bytes from this buffer into another buffer. | |
| void | copy_to (Buffer *buffer, size_t length, size_t offset) |
| Copies a range of bytes from this buffer into another buffer at a specified offset. | |
| void | copy_to (Buffer *buffer, size_t length, size_t offset, size_t offset_other) |
| Copies a range of bytes from this buffer into another at an offset for each. | |
| void | copy_to (void *destination, size_t length) |
| Copies a range of bytes from this buffer into a source. | |
| void | copy_to (void *destination, size_t length, size_t offset) |
| Copies a range of bytes from this buffer at an offset into a source. | |
Public Attributes | |
| bool | update_offset = true |
| Should operations write/read/copy update the offset in the buffer? | |
Wrapper class for a region of bytes in memor in an attempt to add some memory safety. Automatically allocates the size specified and frees it once done, adds boundary to I/O.
Creates a buffer of the specified size.
| size | The capacity of the buffer |
| update_offset | Should operations update the offset of the buffer? |
Definition at line 20 of file buffer.cpp.
Creates a buffer pointing to a source.
| source | The source |
| size | The capacity of the source |
| update_offset | Should buffer operations update the internal offset? |
Definition at line 36 of file buffer.cpp.
| Buffer::~Buffer | ( | ) |
Destroy the buffer, freeing the memory.
Definition at line 48 of file buffer.cpp.
| size_t Buffer::capacity | ( | ) | const |
The max bytes the buffer can currently store.
Definition at line 95 of file buffer.cpp.
Referenced by copy_from(), copy_from(), copy_from(), copy_from(), copy_to(), copy_to(), copy_to(), copy_to(), read(), write(), and MaxOS::drivers::disk::Disk::write().
| void Buffer::clear | ( | ) |
Fulls the buffer with 0's and resets the offset.
Definition at line 65 of file buffer.cpp.
References memset().
Referenced by MaxOS::filesystem::format::Fat32File::read(), and MaxOS::filesystem::format::Fat32File::write().
Copies all the bytes from another buffer into this buffer.
| buffer | Where to read from |
Definition at line 195 of file buffer.cpp.
References ASSERT, capacity(), copy_from(), and raw().
Referenced by copy_from(), copy_from(), copy_from(), copy_from(), MaxOS::filesystem::format::Fat32File::read(), MaxOS::filesystem::format::ext2::Ext2File::write(), MaxOS::filesystem::format::Fat32File::write(), and MaxOS::filesystem::format::ext2::Ext2Volume::write_inode().
Copies a range of bytes from another buffer into this buffer.
| buffer | Where to read from |
| length | How much to read |
Definition at line 209 of file buffer.cpp.
References ASSERT, capacity(), copy_from(), and raw().
Copies a range of bytes from another buffer into this buffer at a specified offset.
| buffer | Where to read from |
| length | How much to read |
| offset | Where to start writing into this at |
Definition at line 223 of file buffer.cpp.
References ASSERT, capacity(), copy_from(), and raw().
Copies a range of bytes from another buffer into this buffer at a specified offset for both.
| buffer | Where to read from |
| length | How much to read |
| offset | Where to start writing into this at |
| offset_other | Where to start reading from the other buffer |
Definition at line 239 of file buffer.cpp.
References ASSERT, capacity(), copy_from(), and raw().
Copies a range of bytes from a source into this buffer.
| source | Where to read from |
| length | How much to read |
Definition at line 253 of file buffer.cpp.
References ASSERT, memcpy(), and set_offset().
Copies a range of bytes from a source into this buffer at a specified offset.
| source | Where to read from |
| length | How much to read |
| offset | Where to start writing at |
Definition at line 268 of file buffer.cpp.
References ASSERT, memcpy(), and set_offset().
Copies all the bytes from this buffer into another buffer.
| buffer | Where to write to |
Definition at line 282 of file buffer.cpp.
References ASSERT, capacity(), copy_to(), and raw().
Referenced by copy_to(), copy_to(), copy_to(), copy_to(), MaxOS::filesystem::format::ext2::Ext2File::read(), and MaxOS::filesystem::format::ext2::Ext2Volume::read_inode().
Writes a range of bytes from this buffer into another buffer.
| buffer | Where to write to |
| length | How much to write |
Definition at line 296 of file buffer.cpp.
References ASSERT, capacity(), copy_to(), and raw().
Copies a range of bytes from this buffer into another buffer at a specified offset.
| buffer | Where to write to |
| length | How much to write |
| offset | Where to start reading at |
Definition at line 311 of file buffer.cpp.
References ASSERT, capacity(), copy_to(), and raw().
Copies a range of bytes from this buffer into another at an offset for each.
| buffer | Where to write to |
| length | How much to write |
| offset | Where to start reading from |
| offset_other | Where to start writing to |
Definition at line 327 of file buffer.cpp.
References ASSERT, capacity(), copy_to(), and raw().
Copies a range of bytes from this buffer into a source.
| destination | Where to write to |
| length | How much to write |
Definition at line 342 of file buffer.cpp.
References ASSERT, memcpy(), and set_offset().
Copies a range of bytes from this buffer at an offset into a source.
| destination | Where to write to |
| length | How much to write |
| offset | Where to start reading from |
Definition at line 358 of file buffer.cpp.
References ASSERT, memcpy(), and set_offset().
Full the buffer with a specified byte at an offset.
| byte | The byte to write |
| offset | Where to start writing (deafults to 0) |
| amount |
Definition at line 78 of file buffer.cpp.
| uint8_t * Buffer::raw | ( | ) | const |
The raw pointer to the bytes stored in memory, use is not recommended.
Definition at line 57 of file buffer.cpp.
Referenced by copy_from(), copy_from(), copy_from(), copy_from(), copy_to(), copy_to(), copy_to(), and copy_to().
| uint8_t Buffer::read | ( | ) |
Safely reads a byte from the buffer at the current offset.
Definition at line 168 of file buffer.cpp.
References set_offset().
Referenced by MaxOS::drivers::disk::AdvancedTechnologyAttachment::write().
Safely reads a byte from the buffer at the specified offset.
| offset | The offset into the buffer storage array |
Definition at line 180 of file buffer.cpp.
References ASSERT, capacity(), and set_offset().
Grow the buffer to fit a new size.
| size | The new max capacity of the buffer |
Definition at line 104 of file buffer.cpp.
References memcpy().
Set the offset for where operations should begin from.
| offset | The new offset |
Definition at line 128 of file buffer.cpp.
References update_offset.
Referenced by copy_from(), copy_from(), copy_to(), copy_to(), read(), MaxOS::filesystem::format::Fat32File::read(), read(), MaxOS::filesystem::format::ext2::Ext2Volume::read_block(), MaxOS::filesystem::format::Fat32File::write(), write(), write(), and MaxOS::filesystem::format::ext2::Ext2Volume::write_block().
Safely writes a byte to the buffer at the specified offset.
| offset | The offset into the buffer storage array |
| byte | The byte to write |
Definition at line 152 of file buffer.cpp.
References ASSERT, capacity(), and set_offset().
Safely writes a byte to the buffer at the current offset.
| byte | The byte to write |
Definition at line 140 of file buffer.cpp.
References set_offset().
Should operations write/read/copy update the offset in the buffer?
Definition at line 44 of file buffer.h.
Referenced by set_offset(), and MaxOS::filesystem::format::ext2::Ext2Volume::write_block().