FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::net::rules::ChainedArguments< TValue > Struct Template Reference

This is a wrapper around a Packet and a value for safe extraction. More...

#include <network_manager.hpp>

Public Member Functions

constexpr ChainedArguments (Packet const &pck, TValue *existingValue=nullptr)
constexpr ChainedArguments (Packet const &pck, Error &&err, TValue *existingValue=nullptr)
constexpr ChainedArguments (ChainedArguments const &r)=default
constexpr ChainedArguments (ChainedArguments &&r) noexcept=default
constexpr ChainedArgumentsoperator= (ChainedArguments const &r)=default
constexpr ChainedArgumentsoperator= (ChainedArguments &&r) noexcept=default
constexpr TValue * extract ()
 Extract and verify the value from the packet.
template<class TPeek>
constexpr std::optional< TPeek > peek ()
 Peek without changing the read position a copy of value.
constexpr operator Packet const & () const
constexpr Packet const & packet () const
constexpr TValue const & value () const
constexpr TValue & value ()
template<class TInvokable>
constexpr std::invoke_result_t< TInvokable, ChainedArguments< TValue > & > and_then (TInvokable &&f)
 Chain up some code after a successful extraction.
template<class TInvokable, class TIndex>
constexpr ChainedArguments< TValue > & and_for_each (TIndex iStart, TIndex iEnd, TIndex iIncrement, TInvokable &&f)
 Chain up some code in a for loop after a successful extraction.
template<class TInvokable, class TIndex>
constexpr ChainedArguments< TValue > & and_for_each (TIndex iStart, TIndex iIncrement, TInvokable &&f)
 Chain up some code in a for loop after a successful extraction.
template<class TInvokable>
constexpr ChainedArguments< TValue > & and_for_each (TInvokable &&f)
 Chain up some code in a for loop after a successful extraction.
template<class TInvokable>
constexpr std::optional< Erroron_error (TInvokable &&f)
 Chain up some code after an unsuccessful extraction.
constexpr std::optional< Errorend ()
 End the chain by doing a last validity check on the packet.
constexpr std::optional< Errorfinal ()
 End the chain by doing a last validity check on the packet.
constexpr std::optional< Errorskip () const
 Helper to "continue" in a and_for_each() loop without returning an error.
constexpr std::optional< Errorstop (char const *error, char const *function) const
 Helper to "break" in a and_for_each() loop with a custom error.
constexpr ChainedArguments< TValue > & apply (TValue &value)
 Apply the extracted value to the provided reference.
template<class TInvokable>
constexpr ChainedArguments< TValue > & apply (TInvokable &&f)
 Apply the extracted value to the provided invokable argument.
constexpr ChainedArguments< TValue > & setError (Error &&err)
 Set the error.
constexpr ChainedArguments< TValue > & invalidate (Error &&err)
 Invalidate the packet and set the error.
constexpr ChainedArguments< TValue > & invalidate (char const *error, char const *function)

Detailed Description

template<class TValue>
struct fge::net::rules::ChainedArguments< TValue >

This is a wrapper around a Packet and a value for safe extraction.

A ChainedArguments is the argument for all network extraction rules. The goal is to chain up multiple rules and at the end output an optional error.

When the packet is invalid, the chain will stop and the error will be returned.

Template Parameters
TValueThe type of the value that will be extracted

Member Function Documentation

◆ and_for_each() [1/3]

template<class TValue>
template<class TInvokable, class TIndex>
ChainedArguments< TValue > & fge::net::rules::ChainedArguments< TValue >::and_for_each ( TIndex iStart,
TIndex iEnd,
TIndex iIncrement,
TInvokable && f )
nodiscardconstexpr

Chain up some code in a for loop after a successful extraction.

If the packet is invalid, the chain will stop and the invokable argument will not be called.

Template Parameters
TInvokableThe type of the invokable argument
TIndexThe type of the index
Parameters
iStartThe starting value of the index
iEndThe ending value of the index
iIncrementThe increment value of the index
fThe invokable argument
Returns
A reference to the same ChainedArguments or a new one with a different value type

◆ and_for_each() [2/3]

template<class TValue>
template<class TInvokable, class TIndex>
ChainedArguments< TValue > & fge::net::rules::ChainedArguments< TValue >::and_for_each ( TIndex iStart,
TIndex iIncrement,
TInvokable && f )
nodiscardconstexpr

Chain up some code in a for loop after a successful extraction.

This is the same as and_for_each(TIndex iStart, TIndex iEnd, TIndex iIncrement, TInvokable&& f) but you don't have to provide the end value of the index as it will be got from the last chain result.

Template Parameters
TInvokableThe type of the invokable argument
TIndexThe type of the index
Parameters
iStartThe starting value of the index
iIncrementThe increment value of the index
fThe invokable argument
Returns
A reference to the same ChainedArguments or a new one with a different value type

◆ and_for_each() [3/3]

template<class TValue>
template<class TInvokable>
ChainedArguments< TValue > & fge::net::rules::ChainedArguments< TValue >::and_for_each ( TInvokable && f)
nodiscardconstexpr

Chain up some code in a for loop after a successful extraction.

This is the same as and_for_each(TIndex iStart, TIndex iEnd, TIndex iIncrement, TInvokable&& f) but you don't have to provide any index arguments as the end value of the index as it will be got from the last chain result and the start is 0.

Template Parameters
TInvokableThe type of the invokable argument
Parameters
fThe invokable argument
Returns
A reference to the same ChainedArguments or a new one with a different value type

◆ and_then()

template<class TValue>
template<class TInvokable>
std::invoke_result_t< TInvokable, ChainedArguments< TValue > & > fge::net::rules::ChainedArguments< TValue >::and_then ( TInvokable && f)
nodiscardconstexpr

Chain up some code after a successful extraction.

If the packet is invalid, the chain will stop and the invokable argument will not be called.

Template Parameters
TInvokableThe type of the invokable argument
Parameters
fThe invokable argument
Returns
A reference to the same ChainedArguments or a new one with a different value type

◆ apply() [1/2]

template<class TValue>
template<class TInvokable>
ChainedArguments< TValue > & fge::net::rules::ChainedArguments< TValue >::apply ( TInvokable && f)
constexpr

Apply the extracted value to the provided invokable argument.

Template Parameters
TInvokableThe type of the invokable argument
Parameters
fThe invokable argument
Returns
A reference to the same ChainedArguments

◆ apply() [2/2]

template<class TValue>
ChainedArguments< TValue > & fge::net::rules::ChainedArguments< TValue >::apply ( TValue & value)
constexpr

Apply the extracted value to the provided reference.

If the packet is invalid, the value will not be applied. When applied, the internal value is (if possible) moved to the provided reference. So value() must not be called after this.

Parameters
valueThe reference that will be applied
Returns
A reference to the same ChainedArguments

◆ end()

template<class TValue>
std::optional< Error > fge::net::rules::ChainedArguments< TValue >::end ( )
nodiscardconstexpr

End the chain by doing a last validity check on the packet.

Returns
An optional error

◆ extract()

template<class TValue>
TValue * fge::net::rules::ChainedArguments< TValue >::extract ( )
nodiscardconstexpr

Extract and verify the value from the packet.

If the user as provided an existing value, it will be used instead of creating a new one.

Returns
The extracted value or nullptr if the Packet is/become invalid

◆ final()

template<class TValue>
std::optional< Error > fge::net::rules::ChainedArguments< TValue >::final ( )
nodiscardconstexpr

End the chain by doing a last validity check on the packet.

Also verify the endReached() method on the packet.

Returns
An optional error

◆ invalidate()

template<class TValue>
ChainedArguments< TValue > & fge::net::rules::ChainedArguments< TValue >::invalidate ( Error && err)
constexpr

Invalidate the packet and set the error.

Parameters
errThe error
Returns
A reference to the same ChainedArguments

◆ on_error()

template<class TValue>
template<class TInvokable>
std::optional< Error > fge::net::rules::ChainedArguments< TValue >::on_error ( TInvokable && f)
constexpr

Chain up some code after an unsuccessful extraction.

This must be the last method called in the chain as this return an optional error.

Template Parameters
TInvokableThe type of the invokable argument
Parameters
fThe invokable argument
Returns
An optional error

◆ peek()

template<class TValue>
template<class TPeek>
std::optional< TPeek > fge::net::rules::ChainedArguments< TValue >::peek ( )
nodiscardconstexpr

Peek without changing the read position a copy of value.

Template Parameters
TPeekThe type of the value that will be peeked
Returns
A copy of the peeked value

◆ setError()

template<class TValue>
ChainedArguments< TValue > & fge::net::rules::ChainedArguments< TValue >::setError ( Error && err)
constexpr

Set the error.

Parameters
errThe error
Returns
A reference to the same ChainedArguments

◆ skip()

template<class TValue>
std::optional< Error > fge::net::rules::ChainedArguments< TValue >::skip ( ) const
nodiscardconstexpr

Helper to "continue" in a and_for_each() loop without returning an error.

This should be used only inside a and_for_each() loop.

Returns
An optional error (construct with std::nullopt)

◆ stop()

template<class TValue>
std::optional< Error > fge::net::rules::ChainedArguments< TValue >::stop ( char const * error,
char const * function ) const
nodiscardconstexpr

Helper to "break" in a and_for_each() loop with a custom error.

Parameters
errorThe error message
functionThe function name
Returns
An error built with the provided message

The documentation for this struct was generated from the following files: