Cogs.Foundation
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Cogs::ImmutableString Class Reference

Represents a non-copyable immutable string. More...

#include <ImmutableString.h>

Public Member Functions

constexpr ImmutableString () noexcept=default
 Create an empty string.
 
 ImmutableString (const ImmutableString &)=delete
 Non-copyable.
 
ImmutableStringoperator= (const ImmutableString &)=delete
 Non-copyable.
 
constexpr ImmutableString (ImmutableString &&other) noexcept
 Take ownership of another string.
 
constexpr ImmutableStringoperator= (ImmutableString &&other) noexcept
 Take ownership of another string.
 
COGSFOUNDATION_API ImmutableString (const Cogs::StringView &view)
 Create a new unique immutable string from a string view.
 
 ~ImmutableString ()
 Destructor.
 
constexpr operator const char * () const noexcept
 View the string as C-string.
 
constexpr operator Cogs::StringView () const noexcept
 View the string as a string view.
 
constexpr void swap (ImmutableString &other) noexcept
 Swap contents with another string.
 
constexpr Cogs::StringView asView () const noexcept
 Explicitly view the string as a string view.
 
constexpr bool empty () const noexcept
 Check if string is empty.
 
void clear ()
 Set contents to the empty string.
 
constexpr const char * c_str () const noexcept
 Get the string as C-string.
 
constexpr size_t size () const noexcept
 Get the string length.
 

Private Member Functions

COGSFOUNDATION_API void release ()
 

Private Attributes

char * ptr = nullptr
 

Detailed Description

Represents a non-copyable immutable string.

Essentially a heap-allocated string with unique_ptr-semantics.

Optimized for representing empty strings, in that case the object has the memory footprint of a single pointer.

Note
: Create these objects sparingly as creating this object wih any non-empty string will might incur a memory allocation. If you create such an object every frame you are using this class incorrectly.

Constructor & Destructor Documentation

◆ ImmutableString() [1/4]

constexpr Cogs::ImmutableString::ImmutableString ( )
constexprdefaultnoexcept

Create an empty string.

◆ ImmutableString() [2/4]

Cogs::ImmutableString::ImmutableString ( const ImmutableString )
delete

Non-copyable.

◆ ImmutableString() [3/4]

constexpr Cogs::ImmutableString::ImmutableString ( ImmutableString &&  other)
inlineconstexprnoexcept

Take ownership of another string.

References swap().

◆ ImmutableString() [4/4]

Cogs::ImmutableString::ImmutableString ( const Cogs::StringView view)

Create a new unique immutable string from a string view.

References Cogs::StringView::data(), Cogs::StringView::empty(), Cogs::N, ptr, release(), Cogs::S, and Cogs::StringView::size().

◆ ~ImmutableString()

Cogs::ImmutableString::~ImmutableString ( )
inline

Destructor.

References clear().

Member Function Documentation

◆ asView()

constexpr Cogs::StringView Cogs::ImmutableString::asView ( ) const
inlineconstexprnoexcept

Explicitly view the string as a string view.

References ptr.

Referenced by operator Cogs::StringView().

◆ c_str()

constexpr const char * Cogs::ImmutableString::c_str ( ) const
inlineconstexprnoexcept

Get the string as C-string.

References ptr.

Referenced by operator const char *().

◆ clear()

void Cogs::ImmutableString::clear ( )
inline

Set contents to the empty string.

References ptr, and release().

Referenced by ~ImmutableString().

◆ empty()

constexpr bool Cogs::ImmutableString::empty ( ) const
inlineconstexprnoexcept

Check if string is empty.

References ptr.

◆ operator Cogs::StringView()

constexpr Cogs::ImmutableString::operator Cogs::StringView ( ) const
inlineconstexprnoexcept

View the string as a string view.

References asView().

◆ operator const char *()

constexpr Cogs::ImmutableString::operator const char * ( ) const
inlineconstexprnoexcept

View the string as C-string.

References c_str().

◆ operator=() [1/2]

ImmutableString & Cogs::ImmutableString::operator= ( const ImmutableString )
delete

Non-copyable.

◆ operator=() [2/2]

constexpr ImmutableString & Cogs::ImmutableString::operator= ( ImmutableString &&  other)
inlineconstexprnoexcept

Take ownership of another string.

References swap().

◆ release()

void Cogs::ImmutableString::release ( )
private

References Cogs::N.

Referenced by clear(), and ImmutableString().

◆ size()

constexpr size_t Cogs::ImmutableString::size ( ) const
inlineconstexprnoexcept

Get the string length.

References ptr, and size().

Referenced by size().

◆ swap()

constexpr void Cogs::ImmutableString::swap ( ImmutableString other)
inlineconstexprnoexcept

Swap contents with another string.

References ptr.

Referenced by ImmutableString(), and operator=().

Member Data Documentation

◆ ptr

char* Cogs::ImmutableString::ptr = nullptr
private

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