Public Types | Public Member Functions | Static Public Member Functions | List of all members
MinMax Class Reference

A min/max value pair with additional methods. In addition to conveniently storing values, it can be used for logic operations or to modify data. A few global functions and functors are also provided. More...

Inheritance diagram for MinMax:
Inheritance graph
[legend]

Public Types

typedef T value_type
 
typedef pTraits< T >::cmptType cmptType
 

Public Member Functions

 MinMax ()
 
 MinMax (const T &minVal, const T &maxVal)
 
 MinMax (const std::pair< T, T > &range)
 
 MinMax (const Pair< T > &range)
 
 MinMax (const Foam::zero)
 
 MinMax (const T &val)
 
 MinMax (const UList< T > &vals)
 
const Tmin () const noexcept
 
Tmin () noexcept
 
const Tmax () const noexcept
 
Tmax () noexcept
 
T centre () const
 
T span () const
 
scalar mag () const
 
bool empty () const
 
bool valid () const
 
void clear ()
 
bool intersect (const MinMax< T > &b)
 
bool overlaps (const MinMax< T > &b) const
 
int compare (const T &val) const
 
bool contains (const T &val) const
 
const Tclip (const T &val) const
 
bool inplaceClip (T &val) const
 
MinMax< T > & add (const MinMax &other)
 
MinMax< T > & add (const T &val)
 
MinMax< T > & add (const UList< T > &vals)
 
bool operator() (const T &val) const
 
MinMax< T > & operator+= (const MinMax< T > &b)
 
MinMax< T > & operator+= (const T &val)
 
MinMax< T > & operator+= (const UList< T > &vals)
 
MinMax< T > & operator*= (const scalar &s)
 
MinMax< T > & operator/= (const scalar &s)
 

Static Public Member Functions

static MinMax< Tge (const T &minVal)
 
static MinMax< Tle (const T &maxVal)
 
static MinMax< Tzero_one ()
 

Detailed Description

A min/max value pair with additional methods. In addition to conveniently storing values, it can be used for logic operations or to modify data. A few global functions and functors are also provided.

Examples of use.

Determine min/max limits from a List of values:

List<scalar> values = ...;

// on construction
MinMax<scalar> range(values);

range.clear();

range += val;

// global minMax() function
Info<< minMax(values) << nl;

General comparison operations

scalar val;
if (val < range) ... value is below range min
if (range.contains(val)) ... value within range
if (range.compare(val) > 0) ... value is above range max
if (range(val)) ... value within range - as predicate

Since the range has a predicate form, it can be used as a filter method. For example,

Info<< "values in range: " << subsetList(values, range) << nl;

boolList mask = ListOps::create<bool>(values, range);
Info<< "values values in range " << mask << nl;

One particular advantage offered by MinMax is to clip or limit values to a particular range. For example,

scalarMinMax range(lower, upper);

scalar val;
val = range.clip(val)    .. return clip values

// vs.
val = min(max(value, lower, upper))

Or when working on lists, the values can be limited in a single pass of the data without intermediate memory allocation.

scalarField values = ...;

for (scalar& val : values)
{
    range.inplaceClip(val);
}

// vs.
values = min(max(values, lower, upper))

Definition at line 72 of file HashSet.H.

Member Typedef Documentation

◆ value_type

typedef T value_type

Definition at line 128 of file MinMax.H.

◆ cmptType

Definition at line 131 of file MinMax.H.

Constructor & Destructor Documentation

◆ MinMax() [1/7]

MinMax ( )
inline

Definition at line 47 of file MinMaxI.H.

◆ MinMax() [2/7]

MinMax ( const T minVal,
const T maxVal 
)
inline

Definition at line 54 of file MinMaxI.H.

◆ MinMax() [3/7]

MinMax ( const std::pair< T, T > &  range)
inline

Definition at line 61 of file MinMaxI.H.

◆ MinMax() [4/7]

MinMax ( const Pair< T > &  range)
inline

Definition at line 68 of file MinMaxI.H.

◆ MinMax() [5/7]

MinMax ( const Foam::zero  )
inlineexplicit

Definition at line 75 of file MinMaxI.H.

◆ MinMax() [6/7]

MinMax ( const T val)
inlineexplicit

Definition at line 82 of file MinMaxI.H.

◆ MinMax() [7/7]

MinMax ( const UList< T > &  vals)
inlineexplicit

Definition at line 89 of file MinMaxI.H.

Member Function Documentation

◆ ge()

Foam::MinMax< T > ge ( const T minVal)
inlinestatic

◆ le()

Foam::MinMax< T > le ( const T maxVal)
inlinestatic

Definition at line 31 of file MinMaxI.H.

◆ zero_one()

Foam::MinMax< T > zero_one ( )
inlinestatic

Definition at line 38 of file MinMaxI.H.

Referenced by lumpedPointMovement::readDict().

Here is the caller graph for this function:

◆ min() [1/2]

const T& min ( ) const
inlinenoexcept

◆ min() [2/2]

T& min ( )
inlinenoexcept

◆ max() [1/2]

const T& max ( ) const
inlinenoexcept

Referenced by MinMax< scalar >::add(), and MinMax< scalar >::overlaps().

Here is the caller graph for this function:

◆ max() [2/2]

T& max ( )
inlinenoexcept

◆ centre()

T centre ( ) const
inline

Definition at line 128 of file MinMaxI.H.

◆ span()

T span ( ) const
inline

Definition at line 136 of file MinMaxI.H.

◆ mag()

Foam::scalar mag ( ) const
inline

Definition at line 143 of file MinMaxI.H.

◆ empty()

bool empty ( ) const
inline

Definition at line 150 of file MinMaxI.H.

◆ valid()

bool valid ( ) const
inline

Definition at line 157 of file MinMaxI.H.

◆ clear()

void clear ( )
inline

Definition at line 164 of file MinMaxI.H.

◆ intersect()

bool intersect ( const MinMax< T > &  b)
inline

Definition at line 172 of file MinMaxI.H.

◆ overlaps()

bool overlaps ( const MinMax< T > &  b) const
inline

Definition at line 182 of file MinMaxI.H.

◆ compare()

int compare ( const T val) const
inline

Definition at line 190 of file MinMaxI.H.

◆ contains()

bool contains ( const T val) const
inline

Definition at line 209 of file MinMaxI.H.

◆ clip()

const T & clip ( const T val) const
inline

Definition at line 216 of file MinMaxI.H.

◆ inplaceClip()

bool inplaceClip ( T val) const
inline

Definition at line 235 of file MinMaxI.H.

◆ add() [1/3]

Foam::MinMax< T > & add ( const MinMax other)
inline

Definition at line 256 of file MinMaxI.H.

Referenced by PDRblock::location::edgeLimits(), Foam::minMax(), Foam::minMaxMag(), minMaxOp< T >::operator()(), and Foam::operator+().

Here is the caller graph for this function:

◆ add() [2/3]

Foam::MinMax< T > & add ( const T val)
inline

Definition at line 265 of file MinMaxI.H.

◆ add() [3/3]

Foam::MinMax< T > & add ( const UList< T > &  vals)
inline

Definition at line 274 of file MinMaxI.H.

◆ operator()()

bool operator() ( const T val) const
inline

Definition at line 287 of file MinMaxI.H.

◆ operator+=() [1/3]

Foam::MinMax< T > & operator+= ( const MinMax< T > &  b)
inline

Definition at line 325 of file MinMaxI.H.

◆ operator+=() [2/3]

Foam::MinMax< T > & operator+= ( const T val)
inline

Definition at line 332 of file MinMaxI.H.

◆ operator+=() [3/3]

Foam::MinMax< T > & operator+= ( const UList< T > &  vals)
inline

Definition at line 339 of file MinMaxI.H.

◆ operator*=()

Foam::MinMax< T > & operator*= ( const scalar &  s)
inline

Definition at line 346 of file MinMaxI.H.

◆ operator/=()

Foam::MinMax< T > & operator/= ( const scalar &  s)
inline

Definition at line 355 of file MinMaxI.H.


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