protozero
Minimalistic protocol buffer decoder and encoder in C++.
Public Member Functions | List of all members
protozero::data_view Class Reference

#include <types.hpp>

Public Member Functions

constexpr data_view () noexcept
 
constexpr data_view (const char *ptr, std::size_t length) noexcept
 
 data_view (const std::string &str) noexcept
 
 data_view (const char *ptr) noexcept
 
void swap (data_view &other) noexcept
 
constexpr const char * data () const noexcept
 Return pointer to data.
 
constexpr std::size_t size () const noexcept
 Return length of data in bytes.
 
constexpr bool empty () const noexcept
 Returns true if size is 0.
 
std::string to_string () const
 
 operator std::string () const
 

Detailed Description

Holds a pointer to some data and a length.

This class is supposed to be compatible with the std::string_view that will be available in C++17.

Constructor & Destructor Documentation

◆ data_view() [1/4]

constexpr protozero::data_view::data_view ( )
inlinenoexcept

Default constructor. Construct an empty data_view.

◆ data_view() [2/4]

constexpr protozero::data_view::data_view ( const char *  ptr,
std::size_t  length 
)
inlinenoexcept

Create data_view from pointer and size.

Parameters
ptrPointer to the data.
lengthLength of the data.

◆ data_view() [3/4]

protozero::data_view::data_view ( const std::string &  str)
inlinenoexcept

Create data_view from string.

Parameters
strString with the data.

◆ data_view() [4/4]

protozero::data_view::data_view ( const char *  ptr)
inlinenoexcept

Create data_view from zero-terminated string.

Parameters
ptrPointer to the data.

Member Function Documentation

◆ operator std::string()

protozero::data_view::operator std::string ( ) const
inlineexplicit

Convert data view to string.

Precondition
Must not be default constructed data_view.

◆ swap()

void protozero::data_view::swap ( data_view other)
inlinenoexcept

Swap the contents of this object with the other.

Parameters
otherOther object to swap data with.

◆ to_string()

std::string protozero::data_view::to_string ( ) const
inline

Convert data view to string.

Precondition
Must not be default constructed data_view.

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