|
BDE 4.14.0 Production release
|
#include <bslstl_string.h>
Public Types | |
| enum | ShortBufferConstraints { SHORT_BUFFER_MIN_BYTES = 20 , SHORT_BUFFER_NEED_BYTES } |
| enum | ConfigurableParameters { BASIC_STRING_DEALLOCATE_IN_CLEAR = false , BASIC_STRING_HONOR_SHRINK_REQUEST = false } |
Public Member Functions | |
| BSLMF_ASSERT (SHORT_BUFFER_BYTES >=sizeof(CHAR_TYPE *)) | |
| BSLMF_NESTED_TRAIT_DECLARATION (String_Imp, BloombergLP::bslmf::IsBitwiseMoveable) | |
| String_Imp () | |
| String_Imp (SIZE_TYPE length, SIZE_TYPE capacity) | |
| String_Imp (const String_Imp &original)=default | |
| ~String_Imp ()=default | |
| String_Imp & | operator= (const String_Imp &rhs)=default |
| void | swap (String_Imp &other) |
| void | resetFields () |
| Reset all fields of this object to their default-constructed state. | |
| CHAR_TYPE * | dataPtr () |
| bool | isShortString () const |
| const CHAR_TYPE * | dataPtr () const |
Static Public Member Functions | |
| static SIZE_TYPE | computeNewCapacity (SIZE_TYPE newLength, SIZE_TYPE oldCapacity, SIZE_TYPE maxSize) |
Public Attributes | ||
| union { | ||
| BloombergLP::bsls::AlignedBuffer< SHORT_BUFFER_BYTES, BloombergLP::bsls::AlignmentFromType< CHAR_TYPE >::VALUE > d_short | ||
| CHAR_TYPE * d_start_p | ||
| }; | ||
| SIZE_TYPE | d_length | |
| SIZE_TYPE | d_capacity | |
This component private class describes the basic data layout for a string class and provides methods to help encapsulate internal string implementation details. It is parameterized by CHAR_TYPE and SIZE_TYPE only, and implements the portion of basic_string that does not need to know about its (template parameter) types CHAR_TRAITS or ALLOCATOR. It contains the following data fields: pointer to string, short string buffer, length, and capacity. The purpose of the short string buffer is to implement a "short string optimization" such that strings with lengths shorter than a certain number of characters are stored directly inside the string object (inside the short string buffer), and thereby avoid memory allocations/deallocations.
See bslstl_string
| enum bsl::String_Imp::ConfigurableParameters |
| enum bsl::String_Imp::ShortBufferConstraints |
This enum contains values necessary to calculate the size of the short string buffer. The starting value is SHORT_BUFFER_MIN_BYTES, which defines the minimal number of bytes (or char values) that the short string buffer should be able to contain. Then this value is aligned to a word boundary. Then we make sure that it fits at least one CHAR_TYPE character (because the default state of the string object requires that the first character is initialized with a NULL-terminator). The final output of this enum used by String_Imp is the SHORT_BUFFER_CAPACITY value. It defines the capacity of the short string buffer and also the capacity of the default-constructed empty string object.
| Enumerator | |
|---|---|
| SHORT_BUFFER_MIN_BYTES | |
| SHORT_BUFFER_NEED_BYTES | |
| BSLS_PLATFORM_AGGRESSIVE_INLINE bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::String_Imp | ( | ) |
Create a String_Imp object having (default) attribute values except that the d_capacity attribute is initialized with SHORT_BUFFER_CAPACITY.
| BSLS_PLATFORM_AGGRESSIVE_INLINE bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::String_Imp | ( | SIZE_TYPE | length, |
| SIZE_TYPE | capacity | ||
| ) |
Create a String_Imp object and initialize the d_length and d_capacity attributes with the specified length and specified capacity, respectively. If capacity is less than SHORT_BUFFER_CAPACITY, then d_capacity is set to SHORT_BUFFER_CAPACITY. The value of the d_short and d_start_p fields are left uninitialized. basic_string is required to assign either d_short or d_start_p to a proper value before using any methods of this class.
|
default |
Create a String_Imp object having the same value as the specified original object. Note that this copy constructor is generated by the compiler.
|
default |
Destroy this object. Note that this destructor is generated by the compiler.
| bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::BSLMF_ASSERT | ( | SHORT_BUFFER_BYTES >= | sizeofCHAR_TYPE * | ) |
| bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::BSLMF_NESTED_TRAIT_DECLARATION | ( | String_Imp< CHAR_TYPE, SIZE_TYPE > | , |
| BloombergLP::bslmf::IsBitwiseMoveable | |||
| ) |
|
static |
Compute and return the capacity required for a string having the specified newLength and using the specified oldCapacity to exercise an exponential capacity growth necessary to ensure the amortized linear complexity of push_back and other operations and ensuring that the new capacity does not exceed the specified maxSize. Note that the behavior is undefined unless newLength > oldCapacity, newLength < maxSize, and oldCapacity < maxSize.
|
inline |
Return an address providing modifiable access to the NULL-terminated C-string stored by this string object. Note that the returned address can point to either the internal short string buffer or the externally allocated memory depending on the type of the string defined by the return value of isShortString.
|
inline |
Return an address providing non-modifiable access to the NULL-terminated C-string stored by this string object. Note that the returned address can point to either the internal short string buffer or the externally allocated memory depending on the type of the string defined by the return value of isShortString.
|
inline |
Return true if this object contains a short string and the string data is stored in the short string buffer, and false if the object contains a long string (and the short string buffer contains a pointer to the string data allocated externally).
|
default |
Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. Note that this assignment operator is generated by the compiler.
|
inline |
| void bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::swap | ( | String_Imp< CHAR_TYPE, SIZE_TYPE > & | other | ) |
Efficiently exchange the value of this object with the value of the specified other object. This method provides the no-throw exception-safety guarantee.
| union { ... } bsl::String_Imp< CHAR_TYPE, SIZE_TYPE > |
This is the union of the string storage options: it can either be stored inside the short string buffer, d_short, or in the externally allocated memory, pointed to by d_start_p.
| SIZE_TYPE bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::d_capacity |
| SIZE_TYPE bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::d_length |
| BloombergLP::bsls::AlignedBuffer< SHORT_BUFFER_BYTES, BloombergLP::bsls::AlignmentFromType<CHAR_TYPE>::VALUE> bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::d_short |
| CHAR_TYPE* bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::d_start_p |