WarpX
Loading...
Searching...
No Matches
ablastr::utils::text::SliceParser Class Reference

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. More...

#include <IntervalsParser.H>

Public Member Functions

 SliceParser (const std::string &instr, bool require_stop=false)
 Constructor of the SliceParser class.
 
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 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.
 
int nextContains (int n) const
 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.
 
int previousContains (int n) const
 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.
 
int getPeriod () const
 A method that returns the slice period.
 
int getStart () const
 A method that returns the slice start.
 
int getStop () const
 A method that returns the slice stop.
 
int numContained () const
 A method that returns the number of integers contained by the slice.
 

Private Attributes

bool m_require_stop = false
 
int m_start = 0
 
int m_stop = std::numeric_limits<int>::max()
 
int m_period = 1
 
std::string m_separator = ":"
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SliceParser()

ablastr::utils::text::SliceParser::SliceParser ( const std::string & instr,
bool require_stop = false )
explicit

Constructor of the SliceParser class.

Parameters
[in]instran 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").
[in]require_stopwhether the stopping point must be explicitly specified (e.g., for back-transformed diagnostics)

Member Function Documentation

◆ contains()

bool ablastr::utils::text::SliceParser::contains ( int n) const
nodiscard

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.

Parameters
[in]nthe input integer

◆ getPeriod()

int ablastr::utils::text::SliceParser::getPeriod ( ) const
nodiscard

A method that returns the slice period.

◆ getStart()

int ablastr::utils::text::SliceParser::getStart ( ) const
nodiscard

A method that returns the slice start.

◆ getStop()

int ablastr::utils::text::SliceParser::getStop ( ) const
nodiscard

A method that returns the slice stop.

◆ nextContains()

int ablastr::utils::text::SliceParser::nextContains ( int n) const
nodiscard

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.

Parameters
[in]nthe input integer

◆ numContained()

int ablastr::utils::text::SliceParser::numContained ( ) const
nodiscard

A method that returns the number of integers contained by the slice.

◆ previousContains()

int ablastr::utils::text::SliceParser::previousContains ( int n) const
nodiscard

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.

Parameters
[in]nthe input integer

Member Data Documentation

◆ m_period

int ablastr::utils::text::SliceParser::m_period = 1
private

◆ m_require_stop

bool ablastr::utils::text::SliceParser::m_require_stop = false
private

◆ m_separator

std::string ablastr::utils::text::SliceParser::m_separator = ":"
private

◆ m_start

int ablastr::utils::text::SliceParser::m_start = 0
private

◆ m_stop

int ablastr::utils::text::SliceParser::m_stop = std::numeric_limits<int>::max()
private

The documentation for this class was generated from the following files: