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<traits::OneofField... TFields>
class proto_structs::Oneof< TFields >

Wrapper for oneof protobuf message fields.

Template Parameters
TFieldsoneof field types

Definition at line 69 of file oneof.hpp.

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. If oneof does not contain any field, returns proto_structs::kOneofNpos .
 
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< TFields... > > & Get () const &
 Returns Index field.
 
template<std::size_t Index>
constexpr OneofAlternativeType< Index, Oneof< TFields... > > & Get () &
 Returns Index field.
 
template<std::size_t Index>
constexpr OneofAlternativeType< Index, Oneof< TFields... > > && Get () &&
 Returns Index field.
 
template<std::size_t Index, typename... TArgs>
constexpr OneofAlternativeType< Index, Oneof< TFields... > > & Emplace (TArgs &&... args)
 Initializes Index field in-place and returns it.
 
template<std::size_t Index>
constexpr void Set (const OneofAlternativeType< Index, Oneof< TFields... > > &value)
 
template<std::size_t Index>
constexpr void Set (OneofAlternativeType< Index, Oneof< TFields... > > &&value)
 
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.
 

Static Public Attributes

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

Constructor & Destructor Documentation

◆ Oneof()

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

Creates oneof wrapper initializing index field.

Definition at line 81 of file oneof.hpp.

Member Function Documentation

◆ Clear()

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

Clear field Index if it is set.

Definition at line 152 of file oneof.hpp.

◆ ClearOneof()

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

Clears oneof.

Definition at line 159 of file oneof.hpp.

◆ Contains()

template<traits::OneofField... TFields>
constexpr bool proto_structs::Oneof< TFields >::Contains ( std::size_t  index) const
inlineconstexprnoexcept

Returns true of oneof contains index field.

Definition at line 89 of file oneof.hpp.

◆ ContainsAny()

template<traits::OneofField... TFields>
constexpr bool proto_structs::Oneof< TFields >::ContainsAny ( ) const
inlineconstexprnoexcept

Returns true of oneof contains some field.

Definition at line 94 of file oneof.hpp.

◆ Emplace()

template<traits::OneofField... TFields>
template<std::size_t Index, typename... TArgs>
constexpr OneofAlternativeType< Index, Oneof< TFields... > > & 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 132 of file oneof.hpp.

◆ Get() [1/3]

template<traits::OneofField... TFields>
template<std::size_t Index>
constexpr OneofAlternativeType< Index, Oneof< TFields... > > & proto_structs::Oneof< TFields >::Get ( ) &
inlineconstexpr

Returns Index field.

Exceptions
OneofAccessErrorif Index field is not set

Definition at line 110 of file oneof.hpp.

◆ Get() [2/3]

template<traits::OneofField... TFields>
template<std::size_t Index>
constexpr OneofAlternativeType< Index, Oneof< TFields... > > && proto_structs::Oneof< TFields >::Get ( ) &&
inlineconstexpr

Returns Index field.

Exceptions
OneofAccessErrorif Index field is not set

Definition at line 121 of file oneof.hpp.

◆ Get() [3/3]

template<traits::OneofField... TFields>
template<std::size_t Index>
constexpr const OneofAlternativeType< Index, Oneof< TFields... > > & proto_structs::Oneof< TFields >::Get ( ) const &
inlineconstexpr

Returns Index field.

Exceptions
OneofAccessErrorif Index field is not set

Definition at line 99 of file oneof.hpp.

◆ GetIndex()

template<traits::OneofField... TFields>
constexpr std::size_t proto_structs::Oneof< TFields >::GetIndex ( ) const
inlineconstexprnoexcept

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 86 of file oneof.hpp.

◆ operator bool()

template<traits::OneofField... TFields>
constexpr proto_structs::Oneof< TFields >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Returns true if oneof contains some field.

Definition at line 162 of file oneof.hpp.

◆ Set() [1/2]

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

Definition at line 142 of file oneof.hpp.

◆ Set() [2/2]

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

Definition at line 147 of file oneof.hpp.

Member Data Documentation

◆ kSize

template<traits::OneofField... TFields>
constexpr std::size_t proto_structs::Oneof< TFields >::kSize = sizeof...(TFields)
inlinestaticconstexpr

Number of fields in the oneof.

Definition at line 72 of file oneof.hpp.


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