SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches

Helpers to use C++ strings parameters. More...

Public Member Functions

constexpr StringParam (const char *str="")
 Constructs from a C string.
 StringParam (const std::string &str)
 Constructs from std::string reference.
 StringParam (std::string_view str)
 Constructs from std::string_view object.
constexpr const char * c_str () const
 Converts to a null terminated C string.
constexpr operator const char * () const
 Converts to a null terminated C string.

Detailed Description

Helpers to use C++ strings parameters.

This wraps std::string and std::string_view to the SDL's C interfaces.

This should only be declared in function parameters, using it otherwise is to ask for undefined behavior

Constructor & Destructor Documentation

◆ StringParam() [1/3]

SDL::StringParam::StringParam ( const char * str = "")
inlineconstexpr

Constructs from a C string.

This assumes the parameter object lifetime is larger than this object, which is always true on parameters, so it just stores the pointer, no copy is done.

Parameters
strthe string to store. This parameter must outlive this object.

◆ StringParam() [2/3]

SDL::StringParam::StringParam ( const std::string & str)
inline

Constructs from std::string reference.

This assumes the parameter object lifetime is larger than this object, which is always true on parameters, so it just stores the pointer to internal string data, no copy is done.

Parameters
strthe reference to a string. This parameter must outlive this object.

◆ StringParam() [3/3]

SDL::StringParam::StringParam ( std::string_view str)
inline

Constructs from std::string_view object.

String view are very usefull on C++, but they don't have the null terminator expected by most string SDL APIs, so we always copy its content to a stored std::string.

Parameters
strthe string_view to store

Member Function Documentation

◆ c_str()

const char * SDL::StringParam::c_str ( ) const
inlineconstexpr

Converts to a null terminated C string.

Returns
the C string representation. We guarantee it to be null terminated unless the objects it was constructed from are corrupted.

◆ operator const char *()

SDL::StringParam::operator const char * ( ) const
inlineconstexpr

Converts to a null terminated C string.

Returns
the C string representation. We guarantee it to be null terminated unless the objects it was constructed from are corrupted.

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