JeVois  1.5
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
ValidValuesSpecImpl.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 code is inspired by the Neuromorphic Robotics Toolkit (http://nrtkit.org)
19 
20 #pragma once
21 
22 #include <sstream>
24 
25 // ######################################################################
26 // ######################################################################
27 // ######################################################################
28 template <typename T> inline
30 { }
31 
32 template <typename T> inline
34 { }
35 
36 // ######################################################################
37 // ######################################################################
38 // ######################################################################
39 template <typename T> inline
41 { }
42 
43 template <typename T> inline
45 { }
46 
47 template <typename T> inline
48 bool jevois::ValidValuesSpecNone<T>::checkValueValidity(T const & JEVOIS_UNUSED_PARAM(val)) const
49 { return true; }
50 
51 template <typename T> inline
52 std::string const jevois::ValidValuesSpecNone<T>::str() const
53 { return "None:[]"; }
54 
55 // ######################################################################
56 // ######################################################################
57 // ######################################################################
58 template <typename T> inline
59 jevois::ValidValuesSpecList<T>::ValidValuesSpecList(std::vector<T> const & valid_list) :
60  ValidValuesSpecBase<T>(), itsValidList(valid_list)
61 { }
62 
63 template <typename T> inline
65 { }
66 
67 template <typename T> inline
69 {
70  for (T const & v : itsValidList) if (val == v) return true;
71  return false;
72 }
73 
74 template <typename T> inline
75 std::string const jevois::ValidValuesSpecList<T>::str() const
76 {
77  std::ostringstream os;
78  os << "List:[";
79  for (T const & v : itsValidList) os << v << '|';
80  os.seekp(-1, std::ios_base::end); os << ']';
81  return os.str();
82 }
83 
84 // ######################################################################
85 // ######################################################################
86 // ######################################################################
87 template <typename T> inline
89  ValidValuesSpecBase<T>(), itsValidRange(valid_range)
90 { }
91 
92 template <typename T> inline
94 { }
95 
96 template <typename T> inline
98 {
99  return (val >= itsValidRange.min() && val <= itsValidRange.max());
100 }
101 
102 template <typename T> inline
103 std::string const jevois::ValidValuesSpecRange<T>::str() const
104 {
105  std::ostringstream os;
106  os << "Range:" << itsValidRange;
107  return os.str();
108 }
109 
110 // ######################################################################
111 // ######################################################################
112 // ######################################################################
113 template <typename T> inline
115  ValidValuesSpecBase<T>(), itsValidStepRange(valid_range)
116 { }
117 
118 template <typename T> inline
120 { }
121 
122 template <typename T> inline
124 {
125  return itsValidStepRange.isValueValid(val);
126 }
127 
128 template <typename T> inline
130 {
131  std::ostringstream os;
132  os << "StepRange:" << itsValidStepRange;
133  return os.str();
134 }
135 
136 // ######################################################################
137 // ######################################################################
138 // ######################################################################
139 template <typename T> inline
140 jevois::ValidValuesSpecRegex<T>::ValidValuesSpecRegex(boost::regex const & valid_regex) :
141  ValidValuesSpecBase<T>(), itsValidRegex(valid_regex)
142 { }
143 
144 template <typename T> inline
146 { }
147 
148 template <typename T> inline
150 {
151  std::string v; jevois::paramValToString(val, v);
152  return boost::regex_match(v, itsValidRegex);
153 }
154 
155 template <typename T> inline
156 std::string const jevois::ValidValuesSpecRegex<T>::str() const
157 {
158  std::ostringstream os;
159  os << "Regex:[" << itsValidRegex.str() << ']';
160  return os.str();
161 }
ValidValuesSpecRegex()=delete
No default constructor, always need to provide a regex.
ValidValuesSpecRange()=delete
No default constructor, always need to provide a range.
A generic range class with a step.
Definition: StepRange.H:69
Base class for specifying a set of valid values for a type.
virtual ~ValidValuesSpecRange()
Destructor.
virtual bool checkValueValidity(T const &val) const
Check whether a proposed value is valid, here always returns true.
ValidValuesSpecList()=delete
No default constructor, always need to provide a list.
StepRange< T > const itsValidStepRange
Our step-range of valid values.
void paramValToString(T const &val, std::string &result)
Machine-readable conversion of T to a string, for use in jevois::Parameter.
virtual ~ValidValuesSpecRegex()
Destructor.
virtual ~ValidValuesSpecList()
Destructor.
std::vector< T > const itsValidList
Our list of valid values.
virtual std::string const str() const
Convert to a readable string: Range:[MIN-MAX] where MIN and MAX are replaced by the actual range boun...
virtual std::string const str() const
Convert to a readable string: StepRange:[MIN-STEP-MAX] where MIN, STEP and MAX are replaced by actual...
boost::regex const itsValidRegex
Th eregex that defines our valid values.
ValidValuesSpecBase()
Construct, for the base class this is a no-op.
virtual std::string const str() const
Convert to a readable string.
virtual bool checkValueValidity(T const &val) const
Check whether a proposed value is valid, returns true iff value is a match against our regex...
Range< T > const itsValidRange
Our range of valid values.
virtual std::string const str() const
Convert to a readable string.
ValidValuesSpecNone()
Construct with no specification, any value that T can take goes.
A generic range class.
Definition: Range.H:80
virtual bool checkValueValidity(T const &val) const
Check whether a proposed value is valid, returns true iff value is in our range (bounds included) ...
virtual std::string const str() const
Convert to a readable string.
virtual bool checkValueValidity(T const &val) const
Check whether a proposed value is valid, returns true iff value is in our list.
ValidValuesSpecStepRange()=delete
No default constructor, always need to provide a range.
virtual ~ValidValuesSpecStepRange()
Destructor.
virtual ~ValidValuesSpecNone()
Destructor.
virtual ~ValidValuesSpecBase()
Destructor.
virtual bool checkValueValidity(T const &val) const
Check whether a proposed value is valid, returns true iff value is in our range (bounds included) ...