labelRange Class Reference

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

Inheritance diagram for labelRange:
Collaboration diagram for labelRange:

Public Member Functions

constexpr labelRange () noexcept
 Default construct an empty range (0,0) More...
 
constexpr labelRange (const label len) noexcept
 Construct a range with specified length, starting at zero (0,len) More...
 
 labelRange (const label beg, const label len) noexcept
 Construct a range from start/length, no checks. More...
 
 labelRange (const label beg, const label len, const bool adjustStart) noexcept
 Construct a range from start/size, enforces non-negative size. More...
 
 labelRange (const MinMax< label > &range) noexcept
 Construct from a min/max range (both inclusive), enforces non-negative size. More...
 
 labelRange (const Pair< label > &start_end) noexcept
 Construct from start (inclusive) and end (exclusive) values, enforces non-negative size. More...
 
 labelRange (Istream &is)
 Construct from Istream. More...
 
void adjust () noexcept
 Adjust the start to avoid negative indices. More...
 
void reset (const label beg, const label end, const bool adjustStart) noexcept
 Reset start and length, enforces non-negative size. More...
 
List< label > labels () const
 Return list of labels corresponding to the range. 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...
 
bool valid () const noexcept
 Deprecated(2020-09) True if range has size greater than zero. More...
 
- Public Member Functions inherited from IntRange< label >
constexpr IntRange () noexcept
 Default construct an empty range (0,0) More...
 
constexpr IntRange (const label len) noexcept
 Construct a range with specified length, starting at zero (0,len) More...
 
constexpr IntRange (const label beg, const label len) noexcept
 Construct a range from start/length, no checks. More...
 
bool empty () const noexcept
 True if range is empty (zero-sized) More...
 
bool good () const noexcept
 True if range has size greater than zero. More...
 
label size () const noexcept
 The size of the range. More...
 
label & size () noexcept
 Non-const access to size of the range. More...
 
label start () const noexcept
 The (inclusive) lower value of the range. More...
 
label & start () noexcept
 Non-const access to start of the range. More...
 
label min () const noexcept
 The (inclusive) lower value of the range, same as start(), begin_value() More...
 
label max () const noexcept
 The (inclusive) upper value of the range, same as rbegin_value(). Ill-defined for an empty range. More...
 
void reset () noexcept
 Reset to zero start and zero size. More...
 
void reset (const label beg, const label len) noexcept
 Reset start and length, no checks. More...
 
void clear () noexcept
 Same as reset() - reset to zero start and zero size. More...
 
void setStart (const label i) noexcept
 Set the start position, no checks. More...
 
void setSize (const label n) noexcept
 Change the size, no checks. Identical to resize() More...
 
void resize (const label n) noexcept
 Change the size, no checks. Identical to setSize() More...
 
void clampSize () noexcept
 Enforce non-negative size. More...
 
bool contains (const label value) const noexcept
 True if the (global) value is within the range. More...
 
bool found (const label val) const noexcept
 True if the (global) value is within the range. More...
 
const_iterator at (const label i) const
 Return const_iterator to a position within the range, with bounds checking. More...
 
constexpr label operator[] (const label i) const noexcept
 Offset dereference, without bounds checking. More...
 
bool operator() (const label i) const noexcept
 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...
 
 operator bool () const noexcept
 True if range has size greater than zero. Same as good() More...
 
label begin_value () const noexcept
 The value at the beginning of the range - same as min(), start() More...
 
label end_value () const noexcept
 The value 1 beyond the end of the range. More...
 
label rbegin_value () const noexcept
 The max value of the range. More...
 
label rend_value () const noexcept
 The value 1 before the begin of range. More...
 
const_iterator begin () const noexcept
 A const_iterator set to the beginning of the range. More...
 
const_iterator cbegin () const noexcept
 A const_iterator set to the beginning of the range. More...
 
const_iterator cend () const noexcept
 A const_iterator set to 1 beyond the end of the range. More...
 
const_iterator end () const noexcept
 A const_iterator set to 1 beyond the end of the range. More...
 
const_reverse_iterator rbegin () const noexcept
 A const_reverse_iterator set to 1 before the end of range. More...
 
const_reverse_iterator crbegin () const noexcept
 A const_reverse_iterator set to 1 before the end of range. More...
 
const_reverse_iterator rend () const noexcept
 A const_reverse_iterator set to 1 before the begin of range. More...
 
const_reverse_iterator crend () const noexcept
 A const_reverse_iterator set to 1 before the begin of range. More...
 

Static Public Attributes

static int debug
 Debugging. More...
 

Additional Inherited Members

- Public Types inherited from IntRange< label >
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...
 

Detailed Description

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

Source files

Definition at line 52 of file labelRange.H.

Constructor & Destructor Documentation

◆ labelRange() [1/7]

constexpr labelRange ( )
inlinenoexcept

Default construct an empty range (0,0)

Definition at line 24 of file labelRangeI.H.

◆ labelRange() [2/7]

constexpr labelRange ( const label  len)
inlineexplicitnoexcept

Construct a range with specified length, starting at zero (0,len)

Definition at line 30 of file labelRangeI.H.

◆ labelRange() [3/7]

labelRange ( const label  beg,
const label  len 
)
inlinenoexcept

Construct a range from start/length, no checks.

Definition at line 37 of file labelRangeI.H.

◆ labelRange() [4/7]

labelRange ( const label  beg,
const label  len,
const bool  adjustStart 
)
inlinenoexcept

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

Optionally adjust the start to avoid any negative indices.

See also
adjust()

Definition at line 49 of file labelRangeI.H.

◆ labelRange() [5/7]

labelRange ( const MinMax< label > &  range)
explicitnoexcept

Construct from a min/max range (both inclusive), enforces non-negative size.

Passing an invalid range results in an empty labelRange

Definition at line 38 of file labelRange.C.

References range.

◆ labelRange() [6/7]

labelRange ( const Pair< label > &  start_end)
explicitnoexcept

Construct from start (inclusive) and end (exclusive) values, enforces non-negative size.

Passing an invalid range results in an empty labelRange

Definition at line 51 of file labelRange.C.

◆ labelRange() [7/7]

labelRange ( Istream is)
explicit

Construct from Istream.

Definition at line 64 of file labelRange.C.

Member Function Documentation

◆ 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 88 of file labelRange.C.

Referenced by Foam::BitOps::set(), and bitSet::set().

Here is the caller graph for this function:

◆ reset()

void reset ( const label  beg,
const label  end,
const bool  adjustStart 
)
inlinenoexcept

Reset start and length, enforces non-negative size.

Optionally adjust the start to avoid any negative indices.

Definition at line 71 of file labelRangeI.H.

Referenced by labelRanges::add(), meshSearch::boundaryTree(), and labelRanges::remove().

Here is the caller graph for this function:

◆ labels()

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

Return list of labels corresponding to the range.

Same as Foam::identity()

Definition at line 74 of file labelRange.C.

References UList< T >::begin(), UList< T >::end(), and List< T >::resize().

Here is the call graph for this function:

◆ 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 103 of file labelRange.C.

References IntRange< IntType >::max(), Foam::max(), IntRange< IntType >::min(), Foam::min(), and range.

Referenced by labelRanges::add().

Here is the call graph for this function:
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 126 of file labelRange.C.

References IntRange< IntType >::clampSize(), Foam::stringOps::lower(), IntRange< IntType >::max(), Foam::max(), IntRange< IntType >::min(), 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 151 of file labelRange.C.

References Foam::stringOps::lower(), IntRange< IntType >::max(), Foam::max(), IntRange< IntType >::min(), Foam::min(), 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 169 of file labelRange.C.

References Foam::stringOps::lower(), Foam::max(), Foam::min(), 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 189 of file labelRange.C.

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

Referenced by UList< Foam::vector >::validateRange().

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

◆ valid()

bool valid ( ) const
inlinenoexcept

Deprecated(2020-09) True if range has size greater than zero.

Deprecated:
(2020-09) - use bool operator - or good()

Definition at line 221 of file labelRange.H.

References IntRange< label >::good().

Here is the call graph for this function:

Member Data Documentation

◆ debug

int debug
static

Debugging.

Definition at line 76 of file labelRange.H.

Referenced by labelRanges::remove().


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