iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Conversion.H
Go to the documentation of this file.
1 /*! @file
2  @author Randolph Voorhies (voorhies at usc dot edu)
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 #ifndef INCLUDE_NRT_CORE_TYPING_CONVERSION_H
36 #define INCLUDE_NRT_CORE_TYPING_CONVERSION_H
37 
39 
40 #include <boost/numeric/conversion/bounds.hpp>
41 #include <boost/numeric/conversion/is_subranged.hpp>
42 #include <boost/numeric/conversion/conversion_traits.hpp>
43 
45 #include <cmath> // for std::round()
46 
47 namespace nrt
48 {
49  /*! \defgroup typing NRT types, definitions and related functions
50  \ingroup core */
51 
52  /*! \defgroup conversions Conversion functions between types
53 
54  Utility functions to allow the safe conversion from any integral or floating point type to another by clamping the
55  value to the destination type's max/min range. The conversion functions also round floating point numbers to the
56  nearest integer (as opposed to the lower one, as by default in C/C++) when converting them to integrals.
57 
58  \ingroup typing */
59 
60  /*! @{ */ // **********************************************************************
61 
62  //! Perform a clamped-conversion from one type to another
63  template <class dest_type, class source_type> inline
64  typename std::enable_if<not_subranged<dest_type,source_type>::value, dest_type>::type
65  clamped_convert(source_type source);
66 
67  //! Perform a clamped-conversion from one type to another
68  template <class dest_type, class source_type> inline
69  typename std::enable_if<not_subranged_round<dest_type,source_type>::value, dest_type>::type
70  clamped_convert(source_type source);
71 
72  //! Perform a clamped-conversion from one type to another
73  template <class dest_type, class source_type> inline
74  typename std::enable_if<subranged_signed<dest_type, source_type>::value, dest_type>::type
75  clamped_convert(source_type source);
76 
77  //! Perform a clamped-conversion from one type to another
78  template <class dest_type, class source_type> inline
79  typename std::enable_if<subranged_unsigned<dest_type, source_type>::value, dest_type>::type
80  clamped_convert(source_type source);
81 
82  //! Perform a clamped-conversion from one type to another
83  template <class dest_type, class source_type> inline
84  typename std::enable_if<subranged_signed_unsigned<dest_type, source_type>::value, dest_type>::type
85  clamped_convert(source_type source);
86 
87  //! Perform a clamped-conversion from one type to another
88  template <class dest_type, class source_type> inline
89  typename std::enable_if<subranged_unsigned_signed<dest_type, source_type>::value, dest_type>::type
90  clamped_convert(source_type source);
91 
92  //! Perform a clamped-conversion from one type to another
93  template <class dest_type, class source_type> inline
94  typename std::enable_if<subranged_float<dest_type, source_type>::value, dest_type>::type
95  clamped_convert(source_type source);
96 
97  //! Perform a clamped-conversion from one type to another
98  template <class dest_type, class source_type> inline
99  typename std::enable_if<subranged_float_round<dest_type, source_type>::value, dest_type>::type
100  clamped_convert(source_type source);
101 
102  /*! @} */ // **********************************************************************
103 }
104 
106 
107 #endif // INCLUDE_NRT_CORE_TYPING_CONVERSION_H
108