FastEngine 0.9.3
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 (fge::net::Packet const &pck, TValue *existingValue=nullptr)
 
constexpr ChainedArguments (fge::net::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 fge::net::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 a unsuccessful extraction.
 
constexpr std::optional< Errorend ()
 End the chain by doing a last validity check on the packet.
 
constexpr std::optional< Errorend (std::nullopt_t nullopt) const
 End the chain without returning an error.
 
constexpr std::optional< Errorend (Error &&err) const
 End the chain by returning 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.
 
template<class TNewValue >
constexpr ChainedArguments< TNewValue > newChain (TNewValue *existingValue=nullptr)
 Create a new chain with a different value type.
 
template<class TNewValue >
constexpr ChainedArguments< TNewValue > newChain (TNewValue *existingValue=nullptr) const
 Create a new chain with a different value type.
 
constexpr ChainedArguments< TValue > & setError (Error &&err)
 Set the error.
 
constexpr ChainedArguments< TValue > & invalidate (Error &&err)
 Invalidate the packet and set the error.
 

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() [1/3]

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

◆ end() [2/3]

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

End the chain by returning a custom error$.

Parameters
errThe error
Returns
An optional error (construct with err)

◆ end() [3/3]

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

End the chain without returning an error.

This is useful when you want to skip in a and_for_each loop.

Parameters
nulloptA nullopt_t
Returns
An optional error (construct with nullopt)

◆ 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

◆ 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

◆ newChain() [1/2]

template<class TValue >
template<class TNewValue >
ChainedArguments< TNewValue > fge::net::rules::ChainedArguments< TValue >::newChain ( TNewValue * existingValue = nullptr)
constexpr

Create a new chain with a different value type.

The packet and the error will be copied/moved to the new chain.

Template Parameters
TNewValueThe type of the new value
Parameters
existingValueAn optional existing value
Returns
A new ChainedArguments with a different value type

◆ newChain() [2/2]

template<class TValue >
template<class TNewValue >
ChainedArguments< TNewValue > fge::net::rules::ChainedArguments< TValue >::newChain ( TNewValue * existingValue = nullptr) const
constexpr

Create a new chain with a different value type.

This const version is generally used in a and_for_each loop. The error isn't forwarded to the new chain.

Template Parameters
TNewValueThe type of the new value
Parameters
existingValueAn optional existing value
Returns
A new ChainedArguments with a different value type

◆ 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 a 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

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