43 slice(
void *pointer =
nullptr,
size_t length = 0) :
61 length((uint8_t *)end - (uint8_t *)start)
75 pointer((void *)message),
76 length(strlen(message))
93 length = (uint8_t *)end - (uint8_t *)start;
94 pointer = (
void *)pool.
malloc(length);
95 memcpy(pointer, start, length);
110 length = end - start;
111 pointer = (
void *)pool.
malloc(length + 1);
112 memcpy(pointer, start, length);
113 ((
char *)pointer)[
length] =
'\0';
128 length = end - start;
129 pointer = (
void *)pool.
malloc(length + 1);
130 memcpy(pointer, start, length);
131 ((
char *)pointer)[
length] =
'\0';
145 length = strlen(start);
146 pointer = (
void *)pool.
malloc(length + 1);
147 memcpy(pointer, start, length);
148 ((
char *)pointer)[
length] =
'\0';
162 length = strlen(reinterpret_cast<const char *>(start));
163 pointer = (
void *)pool.
malloc(length + 1);
164 memcpy(pointer, start, length);
165 ((
char *)pointer)[
length] =
'\0';
179 length = from.
size();
180 pointer = (
void *)pool.
malloc(length);
194 pointer((void *)pool.malloc(bytes)),
299 return ((uint8_t *)pointer)[index];
323 return cmp < 0 ? true :
false;
331 return cmp < 0 ? true :
false;
402 JASS_assert(chunk2.address() == unittest && chunk2.size() == 5);
406 slice chunk3(pool, (
void *)data, (
void *)((uint8_t *)data + 5));
409 const char *message =
"here there and everywhere";
410 slice chunk4(pool, message, message + 4);
415 slice chunk5(pool, message);
416 JASS_assert(pool.size() == 36 && strcmp((
char *)chunk5.address(), message) == 0);
418 slice chunk6(pool, 10);
450 puts(
"slice::PASSED");
void resize(size_t new_size)
Change the length of the slice.
Definition: slice.h:282
slice(const char *message)
Constructor. Construct as a pointer to message and with length strlen(message). Does not copy...
Definition: slice.h:74
static bool strict_weak_order_less_than(const slice &me, const slice &with)
Return true if this < with.
Definition: slice.h:313
size_t length
The length of the data (in bytes).
Definition: slice.h:31
slice(allocator &pool, void *start, void *end)
Construct a slice by copying the data into allocator's pool of memory. This does NOT ever delete the ...
Definition: slice.h:91
bool operator<(const slice &with) const
Return true if this < with.
Definition: slice.h:345
C++ slices (string-descriptors)
Definition: slice.h:27
replacement for the C runtime library assert that also works in release.
void * address(void) const
Extract the pointer value from the slice.
Definition: slice.h:269
bool operator>(const slice &with) const
Return true if this > with.
Definition: slice.h:364
#define JASS_assert(expression)
Drop in replacement for assert() that aborts in Release as well as Debug.
Definition: asserts.h:33
slice(allocator &pool, const unsigned char *start)
Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory...
Definition: slice.h:160
slice(void *pointer=nullptr, size_t length=0)
Constructor.
Definition: slice.h:43
slice(allocator &pool, const char *start)
Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory...
Definition: slice.h:143
void clear(void)
Construct an empty slice with a pool allocator.
Definition: slice.h:223
slice(allocator &pool)
Construct an empty slice with a pool allocator.
Definition: slice.h:208
Simple block-allocator that internally allocates a large chunk then allocates smaller blocks from thi...
Definition: allocator_pool.h:61
Virtual base class for C style allocators.
Definition: allocator.h:33
virtual void * malloc(size_t bytes, size_t alignment=alignment_boundary)=0
Allocate a small chunk of memory from the internal pool and return a pointer to the caller...
slice(allocator &pool, size_t bytes)
Construct a slice by allocating bytes of memory from a pool allocator.
Definition: slice.h:193
Simple block-allocator that internally allocates a large chunk then allocates smaller blocks from thi...
slice(allocator &pool, const unsigned char *start, const unsigned char *end)
Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory...
Definition: slice.h:126
void * pointer
The start of the data.
Definition: slice.h:30
slice(allocator &pool, const char *start, const char *end)
Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory...
Definition: slice.h:108
uint8_t & operator[](size_t index) const
Return a reference to the n'th byte past the start of the slice.
Definition: slice.h:297
slice & operator=(const slice &with)
Operator = (asignment operator)
Definition: slice.h:240
bool operator==(const slice &with) const
Return true if this == with.
Definition: slice.h:382
Definition: compress_integer_elias_delta_simd.c:23
static std::ostream & operator<<(std::ostream &output, JASS_anytime_stats &data)
Dump a human readable version of the data down an output stream.
Definition: JASS_anytime_stats.h:62
size_t size(void) const
Return the length of this slice.
Definition: slice.h:256
static void unittest(void)
Unit test this class.
Definition: slice.h:396
slice(allocator &pool, const slice &from)
Construct a slice by copying its contents into the pool allocator.
Definition: slice.h:177
slice(void *start, void *end)
Constructor.
Definition: slice.h:59