JASSv2
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
JASS::slice Class Reference

C++ slices (string-descriptors) More...

#include <slice.h>

Public Member Functions

 slice (void *pointer=nullptr, size_t length=0)
 Constructor. More...
 
 slice (void *start, void *end)
 Constructor. More...
 
 slice (const char *message)
 Constructor. Construct as a pointer to message and with length strlen(message). Does not copy, points to. More...
 
 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 memory, that is the allocator's task. More...
 
 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. This does NOT ever delete the memory, that is the allocator's task. More...
 
 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. This does NOT ever delete the memory, that is the allocator's task. More...
 
 slice (allocator &pool, const char *start)
 Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory. This does NOT ever delete the memory, that is the allocator's task. More...
 
 slice (allocator &pool, const unsigned char *start)
 Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory. This does NOT ever delete the memory, that is the allocator's task. More...
 
 slice (allocator &pool, const slice &from)
 Construct a slice by copying its contents into the pool allocator. More...
 
 slice (allocator &pool, size_t bytes)
 Construct a slice by allocating bytes of memory from a pool allocator. More...
 
 slice (allocator &pool)
 Construct an empty slice with a pool allocator. More...
 
void clear (void)
 Construct an empty slice with a pool allocator. More...
 
sliceoperator= (const slice &with)
 Operator = (asignment operator) More...
 
size_t size (void) const
 Return the length of this slice. More...
 
void * address (void) const
 Extract the pointer value from the slice. More...
 
void resize (size_t new_size)
 Change the length of the slice. More...
 
uint8_t & operator[] (size_t index) const
 Return a reference to the n'th byte past the start of the slice. More...
 
bool operator< (const slice &with) const
 Return true if this < with. More...
 
bool operator> (const slice &with) const
 Return true if this > with. More...
 
bool operator== (const slice &with) const
 Return true if this == with. More...
 

Static Public Member Functions

static bool strict_weak_order_less_than (const slice &me, const slice &with)
 Return true if this < with. More...
 
static void unittest (void)
 Unit test this class.
 

Protected Attributes

void * pointer
 The start of the data.
 
size_t length
 The length of the data (in bytes).
 

Detailed Description

C++ slices (string-descriptors)

Constructor & Destructor Documentation

◆ slice() [1/11]

JASS::slice::slice ( void *  pointer = nullptr,
size_t  length = 0 
)
inline

Constructor.

Parameters
pointer[in] The start address of the memory this slice represents.
length[in] The length (in bytes) of this slice.

◆ slice() [2/11]

JASS::slice::slice ( void *  start,
void *  end 
)
inline

Constructor.

Parameters
start[in] The start address of the memory this slice represents.
end[in] The end address of the memory this slice represents.

◆ slice() [3/11]

JASS::slice::slice ( const char *  message)
inline

Constructor. Construct as a pointer to message and with length strlen(message). Does not copy, points to.

Parameters
message[in] A pointer to a '\0' terminated 'C' string.

◆ slice() [4/11]

JASS::slice::slice ( allocator pool,
void *  start,
void *  end 
)
inline

Construct a slice by copying the data into allocator's pool of memory. This does NOT ever delete the memory, that is the allocator's task.

Parameters
pool[in] An allocator to allocate the memory from.
start[in] The start address of the memory this slice represents.
end[in] The end address of the memory this slice represents.

◆ slice() [5/11]

JASS::slice::slice ( allocator pool,
const char *  start,
const char *  end 
)
inline

Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory. This does NOT ever delete the memory, that is the allocator's task.

Parameters
pool[in] An allocator to allocate the memory from.
start[in] The start address of the C string.
end[in] The end address of the C string.

◆ slice() [6/11]

JASS::slice::slice ( allocator pool,
const unsigned char *  start,
const unsigned char *  end 
)
inline

Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory. This does NOT ever delete the memory, that is the allocator's task.

Parameters
pool[in] An allocator to allocate the memory from.
start[in] The start address of the C string.
end[in] The end address of the C string.

◆ slice() [7/11]

JASS::slice::slice ( allocator pool,
const char *  start 
)
inline

Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory. This does NOT ever delete the memory, that is the allocator's task.

Parameters
pool[in] An allocator to allocate the memory from.
start[in] The start address of the C string.

◆ slice() [8/11]

JASS::slice::slice ( allocator pool,
const unsigned char *  start 
)
inline

Construct a slice by copying and '\0' termainating a string, using the allocator's pool of memory. This does NOT ever delete the memory, that is the allocator's task.

Parameters
pool[in] An allocator to allocate the memory from.
start[in] The start address of the C string.

◆ slice() [9/11]

JASS::slice::slice ( allocator pool,
const slice from 
)
inline

Construct a slice by copying its contents into the pool allocator.

Parameters
pool[in] An allocator to allocate the memory from.
from[in] The slice to copy.

◆ slice() [10/11]

JASS::slice::slice ( allocator pool,
size_t  bytes 
)
inline

Construct a slice by allocating bytes of memory from a pool allocator.

Parameters
pool[in] An allocator to allocate from.
bytes[in] The number of bytes of memory to allocate from the pool.

◆ slice() [11/11]

JASS::slice::slice ( allocator pool)
inline

Construct an empty slice with a pool allocator.

Parameters
pool[in] An allocator to allocate from.

Member Function Documentation

◆ address()

void* JASS::slice::address ( void  ) const
inline

Extract the pointer value from the slice.

Returns
The slice's internal pointer

◆ clear()

void JASS::slice::clear ( void  )
inline

Construct an empty slice with a pool allocator.

Parameters
pool[in] An allocator to allocate from.

◆ operator<()

bool JASS::slice::operator< ( const slice with) const
inline

Return true if this < with.

The colaiting sequence is: shorter strings are "less" then longer strings. For strings of equal length memcmp() us used.

Parameters
with[in] The slice to compare to.
Returns
true if this < with, else false.

◆ operator=()

slice& JASS::slice::operator= ( const slice with)
inline

Operator = (asignment operator)

Parameters
with[in] The slice to copy to.
Returns
A reference to this slice

◆ operator==()

bool JASS::slice::operator== ( const slice with) const
inline

Return true if this == with.

Parameters
with[in] The slice to compare to.
Returns
true if this == with, else false.

◆ operator>()

bool JASS::slice::operator> ( const slice with) const
inline

Return true if this > with.

Parameters
with[in] The slice to compare to.

The colaiting sequence is: shorter strings are "less" then longer strings. For strings of equal length memcmp() us used.

Returns
true if this > with, else false.

◆ operator[]()

uint8_t& JASS::slice::operator[] ( size_t  index) const
inline

Return a reference to the n'th byte past the start of the slice.

Parameters
index[in] Which byte to return.

No safety comparison is performed. Out of range indexing will result in undefined behaviour

Returns
A reference to the byte at position specified in index.

◆ resize()

void JASS::slice::resize ( size_t  new_size)
inline

Change the length of the slice.

Parameters
new_size[in] The new size (in bytes) of the slice.

◆ size()

size_t JASS::slice::size ( void  ) const
inline

Return the length of this slice.

Returns
Slice length.

◆ strict_weak_order_less_than()

static bool JASS::slice::strict_weak_order_less_than ( const slice me,
const slice with 
)
inlinestatic

Return true if this < with.

The colaiting sequence is memcmp().

Parameters
me[in] The slice to compare.
with[in] The slice to compare to.
Returns
true if this < with, else false.

The documentation for this class was generated from the following file: