SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members

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

Public Member Functions

constexpr StringParam (std::nullptr_t=nullptr)
 Default ctor.
 
constexpr StringParam (const char *str)
 Constructs from a C string.
 
constexpr StringParam (const std::string &str)
 Constructs from std::string reference.
 
constexpr 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.
 
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

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]

constexpr SDL::StringParam::StringParam ( const char *  str)
inlineconstexpr

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]

constexpr SDL::StringParam::StringParam ( const std::string &  str)
inlineconstexpr

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]

constexpr SDL::StringParam::StringParam ( std::string &&  str)
inlineconstexpr

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

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()

constexpr const char * SDL::StringParam::c_str ( ) const
inlineconstexpr
Returns
the C string representation. We guarantee it to be null terminated unless the objects it was constructed from are corrupted.

◆ operator const char *()

constexpr SDL::StringParam::operator const char * ( ) const
inlineconstexpr
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: