Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::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/ParseResult.h"

Public Member Functions

 ParseResult (T &&result)
 Construct from a successful result.
 ParseResult (const T &result)
 Construct from a successful result.
 ParseResult (ParseDiagnostic &&error)
 Construct from an error.
 ParseResult (const ParseDiagnostic &error)
 Construct from an error by value.
 ParseResult (T &&result, ParseDiagnostic &&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.
ParseDiagnostic & error () &
 Returns the contained error.
ParseDiagnostic && error () &&
 Returns the contained error.
const ParseDiagnostic & error () 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< Target > map (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< Target > mapError (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::ParseResult< T >

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

Template Parameters
TResult type.
Examples
svg_animation.cc, svg_quickstart.cc, and svg_tree_interaction.cc.

Constructor & Destructor Documentation

◆ ParseResult()

template<typename T>
donner::ParseResult< T >::ParseResult ( T && result,
ParseDiagnostic && 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>
ParseDiagnostic & donner::ParseResult< T >::error ( ) &
inline

Returns the contained error.

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

◆ error() [2/3]

template<typename T>
ParseDiagnostic && donner::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 ParseDiagnostic & donner::ParseResult< T >::error ( ) const &
inline

Returns the contained error.

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

◆ map()

template<typename T>
template<typename Target, typename Functor>
ParseResult< Target > donner::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.

If this ParseResult holds both a result and an error, only the mapped result is kept and the error is discarded.

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

◆ mapError()

template<typename T>
template<typename Target, typename Functor>
ParseResult< Target > donner::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.

If this ParseResult holds both a result and an error, only the mapped error is kept and the result is discarded.

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::ParseResult< T >::result ( ) &
inline

Returns the contained result.

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

◆ result() [2/3]

template<typename T>
T && donner::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::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: