msl 1.3.0
Loading...
Searching...
No Matches
If.h
Go to the documentation of this file.
1// Copyright 2024-2026 Julien Lamy, ICube, Université de Strasbourg-CNRS.
2// Part of msl, distributed under the terms of the MIT license.
3
4#ifndef _29882abf_80e7_4434_8f2c_b5109dd75ef7
5#define _29882abf_80e7_4434_8f2c_b5109dd75ef7
6
7#include <functional>
8#include <string>
9
10#include <MrMeasSrv/MeasUtils/NLSStatus.h>
11#include <MrMeasSrv/SeqIF/libRT/sSLICE_POS.h>
12
13#include <MrProtSrv/Domain/CoreNative/SeqLim.h>
14#include <MrProtSrv/Domain/MrProtData/MrProt/MrProt.h>
15#include <MrProtSrv/Domain/MrProtData/MrProt/SeqIF/SeqExpo.h>
16#include <MrProtSrv/Domain/MrProtData/MrProt/SeqIF/SeqExpoRFBlockInfo.h>
17
18#include "msl/Dictionary.h"
20#include "msl/graph/Node.h"
21
22namespace msl
23{
24namespace graph
25{
26
31class If: public Node
32{
33public:
35
38
40 static Pointer New(
41 std::string const & key, Dictionary::Pointer registry={});
42
44 static Pointer New(
45 Function const & function, Dictionary::Pointer registry={});
46
48 template<typename T>
49 static Pointer New(
50 std::string const & key, T const & child,
52
54 template<typename T>
55 static Pointer New(
56 Function const & function, T const & child,
58
60 static Pointer New(
61 std::string const & key, Siblings const & siblings,
63
65 static Pointer New(
66 Function const & function, Siblings const & siblings,
68
69 virtual ~If() = default;
70
72 NLSStatus prepare(
73 MrProt & protocol, SeqLim & limits, SeqExpo & exports) override;
74
76 NLSStatus run(
77 MrProt & protocol, SeqLim & limits, SeqExpo & exports) override;
78
86 uint64_t duration() const override;
87
95 MrProtocolData::SeqExpoRFInfo rfInfo() const override;
96
97private:
98 enum class Mode { Key, Function };
99 Mode _mode;
100 std::string _key;
101 Function _function;
102
103 // Cache for duration and rfInfo, updated when _condition is called
104 mutable uint64_t _duration;
105 mutable MrProtocolData::SeqExpoRFInfo _rfInfo;
106
107 If(std::string const & key, Dictionary::Pointer registry={});
108
109 If(Function const & function, Dictionary::Pointer registry={});
110
111 template<typename T>
112 If(
113 std::string const & key, T const & child,
115
116 template<typename T>
117 If(
118 Function const & function, T const & child,
120
121 If(
122 std::string const & key, Siblings const & siblings,
124
125 If(
126 Function const & function, Siblings const & siblings,
128
129 If(If const &) = default;
130 If(If &&) = default;
131 If & operator=(If const &) = default;
132 If & operator=(If &&) = default;
133
134 bool _condition(MrProt & protocol, SeqLim & limits, SeqExpo & exports) const;
135};
136}
137}
138
139#include "If.txx"
140
141#endif // _29882abf_80e7_4434_8f2c_b5109dd75ef7
std::shared_ptr< Dictionary > Pointer
Reference-counted pointer to Dictionary.
Definition Dictionary.h:34
Dictionary::ConstPointer registry() const
Return the registry.
Node running its children based on a boolean key, a function key, or a function stored in the node.
Definition If.h:32
std::shared_ptr< If > Pointer
Reference-counted pointer to If.
Definition If.h:34
NLSStatus run(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Run the children if the boolean is true.
static Pointer New(Function const &function, Dictionary::Pointer registry={})
Create an If node without children.
static Pointer New(std::string const &key, Siblings const &siblings, Dictionary::Pointer registry={})
Create an If node with multiple children.
static Pointer New(std::string const &key, T const &child, Dictionary::Pointer registry={})
Create an If node with a single child.
uint64_t duration() const override
Return the sum of the duration of the children if the boolean is true, 0 otherwise.
static Pointer New(std::string const &key, Dictionary::Pointer registry={})
Create an If node without children.
MrProtocolData::SeqExpoRFInfo rfInfo() const override
Return the sum of the RF information of the children if the boolean is true, empty RF information oth...
static Pointer New(Function const &function, Siblings const &siblings, Dictionary::Pointer registry={})
Create an If node with multiple children.
FlexibleFunction< bool > Function
Test function.
Definition If.h:37
NLSStatus prepare(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Prepare the children if the boolean is true.
static Pointer New(Function const &function, T const &child, Dictionary::Pointer registry={})
Create an If node with a single child.
std::vector< AbstractNode::Pointer > Siblings
Child container.
Definition Node.h:33
Node(Dictionary::Pointer registry={})
Create a node with no child.
AbstractNode::ConstPointer child(std::size_t index) const
Return a child at given position.
#define DECLARE_POINTERS(name)
Declare pointer type aliases.
Definition helpers.h:83
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
Top-level namespace of the msl library.
Definition acceleration.h:17