JeVois  1.5
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
jevois::StepRange< T > Class Template Reference

#include <jevois/Types/StepRange.H>

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

A generic range class with a step.

The StepRange class is used to represent a range from [min .. (step) .. max]

Valid values are min, min+step, min+2*step, min+3*step, ... max. Note that max is a valid value even if it is not equal to min+N*step for some integer N. Note that T must be a numeric type (can be cast to double). Throws if step is not a positive or zero number.

Because StepRange is typically only used for limited specific purposes (e.g., defining paremeters for controls in video4linux framegrabbers), the interface provided is minimal (much more limited than that of jevois::Range).

Definition at line 69 of file StepRange.H.

Public Member Functions

 StepRange ()
 Default constructor, range is [0 .. (0) .. 0]. More...
 
 StepRange (T const mini, T const stepi, T const maxi)
 Constructor. More...
 
 StepRange (StepRange< T > const &other)=default
 Copy constructor. More...
 
 StepRange (StepRange< T > &&other)=default
 Move constructor. More...
 
template<typename U >
 StepRange (StepRange< U > const &other)
 Copy-conversion constructor, uses jevois::clamped_convert<T,U> internally. More...
 
StepRange< T > & operator= (StepRange< T > const &other)=default
 Assignment. More...
 
StepRange< T > & operator= (StepRange< T > &&other)=default
 Move assignment. More...
 
T const & min () const
 Return the minimum value. More...
 
T const & step () const
 Return the step value. More...
 
T const & max () const
 Return the maximum value. More...
 
bool empty () const
 Return whether min() == max() More...
 
bool isValueValid (T const val) const
 Return true if a value is valid (i.e., it is min, min+step, min+step*2, ... or max) More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
std::ostream & operator<< (std::ostream &out, StepRange< T > const &r)
 Stream out as "min...(step)...max". More...
 
template<typename T >
std::istream & operator>> (std::istream &in, StepRange< T > &r)
 Stream in as "min...(step)...max". More...
 
template<class T >
void paramValToString (StepRange< T > const &val, std::string &result)
 Machine-readable output to a string, for use in jevois::Parameter: outputs min...step...max. More...
 
template<class T >
void paramStringToVal (std::string const &valstring, StepRange< T > &result)
 Machine-readable input from a string, for use in jevois::Parameter: reads min...step...max. More...
 
template<typename T >
bool operator== (StepRange< T > const &range1, StepRange< T > const &range2)
 Equality test: StepRange<T> == StepRange<T> More...
 
template<typename T >
bool operator!= (StepRange< T > const &range1, StepRange< T > const &range2)
 Inequality test: StepRange<T> != StepRange<T> More...
 

Constructor & Destructor Documentation

◆ StepRange() [1/5]

template<typename T >
jevois::StepRange< T >::StepRange ( )
inlineexplicit

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

Definition at line 59 of file StepRangeImpl.H.

◆ StepRange() [2/5]

template<typename T >
jevois::StepRange< T >::StepRange ( T const  mini,
T const  stepi,
T const  maxi 
)
inlineexplicit

Constructor.

Definition at line 65 of file StepRangeImpl.H.

◆ StepRange() [3/5]

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

Copy constructor.

◆ StepRange() [4/5]

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

Move constructor.

◆ StepRange() [5/5]

template<typename T >
template<typename U >
jevois::StepRange< T >::StepRange ( jevois::StepRange< 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::StepRange<float> const & rng) { ... }
jevois::StepRange<int> r1(0, 5, 100);
jevois::StepRange<float> r2(r1); // ok, explicit constructor call
myFunc(r2); // ok, no conversion necessary
//myFunc(r1) // NO: passing StepRange<int> to function that takes a StepRange<float> arg fails to compile
myFunc(jevois::StepRange<float>(r1)); // ok, nice and explicit; and you can think about whether r1 should
// have been a StepRange<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 74 of file StepRangeImpl.H.

Member Function Documentation

◆ empty()

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

Return whether min() == max()

Definition at line 97 of file StepRangeImpl.H.

◆ isValueValid()

template<typename T >
bool jevois::StepRange< T >::isValueValid ( T const  val) const
inline

Return true if a value is valid (i.e., it is min, min+step, min+step*2, ... or max)

Definition at line 103 of file StepRangeImpl.H.

References jevois::StepRange< T >::max(), jevois::StepRange< T >::min(), jevois::paramStringToVal(), jevois::paramValToString(), jevois::split(), and jevois::StepRange< T >::step().

◆ max()

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

Return the maximum value.

Definition at line 92 of file StepRangeImpl.H.

Referenced by jevois::StepRange< T >::isValueValid().

◆ min()

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

Return the minimum value.

Definition at line 82 of file StepRangeImpl.H.

Referenced by jevois::StepRange< T >::isValueValid().

◆ operator=() [1/2]

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

Assignment.

◆ operator=() [2/2]

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

Move assignment.

◆ step()

template<typename T >
T const & jevois::StepRange< T >::step ( ) const
inline

Return the step value.

Definition at line 87 of file StepRangeImpl.H.

Referenced by jevois::StepRange< T >::isValueValid().

Friends And Related Function Documentation

◆ operator!=()

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

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

◆ operator<<()

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

Stream out as "min...(step)...max".

◆ operator==()

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

Equality test: StepRange<T> == StepRange<T>

◆ operator>>()

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

Stream in as "min...(step)...max".

◆ paramStringToVal()

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

Machine-readable input from a string, for use in jevois::Parameter: reads min...step...max.

◆ paramValToString()

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

Machine-readable output to a string, for use in jevois::Parameter: outputs min...step...max.


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