JeVois  1.0
JeVois Smart Embedded Machine Vision Toolkit
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

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

Related Functions

(Note that these are not member functions.)

template<typename T >
Range< T > merge (Range< T > const &r1, Range< T > const &r2)
 Merge two ranges. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &out, Range< T > const &r)
 Stream out as "[min ... max]". More...
 
template<typename T >
std::istream & operator>> (std::istream &in, Range< T > &r)
 Stream in as "[min ... max]". More...
 
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) More...
 
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) More...
 
template<typename T >
bool operator== (Range< T > const &range1, Range< T > const &range2)
 Equality test: Range<T> == Range<T> More...
 
template<typename T >
bool operator!= (Range< T > const &range1, Range< T > const &range2)
 Inequality test: Range<T> != Range<T> More...
 
template<typename T >
Range< T > operator+ (Range< T > const &range, T const &scalar)
 Add constant to both ends of a range: Range<T> + T. More...
 
template<typename T >
Range< T > operator+ (T const &scalar, Range< T > const &range)
 Add constant to both ends of a range: T + Range<T> More...
 
template<typename T >
Range< T > operator- (Range< T > const &range, T const &scalar)
 Subtract constant from both ends of a range: Range<T> - T. More...
 
template<typename T >
Range< T > operator- (T const &scalar, Range< T > const &range)
 Subtract constant from both ends of a range: T - Range<T> More...
 
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. More...
 
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> More...
 
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. More...
 
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> More...
 
template<typename T >
Range< T > & operator+= (Range< T > &range, T const &scalar)
 Add constant to both ends of a range: Range<T> += T. More...
 
template<typename T >
Range< T > & operator-= (Range< T > &range, T const &scalar)
 Subtract constant from both ends of a range: Range<T> -= T. More...
 
template<typename T >
Range< T > & operator*= (Range< T > &range, T const &scalar)
 Multiply both ends of a range by a factor: Range<T> *= T. More...
 
template<typename T >
Range< T > & operator/= (Range< T > &range, T const &scalar)
 Divide both ends of a range by a factor: Range<T> /= T. More...
 

Constructor & Destructor Documentation

template<class T >
jevois::Range< T >::Range ( )
inlineexplicit

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

Definition at line 59 of file RangeImpl.H.

template<class T >
jevois::Range< T >::Range ( T const  mini,
T const  maxi 
)
inlineexplicit

Constructor.

Definition at line 65 of file RangeImpl.H.

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

Copy constructor.

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

Move constructor.

template<class T >
template<class U >
jevois::Range< T >::Range ( jevois::Range< U > const &  other)
inlineexplicit

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)

Definition at line 73 of file RangeImpl.H.

Member Function Documentation

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

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

Definition at line 104 of file RangeImpl.H.

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

Return whether min() == max()

Definition at line 90 of file RangeImpl.H.

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

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

Definition at line 96 of file RangeImpl.H.

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

Return the maximum value.

Definition at line 85 of file RangeImpl.H.

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

Return the minimum value.

Definition at line 80 of file RangeImpl.H.

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

Assignment.

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

Move assignment.

Friends And Related Function Documentation

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

Merge two ranges.

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

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

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.

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>

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.

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.

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>

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

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

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.

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>

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

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

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.

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>

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.

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

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

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

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

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

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

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)

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 files: