userver: formats::common::ConversionStack< ValueFrom, ValueToBuilder > Class Template Reference
Loading...
Searching...
No Matches
formats::common::ConversionStack< ValueFrom, ValueToBuilder > Class Template Referencefinal

#include <userver/formats/common/conversion_stack.hpp>

Detailed Description

template<typename ValueFrom, typename ValueToBuilder>
class formats::common::ConversionStack< ValueFrom, ValueToBuilder >

Used in the implementation of functions that convert between different formats, e.g. formats::yaml::Value to formats::json::Value, etc.

Does not use recursion, so stack overflow will never happen with deeply nested or wide objects or arrays.

Template Parameters
ValueFromthe Value type, FROM which we convert, e.g. formats::yaml::Value
ValueToBuilderthe ValueBuilder type, TO which we convert, e.g. formats::json::ValueBuilder

How to build the conversion function:

  1. Start by constructing the ConversionStack from the source ValueFrom
  2. While !IsParsed:
    1. call GetNextFrom
    2. analyse the kind of the current ValueFrom
    3. call one of:
      • CastCurrentPrimitive
      • SetCurrent
      • EnterItems
  3. Call GetParsed

See the implementation of PerformMinimalFormatConversion as an example.

Definition at line 47 of file conversion_stack.hpp.

Public Member Functions

 ConversionStack (ValueFrom value)
 Start the conversion from value.
 
 ConversionStack (ConversionStack &&)=delete
 
ConversionStackoperator= (ConversionStack &&)=delete
 
bool IsParsed () const
 Check whether the whole source ValueFrom has been parsed.
 
ValueToBuilder && GetParsed () &&
 Get the parsing result, precondition: IsParsed().
 
const ValueFrom & GetNextFrom () const
 Get the current sub-ValueFrom to convert.
 
template<typename T >
void CastCurrentPrimitive ()
 
template<typename T >
void SetCurrent (T &&value)
 
void EnterItems ()
 Use for when an object or an array ValueFrom is encountered.
 

Constructor & Destructor Documentation

◆ ConversionStack()

template<typename ValueFrom , typename ValueToBuilder >
formats::common::ConversionStack< ValueFrom, ValueToBuilder >::ConversionStack ( ValueFrom value)
inlineexplicit

Start the conversion from value.

Definition at line 50 of file conversion_stack.hpp.

Member Function Documentation

◆ CastCurrentPrimitive()

template<typename ValueFrom , typename ValueToBuilder >
template<typename T >
void formats::common::ConversionStack< ValueFrom, ValueToBuilder >::CastCurrentPrimitive ( )
inline

Use for when it's discovered that the current ValueFrom type is available and has the same semantics in ValueFrom and ValueToBuilder, e.g. std::int64_t, std::string, etc.

Definition at line 81 of file conversion_stack.hpp.

◆ EnterItems()

template<typename ValueFrom , typename ValueToBuilder >
void formats::common::ConversionStack< ValueFrom, ValueToBuilder >::EnterItems ( )
inline

Use for when an object or an array ValueFrom is encountered.

Definition at line 98 of file conversion_stack.hpp.

◆ GetNextFrom()

template<typename ValueFrom , typename ValueToBuilder >
const ValueFrom & formats::common::ConversionStack< ValueFrom, ValueToBuilder >::GetNextFrom ( ) const
inline

Get the current sub-ValueFrom to convert.

Definition at line 67 of file conversion_stack.hpp.

◆ GetParsed()

template<typename ValueFrom , typename ValueToBuilder >
ValueToBuilder && formats::common::ConversionStack< ValueFrom, ValueToBuilder >::GetParsed ( ) &&
inline

Get the parsing result, precondition: IsParsed().

Definition at line 61 of file conversion_stack.hpp.

◆ IsParsed()

template<typename ValueFrom , typename ValueToBuilder >
bool formats::common::ConversionStack< ValueFrom, ValueToBuilder >::IsParsed ( ) const
inline

Check whether the whole source ValueFrom has been parsed.

Definition at line 58 of file conversion_stack.hpp.

◆ SetCurrent()

template<typename ValueFrom , typename ValueToBuilder >
template<typename T >
void formats::common::ConversionStack< ValueFrom, ValueToBuilder >::SetCurrent ( T && value)
inline

Use for when it's discovered that the current ValueFrom type is not directly convertible to ValueToBuilder, but can be converted manually (this might be an inexact conversion). For example, ValueFrom could have a special representation for datetime, and we manually convert it to string using some arbitrary format.

Definition at line 92 of file conversion_stack.hpp.


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