msl 1.3.0
Loading...
Searching...
No Matches
Iterator.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 _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>
31{
32public:
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
85 uint64_t duration() const override
86 {
87 return this->_iterator().end() * this->Node::duration();
88 }
89
94 MrProtocolData::SeqExpoRFInfo rfInfo() const override
95 {
96 // NOTE: using `double(this->_counter().end()) * this->Node::rfInfo()`
97 // as in Loop yields a compilation error on Windows.
98 MrProtocolData::SeqExpoRFInfo rfInfo = this->Node::rfInfo();
99 rfInfo *= this->_iterator().end();
100 return rfInfo;
101 }
102
103private:
104 std::string _key;
105
106 IteratorTemplate(std::string const & key, Dictionary::Pointer registry={})
107 : Node(registry), _key(key)
108 {
109 // Nothing else
110 }
111
112 template<typename Child>
113 IteratorTemplate(
114 std::string const & key, Child const & child,
116 : Node(child, registry), _key(key)
117 {
118 // Nothing else
119 }
120
121 IteratorTemplate(
122 std::string const & key, Siblings const & siblings,
124 : Node(siblings, registry), _key(key)
125 {
126 // Nothing else
127 }
128
129 IteratorTemplate(IteratorTemplate<T> const &) = default;
130 IteratorTemplate(IteratorTemplate<T> &&) = default;
131 IteratorTemplate & operator=(IteratorTemplate<T> const &) = default;
132 IteratorTemplate & operator=(IteratorTemplate<T> &&) = default;
133
134 T const & _iterator() const
135 {
136 return this->get<T>(this->_key);
137 }
138
139 T & _iterator()
140 {
141 return this->get<T>(this->_key);
142 }
143};
144
146template<typename T>
148
150template<typename T>
152
153}
154}
155
156#endif // _be7f134a_58de_4d2c_9052_d40da0b2c01d
#define DECLARE_POINTERS(name)
Declare pointer type aliases.
Definition Dictionary.h:18
Generic key-value associative container.
Definition Dictionary.h:26
std::shared_ptr< Dictionary > Pointer
Reference-counted pointer to Dictionary
Definition Dictionary.h:39
Dictionary::ConstPointer registry() const
Return the registry.
Node encapsulating an msl::Iterator.
Definition Iterator.h:31
static Pointer New(std::string const &key, Siblings const &siblings, Dictionary::Pointer registry={})
Create an iterator with multiple children.
Definition Iterator.h:51
NLSStatus run(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Run the children for each item of the iterator range.
Definition Iterator.h:69
uint64_t duration() const override
Return the sum of the duration of the children times the number of items of the iterator range.
Definition Iterator.h:85
std::shared_ptr< IteratorTemplate< T > > Pointer
Reference-counted pointer to IteratorTemplate<T>
Definition Iterator.h:33
NLSStatus prepare(MrProt &protocol, SeqLim &limits, SeqExpo &exports) override
Prepare the children.
Definition Iterator.h:61
virtual ~IteratorTemplate()=default
MrProtocolData::SeqExpoRFInfo rfInfo() const override
Return the sum of the RF information of the children times the number of items of the iterator range.
Definition Iterator.h:94
static Pointer New(std::string const &key, Dictionary::Pointer registry={})
Create an iterator with no child.
Definition Iterator.h:36
static Pointer New(std::string const &key, Child const &child, Dictionary::Pointer registry={})
Create an iterator with a single child.
Definition Iterator.h:43
Container node, prepare and run its children sequentially.
Definition Node.h:28
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.
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 ON_ERROR_RETURN_STATUS(S)
Execute statement S, and, if not MRRESULT_SUCCESS, return the status.
Definition helpers.h:21
Top-level namespace of the msl library.
Definition acceleration.h:17
STL namespace.