WarpX
Loading...
Searching...
No Matches
IntervalsParser.H
Go to the documentation of this file.
1/* Copyright 2022 The ABLASTR Community
2 *
3 * This file is part of ABLASTR.
4 *
5 * Authors: Neil Zaim, Luca Fedeli, Weiqun Zhang, Axel Huebl
6 * License: BSD-3-Clause-LBNL
7 */
8
9#ifndef ABLASTR_UTILS_TEXT_INTERVALSPARSER_H_
10#define ABLASTR_UTILS_TEXT_INTERVALSPARSER_H_
11
12#include <limits>
13#include <string>
14#include <vector>
15
16
18{
19
25 {
26 public:
38 explicit SliceParser (const std::string& instr, bool require_stop=false);
39
47 [[nodiscard]] bool contains (int n) const;
48
55 [[nodiscard]] int nextContains (int n) const;
56
63 [[nodiscard]] int previousContains (int n) const;
64
69 [[nodiscard]] int getPeriod () const;
70
75 [[nodiscard]] int getStart () const;
76
81 [[nodiscard]] int getStop () const;
82
87 [[nodiscard]] int numContained() const;
88
89 private:
90 bool m_require_stop = false;
91 int m_start = 0;
92 int m_stop = std::numeric_limits<int>::max();
93 int m_period = 1;
94 std::string m_separator = ":";
95
96 };
97
98
105 {
106 public:
110 IntervalsParser () = default;
111
119 explicit IntervalsParser (const std::vector<std::string>& instr_vec);
120
127 [[nodiscard]] bool contains (int n) const;
128
135 [[nodiscard]] int nextContains (int n) const;
136
143 [[nodiscard]] int previousContains (int n) const;
144
151 [[nodiscard]] int previousContainsInclusive (int n) const;
152
159 [[nodiscard]] int localPeriod (int n) const;
160
165 [[nodiscard]] bool isActivated () const;
166
167 private:
168 std::vector<SliceParser> m_slices;
169 std::string m_separator = ",";
170 bool m_activated = false;
171 };
172
173}
174
175#endif // ABLASTR_UTILS_TEXT_INTERVALSPARSER_H_
int previousContains(int n) const
A method that returns the greatest integer strictly smaller than n such that contains(n) is true....
Definition IntervalsParser.cpp:134
bool contains(int n) const
A method that returns true if the input integer is contained in any of the slices contained by the In...
Definition IntervalsParser.cpp:117
bool isActivated() const
A method that returns true if any of the slices contained by the IntervalsParser has a strictly posit...
Definition IntervalsParser.cpp:157
IntervalsParser()=default
Default constructor of the IntervalsParser class.
std::string m_separator
Definition IntervalsParser.H:169
int localPeriod(int n) const
A method the local period (in timesteps) of the IntervalsParser at timestep n. The period is defined ...
Definition IntervalsParser.cpp:151
bool m_activated
Definition IntervalsParser.H:170
int nextContains(int n) const
A method that returns the smallest integer strictly greater than n such that contains(n) is true....
Definition IntervalsParser.cpp:124
int previousContainsInclusive(int n) const
A method that returns the greatest integer smaller than or equal to n such that contains(n) is true....
Definition IntervalsParser.cpp:144
std::vector< SliceParser > m_slices
Definition IntervalsParser.H:168
bool m_require_stop
Definition IntervalsParser.H:90
bool contains(int n) const
A method that returns true if the input integer is contained in the slice. (e.g. if the list is initi...
Definition IntervalsParser.cpp:61
int nextContains(int n) const
A method that returns the smallest integer strictly greater than n such that contains(n) is true....
Definition IntervalsParser.cpp:68
int getPeriod() const
A method that returns the slice period.
Definition IntervalsParser.cpp:87
int m_stop
Definition IntervalsParser.H:92
int numContained() const
A method that returns the number of integers contained by the slice.
Definition IntervalsParser.cpp:96
std::string m_separator
Definition IntervalsParser.H:94
int m_period
Definition IntervalsParser.H:93
int getStop() const
A method that returns the slice stop.
Definition IntervalsParser.cpp:93
int getStart() const
A method that returns the slice start.
Definition IntervalsParser.cpp:90
int m_start
Definition IntervalsParser.H:91
int previousContains(int n) const
A method that returns the greatest integer strictly smaller than n such that contains(n) is true....
Definition IntervalsParser.cpp:78
SliceParser(const std::string &instr, bool require_stop=false)
Constructor of the SliceParser class.
Definition IntervalsParser.cpp:23
Definition IntervalsParser.cpp:21