ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
Acts::JsonKindDispatcher< return_t, args_t > Class Template Reference

JSON-specific dispatcher that routes decoder functions based on a string kind tag found in the encoded payload. More...

#include <ActsPlugins/Json/JsonKindDispatcher.hpp>

Inheritance diagram for Acts::JsonKindDispatcher< return_t, args_t >:
[legend]

Public Types

using decoder_pointer_type = return_t (*)(args_t...)
 Decoder callable pointer type.
using decoder_signature = return_t(const nlohmann::json&, args_t...)
 Function signature type.
using decoder_type = std::function<decoder_signature>
 Decoder callable type.
using self_type = JsonKindDispatcher<return_t, args_t...>
 Type of the dispatcher specialization.

Public Member Functions

 JsonKindDispatcher (std::string kindKey="kind", std::string context="JSON payload")
 Explicit constructor of the dispatcher.
void clear ()
 Clear the registered decoders list.
bool hasKind (std::string_view kind) const
 Check if a certain kind is registered.
template<typename... func_args_t>
requires std::invocable<decoder_pointer_type, func_args_t...>
return_t operator() (const nlohmann::json &encoded, func_args_t &&... args) const
 Decode the registered kind from a json file.
self_typeregisterKind (std::string kind, decoder_type decoder)
 Register a kind and the corresponding decoder.
std::size_t size () const
 Get the number of registered decoders.

Detailed Description

template<typename return_t, typename... args_t>
class Acts::JsonKindDispatcher< return_t, args_t >

JSON-specific dispatcher that routes decoder functions based on a string kind tag found in the encoded payload.

Constructor & Destructor Documentation

◆ JsonKindDispatcher()

template<typename return_t, typename... args_t>
Acts::JsonKindDispatcher< return_t, args_t >::JsonKindDispatcher ( std::string kindKey = "kind",
std::string context = "JSON payload" )
explicit

Explicit constructor of the dispatcher.

Parameters
kindKeythe key containing the type kind in json
contextcontext string for error signaling

Member Function Documentation

◆ hasKind()

template<typename return_t, typename... args_t>
bool Acts::JsonKindDispatcher< return_t, args_t >::hasKind ( std::string_view kind) const

Check if a certain kind is registered.

Parameters
kindthe kind to check for registration
Returns
boolean showing registration status

◆ operator()()

template<typename return_t, typename... args_t>
template<typename... func_args_t>
requires std::invocable<decoder_pointer_type, func_args_t...>
return_t Acts::JsonKindDispatcher< return_t, args_t >::operator() ( const nlohmann::json & encoded,
func_args_t &&... args ) const

Decode the registered kind from a json file.

Parameters
encodedjson file to decode
argsforwarding reference to the decoder arguments
Returns
the object constructed from the json encoding

◆ registerKind()

template<typename return_t, typename... args_t>
self_type & Acts::JsonKindDispatcher< return_t, args_t >::registerKind ( std::string kind,
decoder_type decoder )

Register a kind and the corresponding decoder.

Parameters
kindkind to register
decodercorresponding decoder
Returns
reference to this dispatcher instance

◆ size()

template<typename return_t, typename... args_t>
std::size_t Acts::JsonKindDispatcher< return_t, args_t >::size ( ) const

Get the number of registered decoders.

Returns
number of registered decoders