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=NULL, 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 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...
 
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 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/9]

JASS::slice::slice ( void *  pointer = NULL,
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/9]

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/9]

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/9]

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/9]

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/9]

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() [7/9]

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() [8/9]

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() [9/9]

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

§ 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.
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.
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.
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.

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