netxsimdg
Loading...
Searching...
No Matches
Iterator.hpp
Go to the documentation of this file.
1
7#ifndef SRC_INCLUDE_ITERATOR_HPP
8#define SRC_INCLUDE_ITERATOR_HPP
9
10#include "Logged.hpp"
11#include "Time.hpp"
12
13namespace Nextsim {
14
16class Iterator {
17public:
18 typedef TimePoint::Clock Clock;
19 class Iterant;
20
21 Iterator();
23 Iterator(Iterant* iterant);
24
30 void setIterant(Iterant* iterant);
31
40 void setStartStopStep(TimePoint startTime, TimePoint stopTime, Duration timestep);
49 void setStartDurationStep(TimePoint startTime, Duration duration, Duration timestep);
50
63 TimePoint parseAndSet(const std::string& startTimeStr, const std::string& stopTimeStr,
64 const std::string& durationStr, const std::string& stepStr);
66 void run();
67
68private:
69 Iterant* iterant; // FIXME smart pointer
70 TimePoint startTime;
71 TimePoint stopTime;
72 Duration timestep;
73
74public:
76 class Iterant {
77 public:
78 // Define the constructors and copy operator as default to be
79 // rule of 5 compliant, given the virtual destructor
80 Iterant() = default;
81 Iterant(const Iterant& copyFrom) = default;
82 Iterant& operator=(const Iterant& copyFrom) = default;
83 Iterant(Iterant&&) = default;
84 Iterant& operator=(Iterant&&) = default;
85
86 virtual ~Iterant() = default;
87
89 virtual void init() = 0;
95 virtual void start(const TimePoint& startTime) = 0;
101 virtual void iterate(const TimestepTime& dt) = 0;
107 virtual void stop(const TimePoint& stopTime) = 0;
108 };
109
111 class NullIterant : public Iterant {
112 inline void init() {};
113 inline void start(const TimePoint& startTime) {};
114 inline void iterate(const TimestepTime& dt) {};
115 inline void stop(const TimePoint& stopTime) {};
116 };
117
120};
121
122} /* namespace Nextsim */
123
124#endif /* SRC_INCLUDE_ITERATOR_HPP */
A base class for classes that specify what happens during one timestep.
Definition Iterator.hpp:76
virtual void init()=0
Initializes the model, based on some environment stored in the implementing class.
virtual void iterate(const TimestepTime &dt)=0
virtual void stop(const TimePoint &stopTime)=0
virtual void start(const TimePoint &startTime)=0
A simple Iterant that does nothing.
Definition Iterator.hpp:111
A class that controls how time steps are performed.
Definition Iterator.hpp:16
void run()
Run the Iterant over the specified time period.
Definition Iterator.cpp:54
TimePoint parseAndSet(const std::string &startTimeStr, const std::string &stopTimeStr, const std::string &durationStr, const std::string &stepStr)
Parses the four strings and sets the time parameters from them.
Definition Iterator.cpp:34
void setStartDurationStep(TimePoint startTime, Duration duration, Duration timestep)
Sets the time parameters as a start time, run length and timestep length.
static NullIterant nullIterant
A static instance of the NullIterant class.
Definition Iterator.hpp:119
void setStartStopStep(TimePoint startTime, TimePoint stopTime, Duration timestep)
Sets the time parameters as a start time, stop time and timestep length.
Definition Iterator.cpp:27
void setIterant(Iterant *iterant)
Sets the iterant to be iterated using a pointer.
Definition Iterator.cpp:25