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

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

Public Member Functions

 StringParam (const char *str="")
 Constructs from a C string.
 StringParam (const std::string &str)
 Constructs from std::string reference.
 StringParam (std::string &&str)
 Constructs from std::string object.
 StringParam (std::string_view str)
 Constructs from std::string_view object.
 StringParam (const StringParam &)=delete
StringParamoperator= (const StringParam &)=delete
 StringParam (StringParam &&)=default
 Move ctor.
StringParamoperator= (StringParam &&)=default
 Move assignment.
const char * c_str () const
 Converts to a null terminated C string.
 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/4]

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

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/4]

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/4]

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

Constructs from std::string object.

This case we assume the ownership for the string and will properly call destructor automatically.

Parameters
strthe string to store

◆ StringParam() [4/4]

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
inline

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
inline

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: