Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::base::parser::ParseResult< T > Class Template Reference

A parser result, which may contain a result of type T, or an error, or both. More...

#include "donner/base/parser/ParseResult.h"

Public Member Functions

 ParseResult (T &&result)
 Construct from a successful result.
 
 ParseResult (const T &result)
 Construct from a successful result.
 
 ParseResult (ParseError &&error)
 Construct from an error.
 
 ParseResult (T &&result, ParseError &&error)
 Return a result, but also an error.
 
T & result () &
 Returns the contained result.
 
T && result () &&
 Returns the contained result.
 
const T & result () const &
 Returns the contained result.
 
ParseErrorerror () &
 Returns the contained error.
 
ParseError && error () &&
 Returns the contained error.
 
const ParseErrorerror () const &
 Returns the contained error.
 
bool hasResult () const noexcept
 Returns true if this ParseResult contains a valid result.
 
bool hasError () const noexcept
 Returns true if this ParseResult contains an error.
 
template<typename Target , typename Functor >
ParseResult< Targetmap (const Functor &functor) &&
 Map the result of this ParseResult to a new type, by transforming the result with the provided functor.
 
template<typename Target , typename Functor >
ParseResult< TargetmapError (const Functor &functor) &&
 Map the error of this ParseResult to a new type, by transforming the error with the provided functor.
 

Detailed Description

template<typename T>
class donner::base::parser::ParseResult< T >

A parser result, which may contain a result of type T, or an error, or both.

Template Parameters
TResult type.
Examples
svg_to_png.cc, and svg_tree_interaction.cc.

Constructor & Destructor Documentation

◆ ParseResult()

template<typename T >
donner::base::parser::ParseResult< T >::ParseResult ( T && result,
ParseError && error )
inline

Return a result, but also an error.

Used in the case where partial parse results may be returned.

Member Function Documentation

◆ error() [1/3]

template<typename T >
ParseError & donner::base::parser::ParseResult< T >::error ( ) &
inline

Returns the contained error.

Precondition
There is a valid error, i.e. hasError() returns true.
Examples
svg_to_png.cc.

◆ error() [2/3]

template<typename T >
ParseError && donner::base::parser::ParseResult< T >::error ( ) &&
inline

Returns the contained error.

Precondition
There is a valid error, i.e. hasError() returns true.

◆ error() [3/3]

template<typename T >
const ParseError & donner::base::parser::ParseResult< T >::error ( ) const &
inline

Returns the contained error.

Precondition
There is a valid error, i.e. hasError() returns true.

◆ map()

template<typename T >
ParseResult< Target > donner::base::parser::ParseResult< T >::map ( const Functor & functor) &&
inline

Map the result of this ParseResult to a new type, by transforming the result with the provided functor.

Template Parameters
TargetThe type to map to.
FunctorThe functor type.
Parameters
functorThe functor to apply to the result.

◆ mapError()

template<typename T >
ParseResult< Target > donner::base::parser::ParseResult< T >::mapError ( const Functor & functor) &&
inline

Map the error of this ParseResult to a new type, by transforming the error with the provided functor.

Template Parameters
TargetThe type to map to.
FunctorThe functor type.
Parameters
functorThe functor to apply to the error.

◆ result() [1/3]

template<typename T >
T & donner::base::parser::ParseResult< T >::result ( ) &
inline

Returns the contained result.

Precondition
There is a valid result, i.e. hasResult() returns true.
Examples
svg_to_png.cc.

◆ result() [2/3]

template<typename T >
T && donner::base::parser::ParseResult< T >::result ( ) &&
inline

Returns the contained result.

Precondition
There is a valid result, i.e. hasResult() returns true.

◆ result() [3/3]

template<typename T >
const T & donner::base::parser::ParseResult< T >::result ( ) const &
inline

Returns the contained result.

Precondition
There is a valid result, i.e. hasResult() returns true.

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