JeVois  1.21
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
Enum.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 copyright GNU Public License (GPL v3)
22 // ////////////////////////////////////////////////////////////////////////
23 // The iLab Neuromorphic Robotics Toolkit (NRT) //
24 // Copyright 2010-2012 by the University of Southern California (USC) //
25 // and the iLab at USC. //
26 // //
27 // iLab - University of Southern California //
28 // Hedco Neurociences Building, Room HNB-10 //
29 // Los Angeles, Ca 90089-2520 - USA //
30 // //
31 // See http://ilab.usc.edu for information about this project. //
32 // ////////////////////////////////////////////////////////////////////////
33 // This file is part of The iLab Neuromorphic Robotics Toolkit. //
34 // //
35 // The iLab Neuromorphic Robotics Toolkit is free software: you can //
36 // redistribute it and/or modify it under the terms of the GNU General //
37 // Public License as published by the Free Software Foundation, either //
38 // version 3 of the License, or (at your option) any later version. //
39 // //
40 // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
41 // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
42 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
43 // PURPOSE. See the GNU General Public License for more details. //
44 // //
45 // You should have received a copy of the GNU General Public License //
46 // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
47 // <http://www.gnu.org/licenses/>. //
48 // ////////////////////////////////////////////////////////////////////////
49*/
50
51#pragma once
52
53/*! \defgroup types JeVois-specific types and generic helper classes
54
55 These types and classes support the core JeVois implementation. Pay particular attention to the very useful
56 JEVOIS_DEFINE_ENUM_CLASS(name, SEQ) macro to define new enums that can be used in Parameter to allow menu-style
57 parameters.
58
59 JEVOIS_DEFINE_ENUM_CLASS(name, SEQ)
60 -----------------------------------
61
62 Helper macro to define new enum class types. SEQ should be a BOOST_PP_SEQ (see example syntax below). You will get:
63
64 - an enum class declared and defined with the name and values supplied
65 - a static const std::vector of your enum values, with all the values that the enum can take, in name_Values
66 - a static const std::vector of std::string, with string names of all the values the enum can take, in name_Strings
67 - operator<< and operator>> for your enum.
68
69 You can in particular use name_Values when defining a Parameter definition to list all the valid values, and the
70 streaming operators will allow you to set the Parameter value by string, etc.
71
72 For example:
73
74 @code
75 JEVOIS_DEFINE_ENUM_CLASS(myEnum, (One) (Two) (Three));
76 @endcode
77
78 expands to:
79
80 - first, the actual definition of the enum class, with the values you specified in the sequence:
81 @code
82 enum class myEnum { One, Two, Three };
83 @endcode
84
85 - second, a static const vector that contains all the enum values, listed in the order you specified:
86 @code
87 static std::vector<myEnum> const myEnum_Values { myEnum::One, myEnum::Two, myEnum::Three };
88 @endcode
89
90 - third, a static const vector of strings that contains all the enum values in string form, listed in the order you
91 specified:
92 @code
93 static std::vector<std::string> const myEnum_Strings { "One", "Two", "Three" };
94 @endcode
95
96 - finally, two stream operators that allow you to convert between your enum values and string:
97 @code
98 inline std::ostream & operator<<(std::ostream & os, myEnum const & v) {
99 std::vector<myEnum>::const_iterator vitr = myEnum_Values.begin(), vend = myEnum_Values.end();
100 std::vector<std::string>::const_iterator sitr = myEnum_Strings.begin();
101 while (vitr != vend) if (v == *vitr) { os << *sitr; return os; } else { ++vitr; ++sitr; }
102 return os;
103 }
104
105 inline std::istream & operator>>(std::istream & is, myEnum & v) {
106 std::string s; is >> s;
107 std::vector<myEnum>::const_iterator vitr = myEnum_Values.begin(), vend = myEnum_Values.end();
108 std::vector<std::string>::const_iterator sitr = myEnum_Strings.begin();
109 while (vitr != vend) if (s == *sitr) { v = *vitr; return is; } else { ++vitr; ++sitr; }
110 throw std::range_error("Invalid value [" + s + "] for Enum class myEnum");
111 };
112 @endcode
113
114 Note how the \c operator>> will throw if the given string does not match the string representation of one of the
115 enum's values. */
116
117//! Include details of no interest to the user
118#include <jevois/Types/details/EnumImpl.H>
119