Support Forum G3D Web Page |
Very fast string class that follows the std::string
/std::basic_string
interface.
More...
Public Types | |
typedef const char * | const_iterator |
typedef const char * | const_pointer |
typedef const char & | const_reference |
typedef ptrdiff_t | difference_type |
typedef char * | iterator |
typedef char * | pointer |
typedef char & | reference |
typedef size_t | size_type |
typedef std::char_traits< char > | traits_type |
typedef char | value_type |
Public Member Functions | |
G3DString () | |
Creates a zero-length string. More... | |
G3DString (const value_type c) | |
G3DString (size_t count, const value_type c) | |
G3DString (G3DString &&s) | |
G3DString (const G3DString &s) | |
G3DString (const std::string &s) | |
G3DString (const value_type *c) | |
G3DString (const value_type *c, size_t len) | |
~G3DString () | |
G3DString & | append (const G3DString &s, size_t subpos, size_t sublen) |
G3DString & | append (const G3DString &s) |
G3DString & | append (size_t n, value_type c) |
G3DString & | append (const value_type *c, size_t t) |
G3DString & | append (const value_type *c) |
G3DString & | assign (const G3DString &s) |
G3DString & | assign (const G3DString &s, size_t subpos, size_t sublen) |
G3DString & | assign (const value_type *c, size_t n) |
G3DString & | assign (size_t n, const value_type c) |
const_reference | at (size_t x) const |
reference | at (size_t x) |
const_reference | back () const |
reference | back (size_t x) |
iterator | begin () |
const value_type * | c_str () const |
size_type | capacity () const |
const_iterator | cbegin () const |
const_iterator | cend () const |
void | clear () |
int | compare (const G3DString &str) const |
int | compare (size_t pos, size_t len, const G3DString &str) const |
int | compare (size_t pos, size_t len, const G3DString &str, size_t subpos, size_t sublen) const |
int | compare (const char *s) const |
int | compare (size_t pos, size_t len, const char *s) const |
int | compare (size_t pos, size_t len, const char *s, size_t n) const |
const value_type * | data () const |
bool | empty () const |
iterator | end () |
G3DString & | erase (size_t pos=0, size_t len=npos) |
size_t | find (const G3DString &str, size_t pos=0) const |
size_t | find (const char *s, size_t pos=0) const |
size_t | find (const char *s, size_t pos, size_t n) const |
size_t | find (char c, size_t pos=0) const |
size_t | find_first_of (const value_type *s, size_t pos, size_t n) const |
size_t | find_first_of (const G3DString &str, size_t pos=0) const |
size_t | find_first_of (const value_type *s, size_t pos=0) const |
size_t | find_first_of (value_type c, size_t pos=0) const |
size_t | find_last_of (const value_type *s, size_t pos, size_t n) const |
size_t | find_last_of (const G3DString &str, size_t pos=npos) const |
size_t | find_last_of (const value_type *s, size_t pos=npos) const |
size_t | find_last_of (value_type c, size_t pos=npos) const |
const_reference | front () const |
reference | front (size_t x) |
G3DString & | insert (size_t pos, const G3DString &str, size_t subpos, size_t sublen) |
G3DString & | insert (size_t pos, const G3DString &str) |
G3DString & | insert (size_t pos, const value_type *c) |
size_type | length () const |
size_type | max_size () const |
bool | operator!= (const G3DString &s) const |
bool | operator!= (const value_type *c) const |
G3DString | operator+ (const G3DString &s) const |
G3DString | operator+ (const value_type *c) const |
G3DString | operator+ (const value_type c) const |
G3DString & | operator+= (const G3DString &s) |
G3DString & | operator+= (const value_type c) |
G3DString & | operator+= (const value_type *c) |
bool | operator< (const G3DString &s) const |
G3DString & | operator= (const value_type *c) |
G3DString & | operator= (const G3DString &s) |
G3DString & | operator= (G3DString &&s) |
bool | operator== (const G3DString &s) const |
bool | operator== (const value_type *c) const |
bool | operator> (const G3DString &s) const |
const_reference | operator[] (size_t x) const |
reference | operator[] (size_t x) |
void | push_back (value_type c) |
void | reserve (size_t newLength) |
size_t | rfind (const G3DString &str, size_t pos=npos) const |
size_t | rfind (const char *s, size_t pos=npos) const |
size_t | rfind (const char *s, size_t pos, size_t n) const |
size_t | rfind (char c, size_t pos=npos) const |
size_type | size () const |
G3DString | substr (size_t pos=0, size_t len=npos) const |
Static Public Attributes | |
static const size_type | npos = size_type(-1) |
Protected Member Functions | |
value_type * | alloc (size_t b) |
Total size to allocate, including the terminator. More... | |
void | ensureAllocation (size_t newSize, bool copyOldData) |
Ensures that there is enough space for newSize characters in the string (newSize + 1 bytes for the terminator). More... | |
void | free (value_type *p) const |
Only frees if the value was not in the const segment or m_buffer. More... | |
bool | inBuffer (const char *ptr) const |
bool | inBuffer () const |
bool | inConst () const |
Optimized to assume the invariant holds and only check m_allocated. More... | |
void | maybeDeallocate () |
void | prepareToMutate () |
void | testInvariants () const |
Static Protected Member Functions | |
static size_t | chooseAllocationSize (size_t L) |
Choose the number of bytes to allocate to hold a string of length L characters. More... | |
static bool | inConst (const char *ptr) |
static void | memcpy (void *dst, const void *src, size_t len) |
static void | memcpyBuffer (void *dst, const void *src) |
Copies from one m_data to another where both are in the m_buffer of the corresponding string and have 16-byte alignment. More... | |
Protected Attributes | |
size_t | m_allocated |
Total size of m_data, including '\0'... More... | |
char | m_buffer [INTERNAL_SIZE+MAX_ALIGNMENT_PADDING] |
This inline storage is used when strings are small. More... | |
value_type * | m_data |
The current value of this string. More... | |
size_t | m_length |
Bytes to, but not including, '\0'. More... | |
Very fast string class that follows the std::string
/std::basic_string
interface.
Assumes 8-byte (64-bit) alignment of the String (G3DString
) class, and only corrects by up to 8 bytes to ensure 16-byte SSE alignment. This is the default behavior for compilers generating 64-bit code. If you need to use this class with a 32-bit target or inside of a packed block, then it must be modified with additional padding.
typedef const char* G3D::G3DString< INTERNAL_SIZE >::const_iterator |
typedef const char* G3D::G3DString< INTERNAL_SIZE >::const_pointer |
typedef const char& G3D::G3DString< INTERNAL_SIZE >::const_reference |
typedef ptrdiff_t G3D::G3DString< INTERNAL_SIZE >::difference_type |
typedef char* G3D::G3DString< INTERNAL_SIZE >::iterator |
typedef char* G3D::G3DString< INTERNAL_SIZE >::pointer |
typedef char& G3D::G3DString< INTERNAL_SIZE >::reference |
typedef size_t G3D::G3DString< INTERNAL_SIZE >::size_type |
typedef std::char_traits<char> G3D::G3DString< INTERNAL_SIZE >::traits_type |
typedef char G3D::G3DString< INTERNAL_SIZE >::value_type |
|
inline |
Creates a zero-length string.
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inlineexplicit |
|
inline |
|
inline |
len | Copy len characters from c. |
|
inline |
|
inlineprotected |
Total size to allocate, including the terminator.
If b <= INTERNAL_SIZE, allocates INTERNAL_SIZE using m_buffer, otherwise allocates exactly b bytes on the heap.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinestaticprotected |
Choose the number of bytes to allocate to hold a string of length L characters.
i.e., allocate one extra byte, and then decide if it should just use the internal buffer. If not in the internal buffer, allocate at least 64 bytes, or 2*L + 1, so that appends can be fast.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprotected |
Ensures that there is enough space for newSize characters in the string (newSize + 1 bytes for the terminator).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprotected |
Only frees if the value was not in the const segment or m_buffer.
|
inline |
|
inline |
|
inlineprotected |
|
inlineprotected |
|
inlinestaticprotected |
|
inlineprotected |
Optimized to assume the invariant holds and only check m_allocated.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprotected |
|
inlinestaticprotected |
|
inlinestaticprotected |
Copies from one m_data to another where both are in the m_buffer of the corresponding string and have 16-byte alignment.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprotected |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprotected |
|
protected |
Total size of m_data, including '\0'...
or 0 if m_data is in a const segment. If m_data is a pointer into m_buffer, then m_allocated will be INTERNAL_SIZE.
Referenced by G3D::G3DString< INTERNAL_SIZE >::assign().
|
protected |
This inline storage is used when strings are small.
Only INTERNAL_SIZE bytes are used, but m_data may point up to MAX_ALIGNMENT_PADDING bytes into this array to ensure 16-byte (SSE) alignment. Note that the m_buffer array must appear first in the String class to match the allocator's guaranteed 8-byte alignment, reducing the alignment that each instance is required to perform.
|
protected |
The current value of this string.
Includes '\0' termination.
Referenced by G3D::G3DString< INTERNAL_SIZE >::append(), G3D::G3DString< INTERNAL_SIZE >::assign(), G3D::G3DString< INTERNAL_SIZE >::compare(), G3D::G3DString< INTERNAL_SIZE >::G3DString(), G3D::G3DString< INTERNAL_SIZE >::operator+(), G3D::G3DString< INTERNAL_SIZE >::operator+=(), G3D::G3DString< INTERNAL_SIZE >::operator=(), and G3D::G3DString< INTERNAL_SIZE >::operator==().
|
protected |
Bytes to, but not including, '\0'.
Referenced by G3D::G3DString< INTERNAL_SIZE >::compare(), G3D::G3DString< INTERNAL_SIZE >::find(), G3D::G3DString< INTERNAL_SIZE >::operator+(), G3D::G3DString< INTERNAL_SIZE >::operator+=(), G3D::G3DString< INTERNAL_SIZE >::operator=(), G3D::G3DString< INTERNAL_SIZE >::operator==(), and G3D::G3DString< INTERNAL_SIZE >::rfind().
|
static |