Tkrzw
Public Member Functions | List of all members
tkrzw::ScopedStringView Class Reference

Wrapper of string_view of allocated memory. More...

#include <tkrzw_str_util.h>

Public Member Functions

 ScopedStringView ()
 Constructor. More...
 
 ScopedStringView (void *buf, size_t size)
 Constructor. More...
 
 ScopedStringView (std::string_view str)
 Constructor. More...
 
 ~ScopedStringView ()
 Destructor. More...
 
std::string_view Get () const
 Gets the string view object. More...
 
void Set (void *buf, size_t size)
 Sets the data. More...
 
void Set (std::string_view str)
 Sets the data by a string view. More...
 

Detailed Description

Wrapper of string_view of allocated memory.

Constructor & Destructor Documentation

◆ ScopedStringView() [1/3]

tkrzw::ScopedStringView::ScopedStringView ( )

Constructor.

◆ ScopedStringView() [2/3]

tkrzw::ScopedStringView::ScopedStringView ( void *  buf,
size_t  size 
)

Constructor.

Parameters
bufThe pointer to a region allocated by xmalloc. The ownership of is taken.
sizeThe size of the region.

◆ ScopedStringView() [3/3]

tkrzw::ScopedStringView::ScopedStringView ( std::string_view  str)
explicit

Constructor.

Parameters
strA string view object whose data is allocated by xmalloc. The ownership of the data is taken.

◆ ~ScopedStringView()

tkrzw::ScopedStringView::~ScopedStringView ( )

Destructor.

Member Function Documentation

◆ Get()

std::string_view tkrzw::ScopedStringView::Get ( ) const

Gets the string view object.

◆ Set() [1/2]

void tkrzw::ScopedStringView::Set ( void *  buf,
size_t  size 
)

Sets the data.

The region of the old data is released.

◆ Set() [2/2]

void tkrzw::ScopedStringView::Set ( std::string_view  str)

Sets the data by a string view.

The region of the old data is released.