Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
PS::StringBuilder Class Reference

A helper class to build string in-place without additional cost of allocations, locales and format parsing. More...

#include <StringBuilder.h>

Public Member Functions

 StringBuilder (std::span< char > buffer) noexcept
 
template<typename T >
std::enable_if< std::is_arithmetic_v< T > >::type Append (const T value) noexcept
 
void Append (const char ch)
 
void Append (const std::string_view str) noexcept
 
std::string_view Str () noexcept
 Returns a string_view to a null-terminated string. More...
 

Private Attributes

std::span< char > m_Buffer
 
char * m_BufferBegin
 

Detailed Description

A helper class to build string in-place without additional cost of allocations, locales and format parsing.

Prefer to use the class with stack allocated buffers over standard tools in high-load cases. TODO: in case of overflow it might use a heap allocated storage.

Constructor & Destructor Documentation

◆ StringBuilder()

PS::StringBuilder::StringBuilder ( std::span< char >  buffer)
inlinenoexcept

Member Function Documentation

◆ Append() [1/3]

void PS::StringBuilder::Append ( const char  ch)
inline

◆ Append() [2/3]

void PS::StringBuilder::Append ( const std::string_view  str)
inlinenoexcept

◆ Append() [3/3]

template<typename T >
std::enable_if< std::is_arithmetic_v< T > >::type PS::StringBuilder::Append ( const T  value)
inlinenoexcept

◆ Str()

std::string_view PS::StringBuilder::Str ( )
inlinenoexcept

Returns a string_view to a null-terminated string.

Member Data Documentation

◆ m_Buffer

std::span<char> PS::StringBuilder::m_Buffer
private

◆ m_BufferBegin

char* PS::StringBuilder::m_BufferBegin
private

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