1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
#ifndef WARPX_INTERVALSPARSER_H_
#define WARPX_INTERVALSPARSER_H_
#include <limits>
#include <string>
#include <vector>
/**
* \brief This class is a parser for slices of the form i:j:k where i, j and k are integers
* representing respectively the starting point, the stopping point and the period.
*/
class SliceParser
{
public:
/**
* \brief Constructor of the SliceParser class.
*
* @param[in] instr an input string of the form "i:j:k", "i:j" or "k" where i, j and k are
* integers representing respectively the starting point, the stopping point and the period.
* Any of these integers may be omitted in which case it will be equal to their default value
* (0 for the starting point, std::numeric_limits<int>::max() for the stopping point and 1 for
* the period). For example SliceParser(":1000:") is equivalent to SliceParser("0:1000:1").
*/
SliceParser (const std::string& instr);
/**
* \brief A method that returns true if the input integer is contained in the slice. (e.g. if
* the list is initialized with "300:500:100", this method returns true if and only if n is
* 300, 400 or 500). If the period is negative or 0, the function always returns false.
*
* @param[in] n the input integer
*/
bool contains (const int n) const;
/**
* \brief A method that returns the smallest integer strictly greater than n such that
* contains(n) is true. Returns std::numeric_limits<int>::max() if there is no such integer.
*
* @param[in] n the input integer
*/
int nextContains (const int n) const;
/**
* \brief A method that returns the greatest integer strictly smaller than n such that
* contains(n) is true. Returns 0 if there is no such integer.
*
* @param[in] n the input integer
*/
int previousContains (const int n) const;
/**
* \brief A method that returns the slice period.
*
*/
int getPeriod () const;
/**
* \brief A method that returns the slice start.
*
*/
int getStart () const;
/**
* \brief A method that returns the slice stop.
*
*/
int getStop () const;
private:
int m_start = 0;
int m_stop = std::numeric_limits<int>::max();
int m_period = 1;
std::string m_separator = ":";
};
/**
* \brief This class is a parser for multiple slices of the form x,y,z,... where x, y and z are
* slices of the form i:j:k, as defined in the SliceParser class. This class contains a vector of
* SliceParsers.
*/
class IntervalsParser
{
public:
/**
* \brief Default constructor of the IntervalsParser class.
*/
IntervalsParser () = default;
/**
* \brief Constructor of the IntervalsParser class.
*
* @param[in] instr_vec an input vector string, which when concatenated is of the form
* "x,y,z,...". This will call the constructor of SliceParser using x, y and z as input
* arguments.
*/
IntervalsParser (const std::vector<std::string>& instr_vec);
/**
* \brief A method that returns true if the input integer is contained in any of the slices
* contained by the IntervalsParser.
*
* @param[in] n the input integer
*/
bool contains (const int n) const;
/**
* \brief A method that returns the smallest integer strictly greater than n such that
* contains(n) is true. Returns std::numeric_limits<int>::max() if there is no such integer.
*
* @param[in] n the input integer
*/
int nextContains (const int n) const;
/**
* \brief A method that returns the greatest integer strictly smaller than n such that
* contains(n) is true. Returns 0 if there is no such integer.
*
* @param[in] n the input integer
*/
int previousContains (const int n) const;
/**
* \brief A method that returns the greatest integer smaller than or equal to n such that
* contains(n) is true. Returns 0 if there is no such integer.
*
* @param[in] n the input integer
*/
int previousContainsInclusive (const int n) const;
/**
* \brief A method the local period (in timesteps) of the IntervalsParser at timestep n.
* The period is defined by nextContains(n) - previousContainsInclusive(n)
*
* @param[in] n the input integer
*/
int localPeriod (const int n) const;
/**
* \brief A method that returns true if any of the slices contained by the IntervalsParser
* has a strictly positive period.
*/
bool isActivated () const;
private:
std::vector<SliceParser> m_slices;
std::string m_separator = ",";
bool m_activated = false;
};
#endif // WARPX_INTERVALSPARSER_H_
|