JeVois  1.1
JeVois Smart Embedded Machine Vision Toolkit
ParameterHelpers.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 
23 
24 namespace jevois
25 {
26  //! Generic variadic template class template definition for Component Parameters
27  /*! \see Parameter<Param, Tail ...> for detailed documentation. */
28  template <class ... Params> class Parameter;
29 
30  //! Special case to terminate variadic template inheritance recursion
31  /*! \see Parameter<Param, Tail ...> for detailed documentation. */
32  template <> class Parameter<> { };
33 
34 } // namespace jevois
35 
36 // We do not define these macros when compiling the doxygen doc so that parameter declarations in components and modules
37 // will be documented as related functions. Just remember to comment each parameter declaration with a relates doxygen
38 // tag that relates it to the host component.
39 
40 // BEGIN_JEVOIS_CODE_SNIPPET parametermacros.C
41 
42 #ifndef JEVOIS_DOXYGEN
43 
44 // Convenience macro to define a Parameter type. All the ... args are passed to ParameterDef
45 #define JEVOIS_DECLARE_PARAMETER(ParamName, ParamType, ...) \
46  struct ParamName : public virtual jevois::ParameterRegistry, public jevois::ParameterCore<ParamType> \
47  { \
48  typedef ParamType type; \
49  \
50  inline ParamName() : jevois::ParameterCore<ParamType>(jevois::ParameterDef<ParamType>(#ParamName, __VA_ARGS__)) \
51  { jevois::ParameterRegistry::addParameter(this); } \
52  \
53  inline virtual ~ParamName() \
54  { jevois::ParameterRegistry::removeParameter(this); } \
55  \
56  inline virtual jevois::Component const * owner() const override \
57  { return dynamic_cast<jevois::Component const *>(static_cast<jevois::ParameterRegistry const *>(this)); } \
58  };
59 
60 // Convenience macro to define a Parameter type with callback. All the ... args are passed to ParameterDef
61 #define JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(ParamName, ParamType, ...) \
62  struct ParamName : public virtual jevois::ParameterRegistry, public jevois::ParameterCore<ParamType> \
63  { \
64  typedef ParamType type; \
65  \
66  virtual void onParamChange(ParamName const & param, ParamType const & newval) = 0; \
67  \
68  inline ParamName() : jevois::ParameterCore<ParamType>(jevois::ParameterDef<ParamType>(#ParamName, __VA_ARGS__)) \
69  { setCallback([this](ParamType const & newval) { this->onParamChange(*this, newval); }); \
70  jevois::ParameterRegistry::addParameter(this); } \
71  \
72  inline virtual ~ParamName() \
73  { jevois::ParameterRegistry::removeParameter(this); } \
74  \
75  inline virtual jevois::Component const * owner() const override \
76  { return dynamic_cast<jevois::Component const *>(static_cast<jevois::ParameterRegistry const *>(this)); } \
77  };
78 
79 #endif
80 
81 // END_JEVOIS_CODE_SNIPPET
Generic variadic template class template definition for Component Parameters.