Skip to content

Struct mdbx::slice

ClassList > mdbx > slice

References a data located outside the slice. More...

  • #include <mdbx.h++>

Inherits the following classes: MDBX_val

Inherited by the following classes: mdbx::buffer, mdbx::buffer

Public Types

Type Name
enum size_t @257333234016247237045177161061253053363217153027

Public Functions

Type Name
int128_t as_int128 () const
int128_t as_int128_adapt () const
int16_t as_int16 () const
int16_t as_int16_adapt () const
int32_t as_int32 () const
int32_t as_int32_adapt () const
int64_t as_int64 () const
int64_t as_int64_adapt () const
int8_t as_int8 () const
int8_t as_int8_adapt () const
POD as_pod () const
::std::span< const POD > as_span () const
::std::span< POD > as_span ()
::std::basic_string< CHAR, T, ALLOCATOR > as_string (const ALLOCATOR & alloc=ALLOCATOR()) const
uint128_t as_uint128 () const
uint128_t as_uint128_adapt () const
uint16_t as_uint16 () const
uint16_t as_uint16_adapt () const
uint32_t as_uint32 () const
uint32_t as_uint32_adapt () const
uint64_t as_uint64 () const
uint64_t as_uint64_adapt () const
uint8_t as_uint8 () const
uint8_t as_uint8_adapt () const
slice & assign (const ::std::basic_string< CHAR, T, ALLOCATOR > & str)
slice & assign (const ::std::basic_string_view< CHAR, T > & view)
slice & assign (::std::basic_string_view< CHAR, T > && view)
byte back () noexcept const
Returns the last byte of the referenced data.
::std::span< const byte > bytes () const
::std::span< byte > bytes ()
::std::span< const char > chars () const
::std::span< char > chars ()
intptr_t compare (const slice & other) noexcept const
Lexicographical three-way comparison with another slice.
bool contains (const slice & needle) noexcept const
Checks whether the referenced data contains needle as a sub-slice.
byte front () noexcept const
Returns the first byte of the referenced data.
bool is_printable (bool disable_utf8=false) noexcept const
Checks whether the content of the slice is printable.
bool is_valid () noexcept const
Checks the slice is valid: returns false only if it has a null data pointer and a non-zero length.
operator MDBX_val * () noexcept
operator const MDBX_val * () noexcept const
constexpr basic_string () const
constexpr basic_string_view () noexcept const
Return a string_view that references the same data as this slice.
slice & operator= (const slice &) noexcept
slice & operator= (const ::std::basic_string_view< CHAR, T > & view)
slice & operator= (::std::basic_string_view< CHAR, T > && view)
constexpr slice (const char(&) text)
Create a slice that refers to text[0,strlen(text)-1].
constexpr slice (const ::std::basic_string< CHAR, T, A > & str)
Create a slice that refers to the contents of "str".
constexpr slice (const slice &) noexcept
constexpr slice (const ::std::span< POD > & span)
constexpr slice (const ::std::basic_string_view< CHAR, T > & sv)
Create a slice that refers to the same contents as "string_view".
slice (::std::basic_string_view< CHAR, T > && sv)
::std::basic_string_view< CHAR, T > string_view () noexcept const
Return a string_view that references the same data as this slice.
slice substr (size_t pos, size_t count=npos) const
Returns a sub-slice of [pos, pos+count) clamped to the end.
void swap (::std::basic_string_view< CHAR, T > & view) noexcept
void swap (slice & other) noexcept

Public Static Functions

Type Name
slice invalid () noexcept
Builds an invalid slice that has a non-zero length and refers to a null address.
slice null () noexcept
Build a null slice which zero length and refers to null address.
slice wrap (const char(&) text)
slice wrap (const POD & pod)

Protected Functions

Type Name
constexpr slice (size_t invalid_length) noexcept

Detailed Description

The slice is similar in many ways to std::string_view, but it implements specific capabilities and manipulates with bytes but not a characters.

Note:

A slice is non-owning: it references data allocated elsewhere and never copies or releases it. The referenced data must remain valid as long as the slice is used. Passing a temporary (e.g. a std::string converted inline in a call argument, like txn.insert (map, mdbx::slice(std::to_string(k)) , ...)) is safe: a temporary lives until the end of the full-expression and libmdbx copies the bytes during the call. In contrast, storing such a slice beyond the statement leaves it dangling.

See also: mdbx::slice

See also: mdbx::buffer Values returned from the table are valid only until a subsequent update operation, or the end of the transaction. Do not modify or free them, they commonly point into the database itself.

Key sizes must be between 0 and mdbx_env_get_maxkeysize() inclusive. The same applies to data sizes in tables with the MDBX_DUPSORT flag. Other data items can in theory be from 0 to MDBX_MAXDATASIZE bytes long.

Note:

The notable difference between MDBX and LMDB is that MDBX support zero length keys.

Public Types Documentation

enum @257333234016247237045177161061253053363217153027

enum mdbx::slice::@257333234016247237045177161061253053363217153027 {
    max_length = MDBX_MAXDATASIZE,
    npos = size_t(-1)
};

Public Functions Documentation

function as_int128

inline int128_t mdbx::slice::as_int128 () const

function as_int128_adapt

int128_t mdbx::slice::as_int128_adapt () const

function as_int16

inline int16_t mdbx::slice::as_int16 () const

function as_int16_adapt

int16_t mdbx::slice::as_int16_adapt () const

function as_int32

inline int32_t mdbx::slice::as_int32 () const

function as_int32_adapt

int32_t mdbx::slice::as_int32_adapt () const

function as_int64

inline int64_t mdbx::slice::as_int64 () const

function as_int64_adapt

int64_t mdbx::slice::as_int64_adapt () const

function as_int8

inline int8_t mdbx::slice::as_int8 () const

function as_int8_adapt

int8_t mdbx::slice::as_int8_adapt () const

function as_pod

template<typename POD>
inline POD mdbx::slice::as_pod () const

function as_span [1/2]

template<typename POD>
inline ::std::span< const POD > mdbx::slice::as_span () const

function as_span [2/2]

template<typename POD>
inline ::std::span< POD > mdbx::slice::as_span () 

function as_string

template<class CHAR, class T, class ALLOCATOR>
inline ::std::basic_string< CHAR, T, ALLOCATOR > mdbx::slice::as_string (
    const ALLOCATOR & alloc=ALLOCATOR()
) const

function as_uint128

inline uint128_t mdbx::slice::as_uint128 () const

function as_uint128_adapt

uint128_t mdbx::slice::as_uint128_adapt () const

function as_uint16

inline uint16_t mdbx::slice::as_uint16 () const

function as_uint16_adapt

uint16_t mdbx::slice::as_uint16_adapt () const

function as_uint32

inline uint32_t mdbx::slice::as_uint32 () const

function as_uint32_adapt

uint32_t mdbx::slice::as_uint32_adapt () const

function as_uint64

inline uint64_t mdbx::slice::as_uint64 () const

function as_uint64_adapt

uint64_t mdbx::slice::as_uint64_adapt () const

function as_uint8

inline uint8_t mdbx::slice::as_uint8 () const

function as_uint8_adapt

uint8_t mdbx::slice::as_uint8_adapt () const

function assign [1/3]

template<class CHAR, class T, class ALLOCATOR>
inline slice & mdbx::slice::assign (
    const ::std::basic_string< CHAR, T, ALLOCATOR > & str
) 

function assign [2/3]

template<class CHAR, class T>
inline slice & mdbx::slice::assign (
    const ::std::basic_string_view< CHAR, T > & view
) 

function assign [3/3]

template<class CHAR, class T>
inline slice & mdbx::slice::assign (
    ::std::basic_string_view< CHAR, T > && view
) 

function back

Returns the last byte of the referenced data.

inline byte mdbx::slice::back () noexcept const

Precondition:

REQUIRES: !empty()


function bytes [1/2]

inline ::std::span< const byte > mdbx::slice::bytes () const

function bytes [2/2]

inline ::std::span< byte > mdbx::slice::bytes () 

function chars [1/2]

inline ::std::span< const char > mdbx::slice::chars () const

function chars [2/2]

inline ::std::span< char > mdbx::slice::chars () 

function compare

Lexicographical three-way comparison with another slice.

inline intptr_t mdbx::slice::compare (
    const slice & other
) noexcept const

function contains

Checks whether the referenced data contains needle as a sub-slice.

inline bool mdbx::slice::contains (
    const slice & needle
) noexcept const

function front

Returns the first byte of the referenced data.

inline byte mdbx::slice::front () noexcept const

Precondition:

REQUIRES: !empty()


function is_printable

Checks whether the content of the slice is printable.

bool mdbx::slice::is_printable (
    bool disable_utf8=false
) noexcept const

Parameters:

  • disable_utf8 By default if disable_utf8 is false function checks that content bytes are printable ASCII-7 characters or a valid UTF8 sequences. Otherwise, if disable_utf8 is true function checks that content bytes are printable extended 8-bit ASCII codes.

function is_valid

Checks the slice is valid: returns false only if it has a null data pointer and a non-zero length.

inline bool mdbx::slice::is_valid () noexcept const

function operator MDBX_val *

inline mdbx::slice::operator MDBX_val * () noexcept

function operator const MDBX_val *

inline mdbx::slice::operator const MDBX_val * () noexcept const

function basic_string

template<class CHAR, class T, class ALLOCATOR>
inline explicit constexpr mdbx::slice::basic_string () const

function basic_string_view

Return a string_view that references the same data as this slice.

template<class CHAR, class T>
inline explicit constexpr mdbx::slice::basic_string_view () noexcept const

function operator=

slice & mdbx::slice::operator= (
    const slice &
) noexcept

function operator=

template<class CHAR, class T>
inline slice & mdbx::slice::operator= (
    const ::std::basic_string_view< CHAR, T > & view
) 

function operator=

template<class CHAR, class T>
inline slice & mdbx::slice::operator= (
    ::std::basic_string_view< CHAR, T > && view
) 

function slice [1/7]

Create a slice that refers to text[0,strlen(text)-1].

template<size_t SIZE>
inline constexpr mdbx::slice::slice (
    const char(&) text
) 

function slice [2/7]

Create a slice that refers to the contents of "str".

template<class CHAR, class T, class A>
inline explicit constexpr mdbx::slice::slice (
    const ::std::basic_string< CHAR, T, A > & str
) 

Note:

'explicit' to avoid reference to the temporary std::string instance. The slice is non-owning: it references the string's data without copying. Passing a temporary string inline in a call argument is safe (the temporary lives until the end of the full-expression and libmdbx copies the bytes during the call), but storing the resulting slice beyond the statement leaves it dangling — use mdbx::buffer to own a copy.


function slice [3/7]

constexpr mdbx::slice::slice (
    const slice &
) noexcept

function slice [4/7]

template<typename POD>
inline constexpr mdbx::slice::slice (
    const ::std::span< POD > & span
) 

function slice [5/7]

Create a slice that refers to the same contents as "string_view".

template<class CHAR, class T>
inline constexpr mdbx::slice::slice (
    const ::std::basic_string_view< CHAR, T > & sv
) 

function slice [6/7]

template<class CHAR, class T>
inline mdbx::slice::slice (
    ::std::basic_string_view< CHAR, T > && sv
) 

function string_view

Return a string_view that references the same data as this slice.

template<class CHAR, class T>
inline ::std::basic_string_view< CHAR, T > mdbx::slice::string_view () noexcept const

function substr

Returns a sub-slice of [pos, pos+count) clamped to the end.

inline slice mdbx::slice::substr (
    size_t pos,
    size_t count=npos
) const

Exception:

  • std::out_of_range if pos > size().

function swap [1/2]

template<class CHAR, class T>
inline void mdbx::slice::swap (
    ::std::basic_string_view< CHAR, T > & view
) noexcept

function swap [2/2]

inline void mdbx::slice::swap (
    slice & other
) noexcept

Public Static Functions Documentation

function invalid

Builds an invalid slice that has a non-zero length and refers to a null address.

static inline slice mdbx::slice::invalid () noexcept

function null

Build a null slice which zero length and refers to null address.

static inline slice mdbx::slice::null () noexcept

function wrap [1/2]

template<size_t SIZE>
static inline slice mdbx::slice::wrap (
    const char(&) text
) 

function wrap [2/2]

template<typename POD>
static inline slice mdbx::slice::wrap (
    const POD & pod
) 

Protected Functions Documentation

function slice [7/7]

inline constexpr mdbx::slice::slice (
    size_t invalid_length
) noexcept

Friends Documentation

friend operator!=

bool mdbx::slice::operator!= (
    const slice & a,
    const slice & b
) 

friend operator<

bool mdbx::slice::operator< (
    const slice & a,
    const slice & b
) 

friend operator<=

bool mdbx::slice::operator<= (
    const slice & a,
    const slice & b
) 

friend operator==

bool mdbx::slice::operator== (
    const slice & a,
    const slice & b
) 

friend operator>

bool mdbx::slice::operator> (
    const slice & a,
    const slice & b
) 

friend operator>=

bool mdbx::slice::operator>= (
    const slice & a,
    const slice & b
) 


The documentation for this class was generated from the following file docs/mdbx.h++