Cogs.Core
Public Member Functions | Private Types | Private Attributes | List of all members
Cogs::Core::StringViewCharPtr Class Reference

Utility class to ensure that a StringView string is null terminated. More...

#include <StringViewCharPtr.h>

Public Member Functions

 StringViewCharPtr (const char *data)=delete
 Construct from constant C-string. Always null terminated.
 
 StringViewCharPtr (const Cogs::StringView data)
 
 StringViewCharPtr (const std::string &data)=delete
 Deleted to avoid passing a std::string converted to string_view in constructor above.
 
 StringViewCharPtr (const StringViewCharPtr &)=delete
 
StringViewCharPtroperator= (const StringViewCharPtr &)=delete
 
constexpr operator const char * () const noexcept
 Gets null terminated C-string.
 
constexpr const char * c_str () const noexcept
 Gets null terminated C-string.
 
constexpr operator Cogs::StringView () const noexcept
 Gets null terminated StringView.
 

Private Types

using traits_type = std::char_traits< char >
 

Private Attributes

Cogs::StringView view
 
std::string copy
 

Detailed Description

Utility class to ensure that a StringView string is null terminated.

Can be used to pass Cogs::StringView string to Bridge functions requiring null terminated. Can normally use the passed StringView, but copies to std::string if needed.

Fails: getFieldId(componentId, Cogs::StringView("positionXX", 8).data()); OK: getFieldId(componentId, Cogs::Core::StringViewCharPtr(Cogs::StringView("positionXX", 8).data()));

Definition at line 17 of file StringViewCharPtr.h.

Member Typedef Documentation

◆ traits_type

using Cogs::Core::StringViewCharPtr::traits_type = std::char_traits<char>
private

Definition at line 18 of file StringViewCharPtr.h.

Constructor & Destructor Documentation

◆ StringViewCharPtr()

Cogs::Core::StringViewCharPtr::StringViewCharPtr ( const Cogs::StringView  data)

Construct from Cogs::StringView. Copies to local string if substring passed

Definition at line 5 of file StringViewCharPtr.cpp.

Member Function Documentation

◆ c_str()

constexpr const char * Cogs::Core::StringViewCharPtr::c_str ( ) const
inlineconstexprnoexcept

Gets null terminated C-string.

Definition at line 38 of file StringViewCharPtr.h.

◆ operator Cogs::StringView()

constexpr Cogs::Core::StringViewCharPtr::operator Cogs::StringView ( ) const
inlineconstexprnoexcept

Gets null terminated StringView.

Definition at line 41 of file StringViewCharPtr.h.

◆ operator const char *()

constexpr Cogs::Core::StringViewCharPtr::operator const char * ( ) const
inlineconstexprnoexcept

Gets null terminated C-string.

Definition at line 35 of file StringViewCharPtr.h.

Member Data Documentation

◆ copy

std::string Cogs::Core::StringViewCharPtr::copy
private

Definition at line 45 of file StringViewCharPtr.h.

◆ view

Cogs::StringView Cogs::Core::StringViewCharPtr::view
private

Definition at line 44 of file StringViewCharPtr.h.


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