API Documentation
Public Member Functions | List of all members
nkLog::String Class Referencefinal

Allows to exchange strings with external code. More...

Public Member Functions

 String () noexcept
 
 String (char c) noexcept
 
 String (const char *data) noexcept
 
 String (unsigned long long size) noexcept
 
 String (const char *data, unsigned long long size) noexcept
 
 String (const String &other) noexcept
 
 String (String &&other) noexcept
 
 ~String ()
 
char * getData () const
 
unsigned long long getSize () const
 
char operator[] (unsigned long long index) const
 
char & operator[] (unsigned long long index)
 
Stringoperator= (const StringView &other)
 
Stringoperator= (String &&other)
 
String operator+ (char c) const
 
String operator+ (const StringView &other) const
 
void operator+= (char c)
 
void operator+= (const StringView &other)
 
 String (const std::string &str) noexcept
 
 String (const std::string_view &str) noexcept
 
 operator std::string () const
 
 operator std::string_view () const
 

Detailed Description

Allows to exchange strings with external code.

The aim of this class is not to replace any std::string or std::string_view within a code base. It is intended to avoid passing the std templates, or relying on simple pointers when providing string information to logging capabilities. Note that all other components use nkMemory::String. However, as nkMemory depends on nkLog, this class has been introduced to help nkLog in this matter. A String is offered with many conversion functions, meaning you should never worry about it in the general use-case.

Constructor & Destructor Documentation

◆ String() [1/9]

nkLog::String::String ( )
noexcept

Default constructor. Defaults to an empty string (nullptr, of size 0).

◆ String() [2/9]

nkLog::String::String ( char  c)
noexcept

Char constructor. Creates a single char string.

Parameters
cThe char to wrap.

◆ String() [3/9]

nkLog::String::String ( const char *  data)
noexcept

Simple pointer constructor. Will use strlen internally to derive its size.

Parameters
dataThe string pointer to create a copy of.

◆ String() [4/9]

nkLog::String::String ( unsigned long long  size)
noexcept

Size constructor. An empty string will allocate needed memory to fit the size requested, without filling it with any data.

Parameters
sizeThe size that should be allocated.

◆ String() [5/9]

nkLog::String::String ( const char *  data,
unsigned long long  size 
)
noexcept

Pointer and size constructor. This method allows to provide the size and allows to avoid the call to strlen, if known upfront.

Parameters
dataThe string pointer to create a copy of.
sizeThe size of the string passed.

◆ String() [6/9]

nkLog::String::String ( const String other)
noexcept

Copy constructor.

Parameters
otherThe string to copy.

◆ String() [7/9]

nkLog::String::String ( String &&  other)
noexcept

Move constructor.

Parameters
otherThe string to move.

◆ ~String()

nkLog::String::~String ( )

Destructor.

◆ String() [8/9]

nkLog::String::String ( const std::string &  str)
noexcept

Inlined standard string constructor. This function is inlined and thus will be fed by the client application, correctly addressing the templated class.

Parameters
strThe string to create a view from.

◆ String() [9/9]

nkLog::String::String ( const std::string_view &  str)
noexcept

Inlined standard string_view constructor. This function is inlined and thus will be fed by the client application, correctly addressing the templated class.

Parameters
strThe view to create a view from.

Member Function Documentation

◆ getData()

char* nkLog::String::getData ( ) const
Returns
The string data pointer.

◆ getSize()

unsigned long long nkLog::String::getSize ( ) const
Returns
The size of the string view.

◆ operator[]() [1/2]

char nkLog::String::operator[] ( unsigned long long  index) const

Const access operator.

Parameters
indexThe index of the char to access.

◆ operator[]() [2/2]

char& nkLog::String::operator[] ( unsigned long long  index)

Access operator.

Parameters
indexThe index of the char to access.

◆ operator=() [1/2]

String& nkLog::String::operator= ( const StringView other)

Assignment operator.

Parameters
otherThe view to copy.
Returns
The calling, updated String instance.

◆ operator=() [2/2]

String& nkLog::String::operator= ( String &&  other)

Move operator.

Parameters
otherThe String to move.
Returns
The calling, updated String instance.

◆ operator+() [1/2]

String nkLog::String::operator+ ( char  c) const

Concatenation operator.

Parameters
cThe char to concatenate.
Returns
A new string instance with the concatenated char at the end of it.

◆ operator+() [2/2]

String nkLog::String::operator+ ( const StringView other) const

Concatenation operator.

Parameters
otherThe string to concatenate.
Returns
A new string instance with the concatenated string at the end of it.

◆ operator+=() [1/2]

void nkLog::String::operator+= ( char  c)

Self concatenation operator.

Parameters
cThe char to concatenate.

◆ operator+=() [2/2]

void nkLog::String::operator+= ( const StringView other)

Self concatenation operator.

Parameters
otherThe string to concatenate.

◆ operator std::string()

nkLog::String::operator std::string ( ) const

Inlined automatic conversion operator. Used to be able to create std::string from any client code.

◆ operator std::string_view()

nkLog::String::operator std::string_view ( ) const

Inlined automatic conversion operator. Used to be able to create std::string_view from any client code.


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