JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
ParameterStringConversion.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 <string>
23#include <iostream>
24#include <sstream>
25#include <vector>
26#include <opencv2/core/core.hpp> // for Point_ and Size
27
28#ifdef JEVOIS_PRO
29#include <imgui.h> // for ImColor
30#endif
31
32namespace jevois
33{
34 /*! \defgroup parameterstrconv String conversions for Parameter
35 \ingroup parameter */
36
37 /*! @{ */ // **********************************************************************
38
39 //! Machine-readable conversion of T to a string, for use in jevois::Parameter
40 /*! A default implementation is provided which internally just uses jevois::to_string(). When implementing new types
41 that can be used as parameters, users should supply the appropriate template specialization for this
42 function. This function is used internally by Parameter to get a Parameter value as a string. */
43 template <typename T>
44 void paramValToString(T const & val, std::string & result);
45
46 //! Machine-readable conversion of T to a string, specialization to convert unsigned char to number, not character
47 template <>
48 void paramValToString<unsigned char>(unsigned char const & val, std::string & result);
49
50 //! Machine-readable conversion from string to T, for use in jevois::Parameter
51 /*! @throws Implementation-dependent exception encountered during conversion
52
53 A default implementation is provided which internally just uses jevois::from_string(). When implementing new types
54 that can be used as parameters, users should supply the appropriate template specialization for this
55 function. This function is used internally by Parameter to set a Parameter value from string. */
56 template <typename T>
57 void paramStringToVal(std::string const & valstring, T & result);
58
59 //! Machine-readable output to a string, for use in jevois::Parameter: outputs [\c Element1, \c Element2, ...]
60 /*! Overload for std::vector<T> which supports nesting of other vectors and vectors of other types */
61 template <typename Q>
62 void paramValToString(std::vector<Q> const & val, std::string & result);
63
64 //! Machine-readable input from a string, for use in jevois::Parameter: reads [\c Element1, \c Element2, ...]
65 /*! Overload for std::vector<T> which supports nesting of other vectors and vectors of other types */
66 template <typename Q>
67 void paramStringToVal(std::string const & valstring, std::vector<Q> & result);
68
69 //! Machine-readable output to a string, for use in jevois::Parameter: outputs \c first \c second
70 template <typename F, typename S>
71 void paramValToString(std::pair<F, S> const & val, std::string & result);
72
73 //! Machine-readable input from a string, for use in jevois::Parameter: reads \c first \c second
74 template <typename F, typename S>
75 void paramStringToVal(std::string const & valstring, std::pair<F, S> & result);
76
77 //! Machine-readable output to a string, for use in jevois::Parameter: outputs \c x \c y
78 template <typename T>
79 void paramValToString(cv::Point_<T> const & val, std::string & result);
80
81 //! Machine-readable input from a string, for use in jevois::Parameter: reads \c x \c y
82 template <typename T>
83 void paramStringToVal(std::string const & valstring, cv::Point_<T> & result);
84
85 //! Machine-readable output to a string, for use in jevois::Parameter: outputs \c width \c height
86 template <typename T>
87 void paramValToString(cv::Size_<T> const & val, std::string & result);
88
89 //! Machine-readable input from a string, for use in jevois::Parameter: reads \c width \c height
90 template <typename T>
91 void paramStringToVal(std::string const & valstring, cv::Size_<T> & result);
92
93 //! Machine-readable output to a string, for use in jevois::Parameter: outputs \c r \c g \c b \c a
94 template <typename T>
95 void paramValToString(cv::Scalar_<T> const & val, std::string & result);
96
97 //! Machine-readable input from a string, for use in jevois::Parameter: reads \c r \c g \c b \c a or subsets
98 template <typename T>
99 void paramStringToVal(std::string const & valstring, cv::Scalar_<T> & result);
100
101#ifdef JEVOIS_PRO
102 //! Machine-readable output to a string, for use in jevois::Parameter: outputs \c R \c G \c B \c A, each 0..255
103 template <>
104 void paramValToString<ImColor>(ImColor const & val, std::string & result);
105
106 //! Machine-readable input from a string, for use in jevois::Parameter: reads \c R \c G \c B \c A, each 0..255
107 template <>
108 void paramStringToVal<ImColor>(std::string const & valstring, ImColor & result);
109#endif
110
111 //! Machine-readable output to a string, for use in jevois::Parameter: outputs [\c Key1:Value1, \c Key2:Value2, ...]
112 /*! Overload for std::map which supports nesting of other maps/vectors */
113 template <typename K, typename V>
114 void paramValToString(std::map<K,V> const & val, std::string & result);
115
116 //! Machine-readable input from a string, for use in jevois::Parameter: reads [\c Key1:Value1, \c Key2:Value2, ...]
117 /*! Overload for std::map which supports nesting of other maps/vectors */
118 template <typename K, typename V>
119 void paramStringToVal(std::string const & valstring, std::map<K,V> & result);
120
121 //! Machine-readable conversion of bool to a string, for use in jevois::Parameter
122 template <>
123 void paramValToString<bool>(bool const & val, std::string & result);
124
125 //! Machine-readable conversion from string to bool, for use in jevois::Parameter
126 /*! @throws jevois::exception::Exception if input string is malformed.
127
128 Specialization for bool so that we can accept nice verbose terms rather than just 0 and 1. Acceptable ways to set
129 a bool Parameter are:
130
131 - "true" or "false"
132 - "True" or "False"
133 - "t" or "f"
134 - "yes" or "no"
135 - "y" or "n"
136 - 1 or 0
137 - An empty string will set the Parameter to true, so you may use boolean parameters as switches, e.g.,
138 <code>"--myFlag"</code> is equivalent to <code>"--myFlag=true"</code> */
139 template <>
140 void paramStringToVal<bool>(std::string const & valstring, bool & result);
141
142 //! Machine-readable conversion of string to a string, for use in jevois::Parameter
143 /*! This implementation just returns the original string. */
144 template <>
145 void paramValToString<std::string>(std::string const & val, std::string & result);
146
147 //! Machine-readable conversion from string to string, for use in jevois::Parameter
148 /*! This implementation just returns the original string. */
149 template <>
150 void paramStringToVal<std::string>(std::string const & valstring, std::string & result);
151
152 /*! @} */ // **********************************************************************
153
154} // namespace jevois
155
156//! Include implementation details of no interest to the user
157#include <jevois/Component/details/ParameterStringConversionImpl.H>
158
159
void paramValToString< std::string >(std::string const &val, std::string &result)
Machine-readable conversion of string to a string, for use in jevois::Parameter.
void paramStringToVal< ImColor >(std::string const &valstring, ImColor &result)
Machine-readable input from a string, for use in jevois::Parameter: reads R G B A,...
void paramValToString< unsigned char >(unsigned char const &val, std::string &result)
Machine-readable conversion of T to a string, specialization to convert unsigned char to number,...
void paramValToString< bool >(bool const &val, std::string &result)
Machine-readable conversion of bool to a string, for use in jevois::Parameter.
void paramStringToVal< bool >(std::string const &valstring, bool &result)
Machine-readable conversion from string to bool, for use in jevois::Parameter.
void paramValToString< ImColor >(ImColor const &val, std::string &result)
Machine-readable output to a string, for use in jevois::Parameter: outputs R G B A,...
void paramValToString(T const &val, std::string &result)
Machine-readable conversion of T to a string, for use in jevois::Parameter.
void paramStringToVal(std::string const &valstring, T &result)
Machine-readable conversion from string to T, for use in jevois::Parameter.
void paramStringToVal< std::string >(std::string const &valstring, std::string &result)
Machine-readable conversion from string to string, for use in jevois::Parameter.
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2