msl 1.3.0
Loading...
Searching...
No Matches
Case.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 _c1c4f441_160f_46bf_869e_1bf9c199aa91
5#define _c1c4f441_160f_46bf_869e_1bf9c199aa91
6
7#include <unordered_map>
8
9#include <MrMeasSrv/MeasUtils/NLSStatus.h>
10#include <MrMeasSrv/SeqIF/Sequence/sequmsg.h>
11
12#include <MrProtSrv/Domain/CoreNative/SeqLim.h>
13#include <MrProtSrv/Domain/MrProtData/MrProt/MrProt.h>
14#include <MrProtSrv/Domain/MrProtData/MrProt/SeqIF/SeqExpo.h>
15#include <MrProtSrv/Domain/MrProtData/MrProt/SeqIF/SeqExpoRFBlockInfo.h>
16
17#include "msl/Dictionary.h"
20#include "msl/graph/Node.h"
21#include "msl/helpers.h"
22
23namespace msl
24{
25namespace graph
26{
27
32template<typename T>
33class Case: public AbstractNode
34{
35public:
37 using Map = std::unordered_map<T, AbstractNode::Pointer>;
38
41
43
45 static Pointer New(
46 std::string const & key, Map const & cases,
48
50 static Pointer New(
51 Function const & function, Map const & cases,
53
60 NLSStatus prepare(
61 MrProt & protocol, SeqLim & limits, SeqExpo & exports) override;
62
69 NLSStatus run(
70 MrProt & protocol, SeqLim & limits, SeqExpo & exports) override;
71
73 void reset() override;
74
77
82 uint64_t duration() const override;
83
88 MrProtocolData::SeqExpoRFInfo rfInfo() const override;
89
90private:
91 enum class Mode { Key, Function };
92 Mode _mode;
93 std::string _key;
94 Function _function;
95
96 Map _cases;
97
98 // Cache for duration and rfInfo, updated when _condition is called
99 mutable uint64_t _duration;
100 mutable MrProtocolData::SeqExpoRFInfo _rfInfo;
101
102 Case(
103 std::string const & key, Map const & cases,
105
106 Case(
107 Function const & function, Map const & cases,
109
111 MrProt & protocol, SeqLim & limits, SeqExpo & exports) const;
112
114 MrProt & protocol, SeqLim & limits, SeqExpo & exports);
115};
116
117}
118}
119
120#include "Case.txx"
121
122#endif // _c1c4f441_160f_46bf_869e_1bf9c199aa91
std::shared_ptr< Dictionary > Pointer
Reference-counted pointer to Dictionary.
Definition Dictionary.h:34
std::shared_ptr< AbstractNode > Pointer
Reference-counted pointer to AbstractNode.
Definition AbstractNode.h:30
std::shared_ptr< AbstractNode const > ConstPointer
Reference-counted constant pointer to AbstractNode.
Definition AbstractNode.h:30
Dictionary::ConstPointer registry() const
Return the registry.
AbstractNode(Dictionary::Pointer registry={})
Create a node with the given registry.
Node encapsulating a switch/case structure based on a boolean key or a function key.
Definition Case.h:34
static Pointer New(std::string const &key, Map const &cases, Dictionary::Pointer registry={})
Create a case node pointing to a key in the registry.
NLSStatus prepare(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Prepare the selected child, throw an exception if unknown value.
NLSStatus run(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Run the selected child, throw an exception if unknown value.
FlexibleFunction< T > Function
Case function.
Definition Case.h:40
static Pointer New(Function const &function, Map const &cases, Dictionary::Pointer registry={})
Create a case node holding a function.
Case & setRegistry(Dictionary::Pointer registry) override
Set the registry to this node and its children.
std::shared_ptr< Case< T > > Pointer
Reference-counted pointer to Case<T>.
Definition Case.h:42
std::unordered_map< T, AbstractNode::Pointer > Map
Dictionary to dispatch key to function.
Definition Case.h:37
MrProtocolData::SeqExpoRFInfo rfInfo() const override
Return the RF information of the selected child, throw an exception if unknown value.
uint64_t duration() const override
Return the duration of the selected child, throw an exception if unknown value.
void reset() override
Reset all branches to a default state.
#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