BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsl::String_Imp< CHAR_TYPE, SIZE_TYPE > Class Template Reference

#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_Impoperator= (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
 

Detailed Description

template<class CHAR_TYPE, class SIZE_TYPE>
class bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >

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

Member Enumeration Documentation

◆ ConfigurableParameters

template<class CHAR_TYPE , class SIZE_TYPE >
enum bsl::String_Imp::ConfigurableParameters
Enumerator
BASIC_STRING_DEALLOCATE_IN_CLEAR 
BASIC_STRING_HONOR_SHRINK_REQUEST 

◆ ShortBufferConstraints

template<class CHAR_TYPE , class SIZE_TYPE >
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 

Constructor & Destructor Documentation

◆ String_Imp() [1/3]

template<class CHAR_TYPE , class SIZE_TYPE >
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.

◆ String_Imp() [2/3]

template<class CHAR_TYPE , class SIZE_TYPE >
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.

◆ String_Imp() [3/3]

template<class CHAR_TYPE , class SIZE_TYPE >
bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::String_Imp ( const String_Imp< CHAR_TYPE, SIZE_TYPE > &  original)
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.

◆ ~String_Imp()

template<class CHAR_TYPE , class SIZE_TYPE >
bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::~String_Imp ( )
default

Destroy this object. Note that this destructor is generated by the compiler.

Member Function Documentation

◆ BSLMF_ASSERT()

template<class CHAR_TYPE , class SIZE_TYPE >
bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::BSLMF_ASSERT ( SHORT_BUFFER_BYTES >=  sizeofCHAR_TYPE *)

◆ BSLMF_NESTED_TRAIT_DECLARATION()

template<class CHAR_TYPE , class SIZE_TYPE >
bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( String_Imp< CHAR_TYPE, SIZE_TYPE >  ,
BloombergLP::bslmf::IsBitwiseMoveable   
)

◆ computeNewCapacity()

template<class CHAR_TYPE , class SIZE_TYPE >
SIZE_TYPE bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::computeNewCapacity ( SIZE_TYPE  newLength,
SIZE_TYPE  oldCapacity,
SIZE_TYPE  maxSize 
)
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.

◆ dataPtr() [1/2]

template<class CHAR_TYPE , class SIZE_TYPE >
CHAR_TYPE * bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::dataPtr ( )
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.

◆ dataPtr() [2/2]

template<class CHAR_TYPE , class SIZE_TYPE >
const CHAR_TYPE * bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::dataPtr ( ) const
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.

◆ isShortString()

template<class CHAR_TYPE , class SIZE_TYPE >
bool bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::isShortString ( ) const
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).

◆ operator=()

template<class CHAR_TYPE , class SIZE_TYPE >
String_Imp & bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::operator= ( const String_Imp< CHAR_TYPE, SIZE_TYPE > &  rhs)
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.

◆ resetFields()

template<class CHAR_TYPE , class SIZE_TYPE >
void bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::resetFields ( )
inline

◆ swap()

template<class CHAR_TYPE , class SIZE_TYPE >
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.

Member Data Documentation

◆ [union]

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.

◆ d_capacity

template<class CHAR_TYPE , class SIZE_TYPE >
SIZE_TYPE bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::d_capacity

◆ d_length

template<class CHAR_TYPE , class SIZE_TYPE >
SIZE_TYPE bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::d_length

◆ d_short

template<class CHAR_TYPE , class SIZE_TYPE >
BloombergLP::bsls::AlignedBuffer< SHORT_BUFFER_BYTES, BloombergLP::bsls::AlignmentFromType<CHAR_TYPE>::VALUE> bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::d_short

◆ d_start_p

template<class CHAR_TYPE , class SIZE_TYPE >
CHAR_TYPE* bsl::String_Imp< CHAR_TYPE, SIZE_TYPE >::d_start_p

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