userver: proto_structs::Oneof< TFields > Class Template Reference
Loading...
Searching...
No Matches
proto_structs::Oneof< TFields > Class Template Reference

#include </data/code/userver/libraries/proto-structs/include/userver/proto-structs/oneof.hpp>

Detailed Description

template<typename... TFields>
class proto_structs::Oneof< TFields >

Wrapper for oneof protobuf message fields.

Template Parameters
TFieldsoneof field types

Definition at line 20 of file oneof.hpp.

Public Types

using Base = Oneof
 Type of this Oneof.
 

Public Member Functions

constexpr Oneof ()=default
 Creates oneof without any field set.
 
template<std::size_t Index, typename... TArgs>
constexpr Oneof (std::in_place_index_t< Index > index, TArgs &&... args)
 Creates oneof wrapper initializing index field.
 
constexpr std::size_t GetIndex () const noexcept
 Returns zero-based index of the alternative held by the oneof.
 
constexpr bool Contains (std::size_t index) const noexcept
 Returns true of oneof contains index field.
 
constexpr bool ContainsAny () const noexcept
 Returns true of oneof contains some field.
 
template<std::size_t Index>
constexpr const OneofAlternativeType< Index, Oneof > & Get () const &
 Returns Index field.
 
template<std::size_t Index>
constexpr OneofAlternativeType< Index, Oneof > & Get () &
 Returns Index field.
 
template<std::size_t Index>
constexpr OneofAlternativeType< Index, Oneof > && Get () &&
 Returns Index field.
 
template<std::size_t Index, typename... TArgs>
constexpr OneofAlternativeType< Index, Oneof > & Emplace (TArgs &&... args)
 Initializes Index field in-place and returns it.
 
template<std::size_t Index>
constexpr void Set (const OneofAlternativeType< Index, Oneof > &value)
 
template<std::size_t Index>
constexpr void Set (OneofAlternativeType< Index, Oneof > &&value)
 
template<std::size_t Index>
constexpr OneofAlternativeType< Index, Oneof > & GetMutable ()
 If field at Index is not set, sets it. Returns a mutable reference to the field.
 
void Clear (std::size_t index) noexcept
 Clear field Index if it is set.
 
void ClearOneof () noexcept
 Clears oneof.
 
constexpr operator bool () const noexcept
 Returns true if oneof contains some field.
 
bool operator== (const Oneof &other) const =default
 Comparison to another oneof of the same type.
 

Static Public Attributes

static constexpr std::size_t kSize = sizeof...(TFields)
 Number of fields in the oneof.
 

Member Typedef Documentation

◆ Base

template<typename... TFields>
using proto_structs::Oneof< TFields >::Base = Oneof

Type of this Oneof.

Definition at line 23 of file oneof.hpp.

Constructor & Destructor Documentation

◆ Oneof()

template<typename... TFields>
template<std::size_t Index, typename... TArgs>
proto_structs::Oneof< TFields >::Oneof ( std::in_place_index_t< Index > index,
TArgs &&... args )
inlineconstexpr

Creates oneof wrapper initializing index field.

Definition at line 35 of file oneof.hpp.

Member Function Documentation

◆ Clear()

template<typename... TFields>
void proto_structs::Oneof< TFields >::Clear ( std::size_t index)
inlinenoexcept

Clear field Index if it is set.

Definition at line 113 of file oneof.hpp.

◆ ClearOneof()

template<typename... TFields>
void proto_structs::Oneof< TFields >::ClearOneof ( )
inlinenoexcept

Clears oneof.

Definition at line 120 of file oneof.hpp.

◆ Contains()

template<typename... TFields>
bool proto_structs::Oneof< TFields >::Contains ( std::size_t index) const
inlinenodiscardconstexprnoexcept

Returns true of oneof contains index field.

Definition at line 44 of file oneof.hpp.

◆ ContainsAny()

template<typename... TFields>
bool proto_structs::Oneof< TFields >::ContainsAny ( ) const
inlinenodiscardconstexprnoexcept

Returns true of oneof contains some field.

Definition at line 49 of file oneof.hpp.

◆ Emplace()

template<typename... TFields>
template<std::size_t Index, typename... TArgs>
OneofAlternativeType< Index, Oneof > & proto_structs::Oneof< TFields >::Emplace ( TArgs &&... args)
inlineconstexpr

Initializes Index field in-place and returns it.

Template Parameters
TArgsarguments to pass to Index field constructor

Definition at line 87 of file oneof.hpp.

◆ Get() [1/3]

template<typename... TFields>
template<std::size_t Index>
OneofAlternativeType< Index, Oneof > & proto_structs::Oneof< TFields >::Get ( ) &
inlinenodiscardconstexpr

Returns Index field.

Exceptions
OneofAccessErrorif Index field is not set.

Definition at line 65 of file oneof.hpp.

◆ Get() [2/3]

template<typename... TFields>
template<std::size_t Index>
OneofAlternativeType< Index, Oneof > && proto_structs::Oneof< TFields >::Get ( ) &&
inlinenodiscardconstexpr

Returns Index field.

Exceptions
OneofAccessErrorif Index field is not set.

Definition at line 76 of file oneof.hpp.

◆ Get() [3/3]

template<typename... TFields>
template<std::size_t Index>
const OneofAlternativeType< Index, Oneof > & proto_structs::Oneof< TFields >::Get ( ) const &
inlinenodiscardconstexpr

Returns Index field.

Exceptions
OneofAccessErrorif Index field is not set.

Definition at line 54 of file oneof.hpp.

◆ GetIndex()

template<typename... TFields>
std::size_t proto_structs::Oneof< TFields >::GetIndex ( ) const
inlinenodiscardconstexprnoexcept

Returns zero-based index of the alternative held by the oneof.

If oneof does not contain any field, returns proto_structs::kOneofNpos .

Definition at line 41 of file oneof.hpp.

◆ GetMutable()

template<typename... TFields>
template<std::size_t Index>
OneofAlternativeType< Index, Oneof > & proto_structs::Oneof< TFields >::GetMutable ( )
inlinenodiscardconstexpr

If field at Index is not set, sets it. Returns a mutable reference to the field.

Definition at line 104 of file oneof.hpp.

◆ operator bool()

template<typename... TFields>
proto_structs::Oneof< TFields >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Returns true if oneof contains some field.

Definition at line 123 of file oneof.hpp.

◆ Set() [1/2]

template<typename... TFields>
template<std::size_t Index>
void proto_structs::Oneof< TFields >::Set ( const OneofAlternativeType< Index, Oneof< TFields > > & value)
inlineconstexpr

Definition at line 93 of file oneof.hpp.

◆ Set() [2/2]

template<typename... TFields>
template<std::size_t Index>
void proto_structs::Oneof< TFields >::Set ( OneofAlternativeType< Index, Oneof< TFields > > && value)
inlineconstexpr

Definition at line 98 of file oneof.hpp.

Member Data Documentation

◆ kSize

template<typename... TFields>
std::size_t proto_structs::Oneof< TFields >::kSize = sizeof...(TFields)
staticconstexpr

Number of fields in the oneof.

Definition at line 26 of file oneof.hpp.


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