labelRange Class Reference

A range or interval of labels defined by a start and a size. More...

Inheritance diagram for labelRange:
[legend]
Collaboration diagram for labelRange:
[legend]

Classes

class  const_iterator
 Forward iterator with const access. More...
 

Public Types

typedef label value_type
 Type of values the range contains. More...
 
typedef label size_type
 The type that can represent the size of the range. More...
 

Public Member Functions

constexpr labelRange () noexcept
 An empty range with zero for start/size. More...
 
 labelRange (const label start, const label size) noexcept
 Construct a range from start/size, enforcing non-negative size. More...
 
 labelRange (const label start, const label size, const bool adjustStart) noexcept
 Construct a range from start/size, enforcing non-negative size. More...
 
 labelRange (const MinMax< label > &range) noexcept
 
 labelRange (Istream &is)
 Construct from Istream. More...
 
void setStart (const label i) noexcept
 Change the start position. More...
 
void resize (const label n) noexcept
 Change the size, enforcing non-negative size. More...
 
void setSize (const label n) noexcept
 Change the size - alias for resize() More...
 
void clear () noexcept
 Reset to zero start and zero size. More...
 
bool empty () const noexcept
 Is the range empty? More...
 
bool valid () const noexcept
 Is the range non-empty? More...
 
label start () const noexcept
 The (inclusive) lower value of the range. More...
 
label size () const noexcept
 The effective size of the range. More...
 
label before () const noexcept
 The value before the start of the range. More...
 
label first () const noexcept
 The (inclusive) lower value of the range - same as start() More...
 
label min () const noexcept
 The (inclusive) lower value of the range - same as start(), first() More...
 
label last () const noexcept
 The (inclusive) upper value of the range - same as max() More...
 
label max () const noexcept
 The (inclusive) upper value of the range - same as last() More...
 
label after () const noexcept
 The value after the last element in the range. More...
 
void adjust () noexcept
 Adjust the start to avoid negative indices. More...
 
bool reset (const label start, const label size) noexcept
 Reset start and size, enforcing non-negative size. More...
 
bool reset (const label start, const label size, const bool adjustStart) noexcept
 Reset start and size, enforcing non-negative size. More...
 
bool found (const label value) const noexcept
 Return true if the (global) value is located within the range. More...
 
List< labellabels () const
 Return the range as a list of labels. More...
 
bool overlaps (const labelRange &range, bool touches=false) const
 Return true if the ranges overlap. More...
 
labelRange join (const labelRange &range) const
 Return a joined range, squashing any gaps in between. More...
 
labelRange subset (const labelRange &range) const
 Calculate the intersection of the range with another. More...
 
labelRange subset (const label start, const label size) const
 Calculate the intersection with the given start/size range. More...
 
labelRange subset0 (const label size) const
 Calculate the intersection with the given 0/size range. More...
 
label operator[] (const label i) const noexcept
 Return element in the range, without bounds checking. More...
 
bool operator() (const label value) const noexcept
 Return true if the global value is located within the range. More...
 
label operator++ () noexcept
 Increase the size by 1. More...
 
label operator++ (int) noexcept
 
label operator+= (const label n) noexcept
 Increase the size by n. More...
 
label operator-- () noexcept
 Decrease the size by 1, but never below 0. More...
 
label operator-- (int) noexcept
 
label operator-= (const label n) noexcept
 Decrease the size by n, but never below 0. More...
 
const_iterator begin () const
 A const_iterator set to the beginning of the range. More...
 
const_iterator cbegin () const
 A const_iterator set to the beginning of the range. More...
 
const const_iterator cend () const
 A const_iterator set to 1 beyond the end of the range. More...
 
const const_iterator end () const
 A const_iterator set to 1 beyond the end of the range. More...
 
const_iterator at (const label i) const
 

Static Public Member Functions

static labelRange identity (const label len, const label start=0) noexcept
 

Static Public Attributes

static int debug
 Debugging. More...
 
static const labelRange null
 An empty range with start=0, size=0. More...
 

Detailed Description

A range or interval of labels defined by a start and a size.

Source files

Definition at line 58 of file labelRange.H.

Member Typedef Documentation

◆ value_type

typedef label value_type

Type of values the range contains.

Definition at line 74 of file labelRange.H.

◆ size_type

typedef label size_type

The type that can represent the size of the range.

Definition at line 77 of file labelRange.H.

Constructor & Destructor Documentation

◆ labelRange() [1/5]

constexpr labelRange ( )
inlineconstexprnoexcept

An empty range with zero for start/size.

Definition at line 31 of file labelRangeI.H.

◆ labelRange() [2/5]

labelRange ( const label  start,
const label  size 
)
inlinenoexcept

Construct a range from start/size, enforcing non-negative size.

Definition at line 39 of file labelRangeI.H.

◆ labelRange() [3/5]

labelRange ( const label  start,
const label  size,
const bool  adjustStart 
)
inlinenoexcept

Construct a range from start/size, enforcing non-negative size.

Optionally adjust the start to avoid any negative indices.

Definition at line 52 of file labelRangeI.H.

◆ labelRange() [4/5]

labelRange ( const MinMax< label > &  range)
explicitnoexcept

Construct from a min/max range, enforcing non-negative size. Does not adjust the start.

Passing an invalid min/max range results in an empty labelRange

Definition at line 47 of file labelRange.C.

References range.

◆ labelRange() [5/5]

labelRange ( Istream is)
explicit

Construct from Istream.

Definition at line 60 of file labelRange.C.

Member Function Documentation

◆ identity()

Foam::labelRange identity ( const label  len,
const label  start = 0 
)
inlinestaticnoexcept

An identity range corresponding to (map[i] == i), or with an optional start index, so that (map[i] == i+start)

The parameter order as per the Foam::identity() function.

Definition at line 179 of file labelRangeI.H.

References Foam::start.

Referenced by ensightCells::classify().

Here is the caller graph for this function:

◆ setStart()

void setStart ( const label  i)
inlinenoexcept

Change the start position.

Definition at line 188 of file labelRangeI.H.

Referenced by foamPvCore::arrayRange::reset().

Here is the caller graph for this function:

◆ resize()

void resize ( const label  n)
inlinenoexcept

Change the size, enforcing non-negative size.

Definition at line 194 of file labelRangeI.H.

References n.

◆ setSize()

void setSize ( const label  n)
inlinenoexcept

Change the size - alias for resize()

Definition at line 201 of file labelRangeI.H.

References n.

Referenced by foamPvCore::arrayRange::operator+=().

Here is the caller graph for this function:

◆ clear()

void clear ( )
inlinenoexcept

Reset to zero start and zero size.

Definition at line 208 of file labelRangeI.H.

Referenced by labelRanges::add(), and foamPvCore::arrayRange::reset().

Here is the caller graph for this function:

◆ empty()

bool empty ( ) const
inlinenoexcept

Is the range empty?

Definition at line 214 of file labelRangeI.H.

Referenced by bitSet::set(), and bitSet::unset().

Here is the caller graph for this function:

◆ valid()

bool valid ( ) const
inlinenoexcept

Is the range non-empty?

Definition at line 220 of file labelRangeI.H.

◆ start()

Foam::label start ( ) const
inlinenoexcept

The (inclusive) lower value of the range.

Definition at line 232 of file labelRangeI.H.

Referenced by UList< Foam::wordRe >::operator[](), bitSet::set(), bitSet::unset(), and UList< Foam::wordRe >::validateRange().

Here is the caller graph for this function:

◆ size()

Foam::label size ( ) const
inlinenoexcept

The effective size of the range.

Definition at line 226 of file labelRangeI.H.

Referenced by foamPvCore::arrayRange::intersection(), foamPvCore::arrayRange::operator+=(), UList< Foam::wordRe >::operator[](), and UList< Foam::wordRe >::validateRange().

Here is the caller graph for this function:

◆ before()

Foam::label before ( ) const
inlinenoexcept

The value before the start of the range.

Definition at line 238 of file labelRangeI.H.

◆ first()

Foam::label first ( ) const
inlinenoexcept

The (inclusive) lower value of the range - same as start()

Definition at line 244 of file labelRangeI.H.

Referenced by labelRanges::remove(), bitSet::set(), and bitSet::unset().

Here is the caller graph for this function:

◆ min()

Foam::label min ( ) const
inlinenoexcept

The (inclusive) lower value of the range - same as start(), first()

Definition at line 250 of file labelRangeI.H.

◆ last()

Foam::label last ( ) const
inlinenoexcept

The (inclusive) upper value of the range - same as max()

Definition at line 256 of file labelRangeI.H.

Referenced by labelRanges::remove().

Here is the caller graph for this function:

◆ max()

Foam::label max ( ) const
inlinenoexcept

The (inclusive) upper value of the range - same as last()

Definition at line 262 of file labelRangeI.H.

◆ after()

Foam::label after ( ) const
inlinenoexcept

The value after the last element in the range.

This is identical to the value of cend()

Definition at line 268 of file labelRangeI.H.

Referenced by bitSet::set(), and bitSet::unset().

Here is the caller graph for this function:

◆ adjust()

void adjust ( )
noexcept

Adjust the start to avoid negative indices.

The size is decreased accordingly, but will never become negative. Eg, adjusting (-10, 15) becomes (0,5). adjusting (-20, 15) becomes (0,0)

Definition at line 85 of file labelRange.C.

Referenced by bitSet::set().

Here is the caller graph for this function:

◆ reset() [1/2]

bool reset ( const label  start,
const label  size 
)
inlinenoexcept

Reset start and size, enforcing non-negative size.

Returns
true if the updated range is valid (non-empty).

Definition at line 275 of file labelRangeI.H.

References Foam::start.

◆ reset() [2/2]

bool reset ( const label  start,
const label  size,
const bool  adjustStart 
)
inlinenoexcept

Reset start and size, enforcing non-negative size.

Optionally adjust the start to avoid any negative indices.

Returns
true if the updated range is valid (non-empty).

Definition at line 290 of file labelRangeI.H.

References Foam::start.

◆ found()

bool found ( const label  value) const
inlinenoexcept

Return true if the (global) value is located within the range.

Definition at line 312 of file labelRangeI.H.

◆ labels()

Foam::List< Foam::label > labels ( ) const

Return the range as a list of labels.

Definition at line 71 of file labelRange.C.

◆ overlaps()

bool overlaps ( const labelRange range,
bool  touches = false 
) const

Return true if the ranges overlap.

Optional test for ranges that also just touch each other

Definition at line 102 of file labelRange.C.

References range.

Referenced by labelRanges::add().

Here is the caller graph for this function:

◆ join()

Foam::labelRange join ( const labelRange range) const

Return a joined range, squashing any gaps in between.

A prior overlaps() check can be used to avoid squashing gaps.

Definition at line 125 of file labelRange.C.

References Foam::stringOps::lower(), Foam::max(), Foam::min(), range, and Foam::stringOps::upper().

Referenced by labelRanges::add().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subset() [1/2]

Foam::labelRange subset ( const labelRange range) const

Calculate the intersection of the range with another.

If there is no intersection, it returns an empty range with zero for start/size.

Definition at line 147 of file labelRange.C.

References Foam::stringOps::lower(), Foam::max(), Foam::min(), range, and Foam::stringOps::upper().

Here is the call graph for this function:

◆ subset() [2/2]

Foam::labelRange subset ( const label  start,
const label  size 
) const

Calculate the intersection with the given start/size range.

If there is no intersection, it returns an empty range with zero for start/size.

Definition at line 165 of file labelRange.C.

References Foam::stringOps::lower(), Foam::max(), Foam::min(), Foam::start, and Foam::stringOps::upper().

Here is the call graph for this function:

◆ subset0()

Foam::labelRange subset0 ( const label  size) const

Calculate the intersection with the given 0/size range.

If there is no intersection, it returns an empty range with zero for start/size.

Definition at line 185 of file labelRange.C.

References Foam::stringOps::lower(), Foam::max(), Foam::min(), Foam::start, and Foam::stringOps::upper().

Here is the call graph for this function:

◆ operator[]()

Foam::label operator[] ( const label  i) const
inlinenoexcept

Return element in the range, without bounds checking.

Definition at line 320 of file labelRangeI.H.

◆ operator()()

bool operator() ( const label  value) const
inlinenoexcept

Return true if the global value is located within the range.

Behaviour identical to found() - usable as a predicate

Definition at line 326 of file labelRangeI.H.

References found.

◆ operator++() [1/2]

Foam::label operator++ ( )
inlinenoexcept

Increase the size by 1.

Definition at line 332 of file labelRangeI.H.

◆ operator++() [2/2]

Foam::label operator++ ( int  )
inlinenoexcept

Definition at line 338 of file labelRangeI.H.

◆ operator+=()

Foam::label operator+= ( const label  n)
inlinenoexcept

Increase the size by n.

Definition at line 361 of file labelRangeI.H.

References n.

◆ operator--() [1/2]

Foam::label operator-- ( )
inlinenoexcept

Decrease the size by 1, but never below 0.

Definition at line 344 of file labelRangeI.H.

◆ operator--() [2/2]

Foam::label operator-- ( int  )
inlinenoexcept

Definition at line 352 of file labelRangeI.H.

◆ operator-=()

Foam::label operator-= ( const label  n)
inlinenoexcept

Decrease the size by n, but never below 0.

Definition at line 368 of file labelRangeI.H.

References n.

◆ begin()

Foam::labelRange::const_iterator begin ( ) const
inline

A const_iterator set to the beginning of the range.

The value returned is guaranteed to be the same as start()

Definition at line 145 of file labelRangeI.H.

◆ cbegin()

Foam::labelRange::const_iterator cbegin ( ) const
inline

A const_iterator set to the beginning of the range.

The value returned is guaranteed to be the same as start()

Definition at line 151 of file labelRangeI.H.

◆ cend()

const Foam::labelRange::const_iterator cend ( ) const
inline

A const_iterator set to 1 beyond the end of the range.

The value returned is the same as after()

Definition at line 163 of file labelRangeI.H.

◆ end()

const Foam::labelRange::const_iterator end ( ) const
inline

A const_iterator set to 1 beyond the end of the range.

The value returned is the same as after()

Definition at line 157 of file labelRangeI.H.

◆ at()

Foam::labelRange::const_iterator at ( const label  i) const
inline

Return const_iterator to a position within the range, with bounds checking.

Returns
iterator at the requested position, or end() for out of bounds

Definition at line 170 of file labelRangeI.H.

Member Data Documentation

◆ debug

int debug
static

Debugging.

Definition at line 80 of file labelRange.H.

Referenced by labelRanges::remove().

◆ null

const Foam::labelRange null
static

An empty range with start=0, size=0.

Definition at line 89 of file labelRange.H.


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