JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
jevois::Range< T > Class Template Reference

#include <jevois/Types/Range.H>

template<typename T>
class jevois::Range< T >

A generic range class.

The Range class is used to represent a range from [min .. max]

Note that the operators of Range do not use type promotions. This is to minimize template burden and also possible programmer confusion. For example, while in principle one could define Range<int> + float and return a Range<float>, here we do not define such an operator. The same result can be achieved by first converting the range and then adding the constant:

jevois::Range<int> r1(0, 100);
// NOT ALLOWED: jevois::Range<float> r2 = r1 + 1.23F;
jevois::Range<float> r2 = jevois::Range<float>(r1) + 1.23F; // OK, no hidden conversions, easy to read, explicit
A generic range class.
Definition Range.H:81

Operators on Range use range checking and clamping internally. Thus, be careful if using Range<byte>. For example:

jevois::Range<jevois::byte> r(jevois::byte(0), jevois::byte(250));
r += jevois::byte(100); // new range is 100-255

Definition at line 80 of file Range.H.

Public Member Functions

 Range ()
 Default constructor, range is [0 .. 0].
 
 Range (T const mini, T const maxi)
 Constructor.
 
 Range (Range< T > const &other)=default
 Copy constructor.
 
 Range (Range< T > &&other)=default
 Move constructor.
 
template<typename U >
 Range (Range< U > const &other)
 Copy-conversion constructor, uses jevois::clamped_convert<T,U> internally.
 
Range< T > & operator= (Range< T > const &other)=default
 Assignment.
 
Range< T > & operator= (Range< T > &&other)=default
 Move assignment.
 
T const & min () const
 Return the minimum value.
 
T const & max () const
 Return the maximum value.
 
bool empty () const
 Return whether min() == max()
 
void extend (T const val)
 Extend the range, if needed, so that it includes val.
 
bool contains (T const &val) const
 Return true if val is within [min ... max].
 

Related Symbols

(Note that these are not member symbols.)

template<typename T >
Range< T > merge (Range< T > const &r1, Range< T > const &r2)
 Merge two ranges.
 
template<typename T >
std::ostream & operator<< (std::ostream &out, Range< T > const &r)
 Stream out as "[min ... max]".
 
template<typename T >
std::istream & operator>> (std::istream &in, Range< T > &r)
 Stream in as "[min ... max]".
 
template<class T >
void paramValToString (Range< T > const &val, std::string &result)
 Machine-readable output to a string, for use in jevois::Parameter: outputs min...max (e.g., 0...100)
 
template<class T >
void paramStringToVal (std::string const &valstring, Range< T > &result)
 Machine-readable input from a string, for use in jevois::Parameter: reads min...max (e.g., 0...100)
 
template<typename T >
bool operator== (Range< T > const &range1, Range< T > const &range2)
 Equality test: Range<T> == Range<T>
 
template<typename T >
bool operator!= (Range< T > const &range1, Range< T > const &range2)
 Inequality test: Range<T> != Range<T>
 
template<typename T >
Range< T > operator+ (Range< T > const &range, T const &scalar)
 Add constant to both ends of a range: Range<T> + T.
 
template<typename T >
Range< T > operator+ (T const &scalar, Range< T > const &range)
 Add constant to both ends of a range: T + Range<T>
 
template<typename T >
Range< T > operator- (Range< T > const &range, T const &scalar)
 Subtract constant from both ends of a range: Range<T> - T.
 
template<typename T >
Range< T > operator- (T const &scalar, Range< T > const &range)
 Subtract constant from both ends of a range: T - Range<T>
 
template<typename T >
Range< T > operator/ (Range< T > const &range, T const &scalar)
 Divide both ends of a range by a factor: Range<T> / T.
 
template<typename T >
Range< T > operator/ (T const &scalar, Range< T > const &range)
 Divide a factor by both ends of a range: T / Range<T>
 
template<typename T >
Range< T > operator* (Range< T > const &range, T const &scalar)
 Multiply both ends of a range by a factor: Range<T> * T.
 
template<typename T >
Range< T > operator* (T const &scalar, Range< T > const &range)
 Multiply a factor by both ends of a range: T * Range<T>
 
template<typename T >
Range< T > & operator+= (Range< T > &range, T const &scalar)
 Add constant to both ends of a range: Range<T> += T.
 
template<typename T >
Range< T > & operator-= (Range< T > &range, T const &scalar)
 Subtract constant from both ends of a range: Range<T> -= T.
 
template<typename T >
Range< T > & operator*= (Range< T > &range, T const &scalar)
 Multiply both ends of a range by a factor: Range<T> *= T.
 
template<typename T >
Range< T > & operator/= (Range< T > &range, T const &scalar)
 Divide both ends of a range by a factor: Range<T> /= T.
 

Constructor & Destructor Documentation

◆ Range() [1/5]

template<typename T >
jevois::Range< T >::Range ( )
explicit

Default constructor, range is [0 .. 0].

◆ Range() [2/5]

template<typename T >
jevois::Range< T >::Range ( T const  mini,
T const  maxi 
)
explicit

Constructor.

◆ Range() [3/5]

template<typename T >
jevois::Range< T >::Range ( Range< T > const &  other)
default

Copy constructor.

◆ Range() [4/5]

template<typename T >
jevois::Range< T >::Range ( Range< T > &&  other)
default

Move constructor.

◆ Range() [5/5]

template<typename T >
template<typename U >
jevois::Range< T >::Range ( Range< U > const &  other)
explicit

Copy-conversion constructor, uses jevois::clamped_convert<T,U> internally.

Note that this constructor is explicit, i.e., you need to explicitly mention it. This is to avoid conversions to happen without a programmer being aware of it. For example:

void myFunc(jevois::Range<float> const & rng) { ... }
jevois::Range<int> r1(0, 100);
jevois::Range<float> r2(r1); // ok, explicit constructor call
myFunc(r2); // ok, no conversion necessary
//myFunc(r1) // NO: passing Range<int> to function that takes a Range<float> arg fails to compile
myFunc(jevois::Range<float>(r1)); // ok, nice and explicit; and you can think about whether r1 should
// have been a Range<float> in the first place so you don't waste CPU
// doing this conversion (as opposed to just not being aware of the wasting)

Member Function Documentation

◆ contains()

template<typename T >
bool jevois::Range< T >::contains ( T const &  val) const

Return true if val is within [min ... max].

◆ empty()

template<typename T >
bool jevois::Range< T >::empty ( ) const

Return whether min() == max()

◆ extend()

template<typename T >
void jevois::Range< T >::extend ( T const  val)

Extend the range, if needed, so that it includes val.

◆ max()

template<typename T >
T const & jevois::Range< T >::max ( ) const

Return the maximum value.

Referenced by jevois::GUIhelper::drawParameters().

◆ min()

template<typename T >
T const & jevois::Range< T >::min ( ) const

Return the minimum value.

Referenced by jevois::GUIhelper::drawParameters().

◆ operator=() [1/2]

template<typename T >
Range< T > & jevois::Range< T >::operator= ( Range< T > &&  other)
default

Move assignment.

◆ operator=() [2/2]

template<typename T >
Range< T > & jevois::Range< T >::operator= ( Range< T > const &  other)
default

Assignment.

Friends And Related Symbol Documentation

◆ merge()

template<typename T >
Range< T > merge ( Range< T > const &  r1,
Range< T > const &  r2 
)
related

Merge two ranges.

◆ operator!=()

template<typename T >
bool operator!= ( Range< T > const &  range1,
Range< T > const &  range2 
)
related

Inequality test: Range<T> != Range<T>

◆ operator*() [1/2]

template<typename T >
Range< T > operator* ( Range< T > const &  range,
T const &  scalar 
)
related

Multiply both ends of a range by a factor: Range<T> * T.

◆ operator*() [2/2]

template<typename T >
Range< T > operator* ( T const &  scalar,
Range< T > const &  range 
)
related

Multiply a factor by both ends of a range: T * Range<T>

◆ operator*=()

template<typename T >
Range< T > & operator*= ( Range< T > &  range,
T const &  scalar 
)
related

Multiply both ends of a range by a factor: Range<T> *= T.

◆ operator+() [1/2]

template<typename T >
Range< T > operator+ ( Range< T > const &  range,
T const &  scalar 
)
related

Add constant to both ends of a range: Range<T> + T.

◆ operator+() [2/2]

template<typename T >
Range< T > operator+ ( T const &  scalar,
Range< T > const &  range 
)
related

Add constant to both ends of a range: T + Range<T>

◆ operator+=()

template<typename T >
Range< T > & operator+= ( Range< T > &  range,
T const &  scalar 
)
related

Add constant to both ends of a range: Range<T> += T.

◆ operator-() [1/2]

template<typename T >
Range< T > operator- ( Range< T > const &  range,
T const &  scalar 
)
related

Subtract constant from both ends of a range: Range<T> - T.

◆ operator-() [2/2]

template<typename T >
Range< T > operator- ( T const &  scalar,
Range< T > const &  range 
)
related

Subtract constant from both ends of a range: T - Range<T>

◆ operator-=()

template<typename T >
Range< T > & operator-= ( Range< T > &  range,
T const &  scalar 
)
related

Subtract constant from both ends of a range: Range<T> -= T.

◆ operator/() [1/2]

template<typename T >
Range< T > operator/ ( Range< T > const &  range,
T const &  scalar 
)
related

Divide both ends of a range by a factor: Range<T> / T.

◆ operator/() [2/2]

template<typename T >
Range< T > operator/ ( T const &  scalar,
Range< T > const &  range 
)
related

Divide a factor by both ends of a range: T / Range<T>

◆ operator/=()

template<typename T >
Range< T > & operator/= ( Range< T > &  range,
T const &  scalar 
)
related

Divide both ends of a range by a factor: Range<T> /= T.

◆ operator<<()

template<typename T >
std::ostream & operator<< ( std::ostream &  out,
Range< T > const &  r 
)
related

Stream out as "[min ... max]".

◆ operator==()

template<typename T >
bool operator== ( Range< T > const &  range1,
Range< T > const &  range2 
)
related

Equality test: Range<T> == Range<T>

◆ operator>>()

template<typename T >
std::istream & operator>> ( std::istream &  in,
Range< T > &  r 
)
related

Stream in as "[min ... max]".

◆ paramStringToVal()

template<class T >
void paramStringToVal ( std::string const &  valstring,
Range< T > &  result 
)
related

Machine-readable input from a string, for use in jevois::Parameter: reads min...max (e.g., 0...100)

◆ paramValToString()

template<class T >
void paramValToString ( Range< T > const &  val,
std::string &  result 
)
related

Machine-readable output to a string, for use in jevois::Parameter: outputs min...max (e.g., 0...100)


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