ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::strings::TStringLengthResetter< TChar, TAllocator > Class Template Reference

Description:

template<typename TChar, typename TAllocator>
class alib::strings::TStringLengthResetter< TChar, TAllocator >

This is a simple utility class that can be used in situations where a AString is intermediately extended and later shortened back to its original length. With the use of this class, C++ stack-unwinding is used to ensure that the length is reset in all execution paths including exception handling, etc.

See also
Macro ALIB_STRING_RESETTER which automatically creates a unique identifier for the otherwise unused instances of this type.
Template Parameters
TCharThe character type of the AString that is to be reset.
TAllocatorThe allocator type of the AString, as prototyped with Allocator.

Definition at line 2222 of file tastring.inl.

Public Method Index:

 TStringLengthResetter (TAString< TChar, TAllocator > &pAString)
 
 ~TStringLengthResetter ()
 Destructor. Restores the string's original length.
 
integer OriginalLength ()
 
void ResetNow ()
 

Protected Field Index:

TAString< TChar, TAllocator > & aString
 The AString to reset.
 
integer originalLength
 The The original length of the string.
 

Private Method Index:

void * operator new (size_t)
 
void * operator new (size_t, void *)
 
void * operator new[] (size_t)
 
void * operator new[] (size_t, void *)
 
void operator= (const TStringLengthResetter &)
 Private assignment operator.
 

Field Details:

◆ aString

template<typename TChar, typename TAllocator>
TAString<TChar,TAllocator>& alib::strings::TStringLengthResetter< TChar, TAllocator >::aString
protected

The AString to reset.

Definition at line 2225 of file tastring.inl.

◆ originalLength

template<typename TChar, typename TAllocator>
integer alib::strings::TStringLengthResetter< TChar, TAllocator >::originalLength
protected

The The original length of the string.

Definition at line 2226 of file tastring.inl.

Constructor(s) / Destructor Details:

◆ TStringLengthResetter()

template<typename TChar, typename TAllocator>
alib::strings::TStringLengthResetter< TChar, TAllocator >::TStringLengthResetter ( TAString< TChar, TAllocator > & pAString)
inline

Constructor taking the string. Stores the current length in field originalLength.

Parameters
pAStringThe String to take the length of and reset on destruction.

Definition at line 2247 of file tastring.inl.

◆ ~TStringLengthResetter()

template<typename TChar, typename TAllocator>
alib::strings::TStringLengthResetter< TChar, TAllocator >::~TStringLengthResetter ( )
inline

Destructor. Restores the string's original length.

Definition at line 2252 of file tastring.inl.

Method Details:

◆ operator new() [1/2]

template<typename TChar, typename TAllocator>
void * alib::strings::TStringLengthResetter< TChar, TAllocator >::operator new ( size_t )
private

Private new to disallow heap allocation.

Returns
Never called.

◆ operator new() [2/2]

template<typename TChar, typename TAllocator>
void * alib::strings::TStringLengthResetter< TChar, TAllocator >::operator new ( size_t ,
void *  )
private

Private new to disallow heap allocation.

Returns
Never called.

◆ operator new[]() [1/2]

template<typename TChar, typename TAllocator>
void * alib::strings::TStringLengthResetter< TChar, TAllocator >::operator new[] ( size_t )
private

Private new to disallow heap allocation.

Returns
Never called.

◆ operator new[]() [2/2]

template<typename TChar, typename TAllocator>
void * alib::strings::TStringLengthResetter< TChar, TAllocator >::operator new[] ( size_t ,
void *  )
private

Private new to disallow heap allocation.

Returns
Never called.

◆ OriginalLength()

template<typename TChar, typename TAllocator>
integer alib::strings::TStringLengthResetter< TChar, TAllocator >::OriginalLength ( )
inline

Returns the original length.

Returns
The length of the AString when this object was constructed.

Definition at line 2262 of file tastring.inl.

◆ ResetNow()

template<typename TChar, typename TAllocator>
void alib::strings::TStringLengthResetter< TChar, TAllocator >::ResetNow ( )
inline

Resets the strings to the original length before destruction of this object.

Note
With using macro ALIB_STRING_RESETTER, this method is not invocable, because the name of the object is not available in this case. But this method is not a true member of the usual use case of this class.

Definition at line 2258 of file tastring.inl.


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