msl 1.3.0
Loading...
Searching...
No Matches
Iterator.h
Go to the documentation of this file.
1// Copyright 2025-2026 Julien Lamy, ICube, Université de Strasbourg-CNRS.
2// Part of msl, distributed under the terms of the MIT license.
3
4#ifndef _be7f134a_58de_4d2c_9052_d40da0b2c01d
5#define _be7f134a_58de_4d2c_9052_d40da0b2c01d
6
7#include <iterator>
8#include <string>
9
10#include <MrMeasSrv/MeasUtils/NLSStatus.h>
11#include <MrMeasSrv/SeqIF/Sequence/sequmsg.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"
19#include "msl/Iterator.h"
20#include "msl/helpers.h"
21#include "msl/graph/Node.h"
22
23namespace msl
24{
25namespace graph
26{
27
29template<typename T>
30class IteratorTemplate: public Node
31{
32public:
33 DECLARE_POINTERS(IteratorTemplate<T>)
34
35
36 static Pointer New(std::string const & key, Dictionary::Pointer registry={})
37 {
38 return Pointer(new IteratorTemplate<T>(key, registry));
39 }
40
42 template<typename Child>
43 static Pointer New(
44 std::string const & key, Child const & child,
46 {
47 return Pointer(new IteratorTemplate<T>(key, child, registry));
48 }
49
51 static Pointer New(
52 std::string const & key, Siblings const & siblings,
54 {
55 return Pointer(new IteratorTemplate<T>(key, siblings, registry));
56 }
57
58 virtual ~IteratorTemplate() = default;
59
61 NLSStatus prepare(
62 MrProt & protocol, SeqLim & limits, SeqExpo & exports) override
63 {
64 this->_iterator().reset();
65 return this->Node::prepare(protocol, limits, exports);
66 }
67
69 NLSStatus run(
70 MrProt & protocol, SeqLim & limits, SeqExpo & exports) override
71 {
72 this->_iterator().reset();
73 while(!this->_iterator().done())
74 {
75 ON_ERROR_RETURN_STATUS(this->Node::run(protocol, limits, exports));
76 ++this->_iterator();
77 }
78 return MRI_SEQ_SEQU_NORMAL;
79 }
80
82 void reset() override
83 {
84 this->_iterator().reset();
85 this->Node::reset();
86 }
87
92 uint64_t duration() const override
93 {
94 return this->_iterator().end() * this->Node::duration();
95 }
96
101 MrProtocolData::SeqExpoRFInfo rfInfo() const override
102 {
103 // NOTE: using `double(this->_counter().end()) * this->Node::rfInfo()`
104 // as in Loop yields a compilation error on Windows.
105 MrProtocolData::SeqExpoRFInfo rfInfo = this->Node::rfInfo();
106 rfInfo *= this->_iterator().end();
107 return rfInfo;
108 }
109
110private:
111 std::string _key;
112
113 IteratorTemplate(std::string const & key, Dictionary::Pointer registry={})
114 : Node(registry), _key(key)
115 {
116 // Nothing else
117 }
118
119 template<typename Child>
120 IteratorTemplate(
121 std::string const & key, Child const & child,
123 : Node(child, registry), _key(key)
124 {
125 // Nothing else
126 }
127
128 IteratorTemplate(
129 std::string const & key, Siblings const & siblings,
131 : Node(siblings, registry), _key(key)
132 {
133 // Nothing else
134 }
135
136 IteratorTemplate(IteratorTemplate<T> const &) = default;
137 IteratorTemplate(IteratorTemplate<T> &&) = default;
138 IteratorTemplate & operator=(IteratorTemplate<T> const &) = default;
139 IteratorTemplate & operator=(IteratorTemplate<T> &&) = default;
140
141 T const & _iterator() const
142 {
143 return this->get<T>(this->_key);
144 }
145
146 T & _iterator()
147 {
148 return this->get<T>(this->_key);
149 }
150};
151
153template<typename T>
155
157template<typename T>
159
160}
161}
162
163#endif // _be7f134a_58de_4d2c_9052_d40da0b2c01d
Generic key-value associative container.
Definition Dictionary.h:21
std::shared_ptr< Dictionary > Pointer
Reference-counted pointer to Dictionary.
Definition Dictionary.h:34
Dictionary::ConstPointer registry() const
Return the registry.
T const & get(std::string const &key) const
Return an object from the dictionary.
Definition AbstractNode.h:68
Node encapsulating an msl::Iterator.
Definition Iterator.h:31
static Pointer New(std::string const &key, Siblings const &siblings, Dictionary::Pointer registry={})
Definition Iterator.h:51
NLSStatus run(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Definition Iterator.h:69
void reset() override
Definition Iterator.h:82
uint64_t duration() const override
Definition Iterator.h:92
NLSStatus prepare(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Definition Iterator.h:61
MrProtocolData::SeqExpoRFInfo rfInfo() const override
Definition Iterator.h:101
static Pointer New(std::string const &key, Dictionary::Pointer registry={})
Definition Iterator.h:36
static Pointer New(std::string const &key, Child const &child, Dictionary::Pointer registry={})
Definition Iterator.h:43
std::shared_ptr< IteratorTemplate< T > > Pointer
Definition Iterator.h:33
void reset() override
Reset children to a default state.
std::vector< AbstractNode::Pointer > Siblings
Child container.
Definition Node.h:33
NLSStatus prepare(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Prepare all children in order.
Node(Dictionary::Pointer registry={})
Create a node with no child.
MrProtocolData::SeqExpoRFInfo rfInfo() const override
Return the sum of the RF information of the children.
AbstractNode::ConstPointer child(std::size_t index) const
Return a child at given position.
uint64_t duration() const override
Return the sum of the duration of the children.
NLSStatus run(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Run all children in order.
#define DECLARE_POINTERS(name)
Declare pointer type aliases.
Definition helpers.h:83
#define ON_ERROR_RETURN_STATUS(S)
Execute statement S, and, if not MRRESULT_SUCCESS, return the status.
Definition helpers.h:26
Graph-related objects and functions.
Definition AbstractNode.h:24
IteratorTemplate< msl::ConstIterator< T > > ConstIterator
Const iterator node.
Definition Iterator.h:154
IteratorTemplate< msl::Iterator< T > > Iterator
Non-const iterator node.
Definition Iterator.h:158
Top-level namespace of the msl library.
Definition acceleration.h:17
STL namespace.