JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
StepRange.H
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18// This file has been modified / imported from the Neuromorphic Robotics Toolkit (NRT). Original copyright is:
19
20/* author Laurent Itti
21 // ////////////////////////////////////////////////////////////////////////
22 // The iLab Neuromorphic Robotics Toolkit (NRT) //
23 // Copyright 2010-2012 by the University of Southern California (USC) //
24 // and the iLab at USC. //
25 // //
26 // iLab - University of Southern California //
27 // Hedco Neurociences Building, Room HNB-10 //
28 // Los Angeles, Ca 90089-2520 - USA //
29 // //
30 // See http://ilab.usc.edu for information about this project. //
31 // ////////////////////////////////////////////////////////////////////////
32 // This file is part of The iLab Neuromorphic Robotics Toolkit. //
33 // //
34 // The iLab Neuromorphic Robotics Toolkit is free software: you can //
35 // redistribute it and/or modify it under the terms of the GNU General //
36 // Public License as published by the Free Software Foundation, either //
37 // version 3 of the License, or (at your option) any later version. //
38 // //
39 // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
40 // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
41 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
42 // PURPOSE. See the GNU General Public License for more details. //
43 // //
44 // You should have received a copy of the GNU General Public License //
45 // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
46 // <http://www.gnu.org/licenses/>. //
47 // ////////////////////////////////////////////////////////////////////////
48*/
49
50#pragma once
51
52#include <istream>
53#include <ostream>
54
55namespace jevois
56{
57 //! A generic range class with a step
58 /*! The StepRange class is used to represent a range from [min .. (step) .. max]
59
60 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
61 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
62 is not a positive or zero number.
63
64 Because StepRange is typically only used for limited specific purposes (e.g., defining paremeters for controls in
65 video4linux framegrabbers), the interface provided is minimal (much more limited than that of jevois::Range).
66
67 \ingroup types */
68 template <typename T>
70 {
71 public:
72 //! Default constructor, range is [0 .. (0) .. 0]
73 explicit StepRange();
74
75 //! Constructor
76 explicit StepRange(T const mini, T const stepi, T const maxi);
77
78 //! Copy constructor
79 StepRange(StepRange<T> const & other) = default;
80
81 //! Move constructor
82 StepRange(StepRange<T> && other) = default;
83
84 //! Copy-conversion constructor, uses jevois::clamped_convert<T,U> internally
85 /*! Note that this constructor is \e explicit, i.e., you need to explicitly mention it. This is to avoid
86 conversions to happen without a programmer being aware of it. For example:
87 @code
88 void myFunc(jevois::StepRange<float> const & rng) { ... }
89 jevois::StepRange<int> r1(0, 5, 100);
90 jevois::StepRange<float> r2(r1); // ok, explicit constructor call
91 myFunc(r2); // ok, no conversion necessary
92 //myFunc(r1) // NO: passing StepRange<int> to function that takes a StepRange<float> arg fails to compile
93 myFunc(jevois::StepRange<float>(r1)); // ok, nice and explicit; and you can think about whether r1 should
94 // have been a StepRange<float> in the first place so you don't waste CPU
95 // doing this conversion (as opposed to just not being aware of the wasting)
96 @endcode */
97 template <typename U>
98 explicit StepRange(StepRange<U> const & other);
99
100 //! Assignment
101 StepRange<T> & operator=(StepRange<T> const & other) = default;
102
103 //! Move assignment
104 StepRange<T> & operator=(StepRange<T> && other) = default;
105
106 //! Return the minimum value
107 T const & min() const;
108
109 //! Return the step value
110 T const & step() const;
111
112 //! Return the maximum value
113 T const & max() const;
114
115 //! Return whether min() == max()
116 bool empty() const;
117
118 //! Return true if a value is valid (i.e., it is min, min+step, min+step*2, ... or max)
119 bool isValueValid(T const val) const;
120
121 private:
122 T itsMin, itsStep, itsMax;
123 };
124
125 // ######################################################################
126 // Free functions for StepRange<T>
127 // ######################################################################
128
129 //! Stream out as "min...(step)...max"
130 /*! \relates jevois::StepRange */
131 template <typename T>
132 std::ostream & operator<<(std::ostream & out, StepRange<T> const & r);
133
134 //! Stream in as "min...(step)...max"
135 /*! \relates jevois::StepRange */
136 template <typename T>
137 std::istream & operator>>(std::istream & in, StepRange<T> & r);
138
139 //! Machine-readable output to a string, for use in jevois::Parameter: outputs \c min...step...max
140 /*! \relates jevois::StepRange */
141 template <class T>
142 void paramValToString(StepRange<T> const & val, std::string & result);
143
144 //! Machine-readable input from a string, for use in jevois::Parameter: reads \c min...step...max
145 /*! \relates jevois::StepRange */
146 template <class T>
147 void paramStringToVal(std::string const & valstring, StepRange<T> & result);
148
149 //! Equality test: StepRange<T> == StepRange<T>
150 /*! \relates jevois::StepRange */
151 template <typename T>
152 bool operator==(StepRange<T> const & range1, StepRange<T> const & range2);
153
154 //! Inequality test: StepRange<T> != StepRange<T>
155 /*! \relates jevois::StepRange */
156 template <typename T>
157 bool operator!=(StepRange<T> const & range1, StepRange<T> const & range2);
158
159} // namespace jevois
160
161// Include inlined implementation details that are of no interest to the end user
162#include <jevois/Types/details/StepRangeImpl.H>
163
A generic range class with a step.
Definition StepRange.H:70
StepRange(T const mini, T const stepi, T const maxi)
Constructor.
std::ostream & operator<<(std::ostream &out, StepRange< T > const &r)
Stream out as "min...(step)...max".
StepRange(StepRange< T > const &other)=default
Copy constructor.
bool operator==(StepRange< T > const &range1, StepRange< T > const &range2)
Equality test: StepRange<T> == StepRange<T>
bool operator!=(StepRange< T > const &range1, StepRange< T > const &range2)
Inequality test: StepRange<T> != StepRange<T>
StepRange(StepRange< T > &&other)=default
Move constructor.
void paramStringToVal(std::string const &valstring, StepRange< T > &result)
Machine-readable input from a string, for use in jevois::Parameter: reads min...step....
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)
T const & min() const
Return the minimum value.
void paramValToString(StepRange< T > const &val, std::string &result)
Machine-readable output to a string, for use in jevois::Parameter: outputs min...step....
StepRange< T > & operator=(StepRange< T > const &other)=default
Assignment.
bool empty() const
Return whether min() == max()
StepRange(StepRange< U > const &other)
Copy-conversion constructor, uses jevois::clamped_convert<T,U> internally.
StepRange()
Default constructor, range is [0 .. (0) .. 0].
std::istream & operator>>(std::istream &in, StepRange< T > &r)
Stream in as "min...(step)...max".
T const & max() const
Return the maximum value.
T const & step() const
Return the step value.
StepRange< T > & operator=(StepRange< T > &&other)=default
Move assignment.
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2