msl 1.3.0
Loading...
Searching...
No Matches
FlexibleFunction.h
Go to the documentation of this file.
1// Copyright 2025 Julien Lamy, ICube, Université de Strasbourg-CNRS.
2// Part of msl, distributed under the terms of the MIT license.
3
4#ifndef _b7df6a58_79dd_4d8c_92ab_616d6fe3c0ce
5#define _b7df6a58_79dd_4d8c_92ab_616d6fe3c0ce
6
7#include <functional>
8
9#include <boost/variant/variant.hpp>
10
11#include <MrProtSrv/Domain/CoreNative/SeqLim.h>
12#include <MrProtSrv/Domain/MrProtData/MrProt/MrProt.h>
13#include <MrProtSrv/Domain/MrProtData/MrProt/SeqIF/SeqExpo.h>
14
15#include "msl/Dictionary.h"
16
17namespace msl
18{
19
20namespace graph
21{
22
28template<typename T>
29using FlexibleFunction = boost::variant<
30 std::function<T()>,
31 std::function<T(Dictionary::Pointer)>,
32 std::function<T(MrProt &)>,
33 std::function<T(MrProt &, Dictionary::Pointer)>,
34 std::function<T(MrProt &, SeqLim &, SeqExpo &)>,
35 std::function<T(MrProt &, SeqLim &, SeqExpo &, Dictionary::Pointer)>>;
36
38template<typename T>
39class FlexibleFunctionAdapter: public boost::static_visitor<
40 std::function<T(MrProt &, SeqLim &, SeqExpo &, Dictionary::Pointer)>>
41{
42public:
43 using typename boost::static_visitor<
44 std::function<T(MrProt &, SeqLim &, SeqExpo &, Dictionary::Pointer)>
45 >::result_type;
46
48 result_type operator()(std::function<T()> const & f) const
49 {
50 return [&](MrProt &, SeqLim &, SeqExpo &, msl::Dictionary::Pointer){
51 return f(); };
52 }
53
55 result_type operator()(
56 std::function<T(Dictionary::Pointer)> const & f) const
57 {
58 return [&](MrProt &, SeqLim &, SeqExpo &, Dictionary::Pointer d){
59 return f(d); };
60 }
61
63 result_type operator()(std::function<T(MrProt &)> const & f) const
64 {
65 return [&](MrProt & p, SeqLim &, SeqExpo &, Dictionary::Pointer){
66 return f(p); };
67 }
68
70 result_type operator()(
71 std::function<T(MrProt &, Dictionary::Pointer)> const & f) const
72 {
73 return [&](MrProt & p, SeqLim &, SeqExpo &, Dictionary::Pointer d){
74 return f(p, d); };
75 }
76
78 result_type operator()(
79 std::function<T(MrProt &, SeqLim &, SeqExpo &)> const & f) const
80 {
81 return [&](MrProt & p, SeqLim & l, SeqExpo & e, Dictionary::Pointer){
82 return f(p, l, e); };
83 }
84
86 result_type operator()(
87 std::function<T(MrProt &, SeqLim &, SeqExpo &, msl::Dictionary::Pointer)> const & f) const
88 {
89 return f;
90 }
91};
92
94template<typename T>
95std::function<T(MrProt &, SeqLim &, SeqExpo &, Dictionary::Pointer)>
97{
98 return boost::apply_visitor(FlexibleFunctionAdapter<T>{}, f);
99}
100
101}
102
103}
104
105#endif // _b7df6a58_79dd_4d8c_92ab_616d6fe3c0ce
std::shared_ptr< Dictionary > Pointer
Reference-counted pointer to Dictionary.
Definition Dictionary.h:34
Adapt a FlexibleFunction to its nominal form.
Definition FlexibleFunction.h:41
result_type operator()(std::function< T()> const &f) const
Adapt an empty function.
Definition FlexibleFunction.h:48
result_type operator()(std::function< T(MrProt &, Dictionary::Pointer)> const &f) const
Adapt an (protocol, dictionary) function.
Definition FlexibleFunction.h:70
result_type operator()(std::function< T(Dictionary::Pointer)> const &f) const
Adapt an (dictionary) function.
Definition FlexibleFunction.h:55
result_type operator()(std::function< T(MrProt &)> const &f) const
Adapt an (protocol) function.
Definition FlexibleFunction.h:63
result_type operator()(std::function< T(MrProt &, SeqLim &, SeqExpo &, msl::Dictionary::Pointer)> const &f) const
Adapt an (protocol, limits, exports, dictionary) function.
Definition FlexibleFunction.h:86
result_type operator()(std::function< T(MrProt &, SeqLim &, SeqExpo &)> const &f) const
Adapt an (protocol, limits, exports) function.
Definition FlexibleFunction.h:78
Graph-related objects and functions.
Definition AbstractNode.h:24
boost::variant< std::function< T()>, std::function< T(Dictionary::Pointer)>, std::function< T(MrProt &)>, std::function< T(MrProt &, Dictionary::Pointer)>, std::function< T(MrProt &, SeqLim &, SeqExpo &)>, std::function< T(MrProt &, SeqLim &, SeqExpo &, Dictionary::Pointer)> > FlexibleFunction
A graph function (e.g. Case or If), with flexible arguments.
Definition FlexibleFunction.h:29
std::function< T(MrProt &, SeqLim &, SeqExpo &, Dictionary::Pointer)> function_adapter(FlexibleFunction< T > const &f)
Adapt a FlexibleFunction to its nominal form.
Definition FlexibleFunction.h:96
Top-level namespace of the msl library.
Definition acceleration.h:17