OpenEnroth 73e68f7
|
#include <Blob.h>
Public Member Functions | |
Blob () | |
Blob (const Blob &)=delete | |
Blob (Blob &&other) | |
~Blob ()=default | |
Blob & | operator= (const Blob &)=delete |
Blob & | operator= (Blob &&other) |
Blob | subBlob (size_t offset, size_t size=-1) const |
size_t | size () const |
bool | empty () const |
const void * | data () const |
bool | operator! () const |
operator bool () const | |
std::string_view | string_view () const |
const std::string & | displayPath () const |
Blob | withDisplayPath (std::string_view displayPath) |
Static Public Member Functions | |
static Blob | fromMalloc (const void *data, size_t size) |
static Blob | fromMalloc (std::unique_ptr< void, FreeDeleter > data, size_t size) |
static Blob | fromFile (std::string_view path) |
static Blob | fromString (std::string string) |
static Blob | copy (const void *data, size_t size) |
static Blob | copy (const Blob &other) |
static Blob | view (const void *data, size_t size) |
static Blob | view (std::string_view data) |
static Blob | read (FILE *file, size_t size) |
static Blob | read (InputStream *stream, size_t size) |
static Blob | concat (const Blob &l, const Blob &r) |
static Blob | share (const Blob &other) |
Private Attributes | |
const void * | _data = nullptr |
size_t | _size = 0 |
std::shared_ptr< void > | _state |
std::string | _displayPath |
Friends | |
void | swap (Blob &l, Blob &r) |
Blob
is an abstraction that couples a contiguous memory region with the knowledge of how to deallocate it.
Deallocation is type-erased (like it's done in std::shared_ptr
), so you don't have to pass in deleter as a template parameter.
For debug and error reporting purposes, Blob
also stores a string describing the data source.
|
inline |
|
delete |
|
inline |
|
default |
l | First blob. |
r | Second blob. |
|
static |
data | Memory region pointer. |
size | Memory region size. |
|
inline |
|
inline |
|
inline |
|
static |
path | Path to a file. |
path
. std::runtime_error | If file doesn't exist or on some other OS error. |
|
static |
|
static |
|
static |
string | String to create a blob from. |
|
inlineexplicit |
|
inline |
|
static |
|
static |
|
inline |
|
inline |
Blob Blob::subBlob | ( | size_t | offset, |
size_t | size = -1 |
||
) | const |
Pretty much like substr
, but for Blob
s.
Important difference from substr
is that the underlying memory is not copied and is instead shared between the two blobs. It will be freed when both are destroyed, so cases where a small subblob holds a 100Mb chunk of memory are possible, be careful.
Also, this function doesn't throw std::out_of_range
if offset
is larger than the blob's size, returning an empty blob in this case instead.
offset | Offset in the blob. |
size | Size of the subblob. |
|
static |
data | Memory region pointer. |
size | Memory region size. |
|
static |
data | Memory region |
|
inline |
|
private |
|
private |
|
private |
|
private |