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

#include </home/antonyzhilin/arcadia/taxi/uservices/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 Types

using Base = Oneof
 Type of this Oneof base class specialization.
 

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 > & 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.
 

Static Public Attributes

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

Member Typedef Documentation

◆ Base

template<traits::OneofField... TFields>
using proto_structs::Oneof< TFields >::Base = Oneof

Type of this Oneof base class specialization.

Definition at line 72 of file oneof.hpp.

Constructor & Destructor Documentation

◆ Oneof()

template<traits::OneofField... 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 84 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 161 of file oneof.hpp.

◆ ClearOneof()

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

Clears oneof.

Definition at line 168 of file oneof.hpp.

◆ Contains()

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

Returns true of oneof contains index field.

Definition at line 92 of file oneof.hpp.

◆ ContainsAny()

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

Returns true of oneof contains some field.

Definition at line 97 of file oneof.hpp.

◆ Emplace()

template<traits::OneofField... 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 135 of file oneof.hpp.

◆ Get() [1/3]

template<traits::OneofField... 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 113 of file oneof.hpp.

◆ Get() [2/3]

template<traits::OneofField... 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 124 of file oneof.hpp.

◆ Get() [3/3]

template<traits::OneofField... 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 102 of file oneof.hpp.

◆ GetIndex()

template<traits::OneofField... 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 89 of file oneof.hpp.

◆ GetMutable()

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

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

Definition at line 152 of file oneof.hpp.

◆ operator bool()

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

Returns true if oneof contains some field.

Definition at line 171 of file oneof.hpp.

◆ Set() [1/2]

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

Definition at line 141 of file oneof.hpp.

◆ Set() [2/2]

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

Definition at line 146 of file oneof.hpp.

Member Data Documentation

◆ kSize

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

Number of fields in the oneof.

Definition at line 75 of file oneof.hpp.


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