All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Attributes | List of all members
icarus::details::IntegerRangesBase< T > Class Template Reference

A sequence of contiguous ranges of integral numbers. More...

#include <IntegerRanges.h>

Inheritance diagram for icarus::details::IntegerRangesBase< T >:
icarus::IntegerRanges< T, CheckGrowing >

Classes

struct  Range_t
 

Public Types

using Data_t = T
 Type of data for the range set. More...
 

Public Member Functions

void clear () noexcept
 Removes all the entries and makes the set as default-constructed. More...
 
void dump (std::ostream &out, std::string const &sep=" ", std::string const &inRangeSep="--") const
 
template<bool CheckGrowing, typename BIter , typename EIter >
auto compactRange (BIter b, EIter e) -> std::vector< Range_t >
 
Queries
bool empty () const noexcept
 Returns whether there is any element in the range set. More...
 
std::size_t size () const noexcept
 Returns the number of elements in the ranges (gaps excluded). More...
 
std::size_t nRanges () const noexcept
 Returns the number of non-contiguous ranges in the set. More...
 
decltype(auto) ranges () const noexcept
 Returns an iterable object with all sorted ranges as elements. More...
 

Protected Member Functions

 IntegerRangesBase ()=default
 Default constructor: starts with no elements. More...
 
 IntegerRangesBase (std::vector< Range_t > ranges)
 Constructor for the derived classes. More...
 

Static Protected Member Functions

template<bool CheckGrowing, typename BIter , typename EIter >
static std::vector< Range_tcompactRange (BIter b, EIter e)
 Fills the ranges. More...
 
static constexpr Data_t plusOne (Data_t value) noexcept
 Returns value incremented by 1. More...
 
static constexpr Data_t minusOne (Data_t value) noexcept
 Returns value decremented by 1. More...
 

Private Attributes

std::vector< Range_tfRanges
 List of current ranges. More...
 

Detailed Description

template<typename T = int>
class icarus::details::IntegerRangesBase< T >

A sequence of contiguous ranges of integral numbers.

Template Parameters
Ttype of the integral numbers
CheckGrowingif true, checks will be performed on construction

This class parses a sequence in input grouping the consecutive elements. The current interface is very simple, allowing only for query of groups ("ranges") and printing to a stream. The input is required and assumed to be a monotonously growing sequence, with the exception that duplicate consecutive entries are allowed (and ignored).

Each range is stored as a semi-open interval: [ lower, upper [.

Definition at line 29 of file IntegerRanges.h.

Member Typedef Documentation

template<typename T = int>
using icarus::details::IntegerRangesBase< T >::Data_t = T

Type of data for the range set.

Definition at line 79 of file IntegerRanges.h.

Constructor & Destructor Documentation

template<typename T = int>
icarus::details::IntegerRangesBase< T >::IntegerRangesBase ( )
protecteddefault

Default constructor: starts with no elements.

template<typename T >
icarus::details::IntegerRangesBase< T >::IntegerRangesBase ( std::vector< Range_t ranges)
protected

Constructor for the derived classes.

Definition at line 300 of file IntegerRanges.h.

300  : fRanges(std::move(ranges))
301  {}
std::vector< Range_t > fRanges
List of current ranges.

Member Function Documentation

template<typename T >
void icarus::details::IntegerRangesBase< T >::clear ( )
noexcept

Removes all the entries and makes the set as default-constructed.

Definition at line 306 of file IntegerRanges.h.

307  { return fRanges.clear(); }
std::vector< Range_t > fRanges
List of current ranges.
template<typename T = int>
template<bool CheckGrowing, typename BIter , typename EIter >
static std::vector<Range_t> icarus::details::IntegerRangesBase< T >::compactRange ( BIter  b,
EIter  e 
)
staticprotected

Fills the ranges.

template<typename T = int>
template<bool CheckGrowing, typename BIter , typename EIter >
auto icarus::details::IntegerRangesBase< T >::compactRange ( BIter  b,
EIter  e 
) -> std::vector<Range_t>

Definition at line 341 of file IntegerRanges.h.

343 {
344  if (b == e) return {};
345 
346  std::vector<Range_t> ranges;
347 
348  auto it = b;
349  auto iPrev = it; // not sure if BIter default-constructible, so copy instead
350  auto iFirst = b;
351 
352  while (it != e) {
353 
354  iPrev = it++;
355 
356  if (it != e) { // check current and previous elements
357  if (*iPrev == *it) continue; // duplicate entry: quietly skip
358  if constexpr (CheckGrowing) {
359  if (*it < *iPrev) {
360  using std::to_string;
361  throw std::runtime_error{ "icarus::IntegerRanges"
362  " initialized with non-monotonically growing sequence ("
363  + to_string(*iPrev) + " then " + to_string(*it)
364  + ")"
365  };
366  }
367  } // if checking growth
368  } // if not at the end
369 
370  auto const nextExpected = plusOne(*iPrev);
371 
372  if ((it != e) && (*it == nextExpected)) continue; // contiguous to previous
373 
374  ranges.emplace_back(*iFirst, nextExpected);
375 
376  iFirst = it;
377 
378  } // while
379 
380  return ranges;
381 } // icarus::details::IntegerRangesBase<>::compactRange()
static constexpr Data_t plusOne(Data_t value) noexcept
Returns value incremented by 1.
std::string to_string(WindowPattern const &pattern)
do i e
decltype(auto) ranges() const noexcept
Returns an iterable object with all sorted ranges as elements.
template<typename T >
void icarus::details::IntegerRangesBase< T >::dump ( std::ostream &  out,
std::string const &  sep = " ",
std::string const &  inRangeSep = "--" 
) const

Prints the range into the specified stream.

Parameters
outthe stream to print into
sepseparator between ranges
inRangeSepseparator between lower and higher limit of each range

Definition at line 400 of file IntegerRanges.h.

404  {
405 
406  if (empty()) return;
407 
408  auto iRange = fRanges.begin();
409  auto const rend = fRanges.end();
410  iRange->dump(out, inRangeSep, sep);
411  while (++iRange != rend) iRange->dump(out << sep, inRangeSep, sep);
412 
413 } // icarus::details::IntegerRangesBase<>::dump()
bool empty() const noexcept
Returns whether there is any element in the range set.
std::vector< Range_t > fRanges
List of current ranges.
template<typename T >
bool icarus::details::IntegerRangesBase< T >::empty ( ) const
noexcept

Returns whether there is any element in the range set.

Definition at line 312 of file IntegerRanges.h.

313  { return fRanges.empty(); }
std::vector< Range_t > fRanges
List of current ranges.
template<typename T >
constexpr auto icarus::details::IntegerRangesBase< T >::minusOne ( Data_t  value)
staticprotectednoexcept

Returns value decremented by 1.

Definition at line 394 of file IntegerRanges.h.

395  { return --value; }
temporary value
template<typename T >
std::size_t icarus::details::IntegerRangesBase< T >::nRanges ( ) const
noexcept

Returns the number of non-contiguous ranges in the set.

Definition at line 328 of file IntegerRanges.h.

329  { return fRanges.size(); }
std::vector< Range_t > fRanges
List of current ranges.
template<typename T >
constexpr auto icarus::details::IntegerRangesBase< T >::plusOne ( Data_t  value)
staticprotectednoexcept

Returns value incremented by 1.

Definition at line 387 of file IntegerRanges.h.

388  { return ++value; }
temporary value
template<typename T = int>
decltype(auto) icarus::details::IntegerRangesBase< T >::ranges ( ) const
noexcept

Returns an iterable object with all sorted ranges as elements.

template<typename T >
std::size_t icarus::details::IntegerRangesBase< T >::size ( ) const
noexcept

Returns the number of elements in the ranges (gaps excluded).

Definition at line 318 of file IntegerRanges.h.

318  {
319 
320  return std::accumulate(fRanges.begin(), fRanges.end(), 0U,
321  [](std::size_t s, Range_t const& r){ return s + r.size(); });
322 
323 } // icarus::details::IntegerRangesBase<>::size()
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
std::vector< Range_t > fRanges
List of current ranges.
esac echo uname r

Member Data Documentation

template<typename T = int>
std::vector<Range_t> icarus::details::IntegerRangesBase< T >::fRanges
private

List of current ranges.

Definition at line 158 of file IntegerRanges.h.


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