iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConversionHelpers.H
Go to the documentation of this file.
1 /*! @file
2  @author David J. Berg <dberg@usc.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 
36 
37 #ifndef INCLUDE_NRT_CORE_TYPING_DETAILS_CONVERSIONHELPERS_H
38 #define INCLUDE_NRT_CORE_TYPING_DETAILS_CONVERSIONHELPERS_H
39 
40 namespace nrt
41 {
42  // not_subranged
43  template <class dest_type, class source_type,
44  bool B = nrt_traits<dest_type>::is_arithmetic && nrt_traits<source_type>::is_arithmetic>
45  struct not_subranged : std::false_type {};
46 
47  template <class dest_type, class source_type>
48  struct not_subranged<dest_type, source_type, true>
49  {
50  static bool const value = !boost::numeric::is_subranged<dest_type, source_type>::value &&
51  boost::numeric::conversion_traits<dest_type, source_type>::int_float_mixture::value !=
52  boost::numeric::float_to_integral;
53  };
54 
55  // not_subranged_round
56  template <class dest_type, class source_type,
57  bool B = nrt_traits<dest_type>::is_arithmetic && nrt_traits<source_type>::is_arithmetic>
58  struct not_subranged_round : std::false_type {};
59 
60  template <class dest_type, class source_type>
61  struct not_subranged_round<dest_type, source_type, true>
62  {
63  static bool const value = !boost::numeric::is_subranged<dest_type, source_type>::value &&
64  boost::numeric::conversion_traits<dest_type, source_type>::int_float_mixture::value ==
65  boost::numeric::float_to_integral;
66  };
67 
68  // subranged_signed
69  template <class dest_type, class source_type,
70  bool B = nrt_traits<dest_type>::is_arithmetic && nrt_traits<source_type>::is_arithmetic>
71  struct subranged_signed : std::false_type {};
72 
73  template <class dest_type, class source_type>
74  struct subranged_signed <dest_type, source_type, true>
75  {
76  static bool const value = boost::numeric::is_subranged<dest_type, source_type>::value &&
77  boost::numeric::conversion_traits<dest_type,source_type>::int_float_mixture::value ==
78  boost::numeric::integral_to_integral &&
79  boost::numeric::conversion_traits<dest_type,source_type>::sign_mixture::value ==
80  boost::numeric::signed_to_signed;
81  };
82 
83  // subranged_unsigned
84  template <class dest_type, class source_type,
85  bool B = nrt_traits<dest_type>::is_arithmetic && nrt_traits<source_type>::is_arithmetic>
86  struct subranged_unsigned : std::false_type {};
87 
88  template <class dest_type, class source_type>
89  struct subranged_unsigned <dest_type, source_type, true>
90  {
91  static bool const value = boost::numeric::is_subranged<dest_type, source_type>::value &&
92  boost::numeric::conversion_traits<dest_type,source_type>::int_float_mixture::value ==
93  boost::numeric::integral_to_integral &&
94  boost::numeric::conversion_traits<dest_type,source_type>::sign_mixture::value ==
95  boost::numeric::unsigned_to_unsigned;
96  };
97 
98  // subranged_signed_unsigned
99  template <class dest_type, class source_type,
100  bool B = nrt_traits<dest_type>::is_arithmetic && nrt_traits<source_type>::is_arithmetic>
101  struct subranged_signed_unsigned : std::false_type {};
102 
103  template <class dest_type, class source_type>
104  struct subranged_signed_unsigned <dest_type, source_type, true>
105  {
106  static bool const value = boost::numeric::is_subranged<dest_type, source_type>::value &&
107  boost::numeric::conversion_traits<dest_type,source_type>::int_float_mixture::value ==
108  boost::numeric::integral_to_integral &&
109  boost::numeric::conversion_traits<dest_type,source_type>::sign_mixture::value ==
110  boost::numeric::signed_to_unsigned;
111  };
112 
113  // subranged_unsigned_signed
114  template <class dest_type, class source_type,
115  bool B = nrt_traits<dest_type>::is_arithmetic && nrt_traits<source_type>::is_arithmetic>
116  struct subranged_unsigned_signed : std::false_type {};
117 
118  template <class dest_type, class source_type>
119  struct subranged_unsigned_signed<dest_type, source_type, true>
120  {
121  static bool const value = boost::numeric::is_subranged<dest_type, source_type>::value &&
122  boost::numeric::conversion_traits<dest_type,source_type>::int_float_mixture::value ==
123  boost::numeric::integral_to_integral &&
124  boost::numeric::conversion_traits<dest_type,source_type>::sign_mixture::value ==
125  boost::numeric::unsigned_to_signed;
126  };
127 
128  // subranged_float
129  template <class dest_type, class source_type,
130  bool B = nrt_traits<dest_type>::is_arithmetic && nrt_traits<source_type>::is_arithmetic>
131  struct subranged_float : std::false_type {};
132 
133  template <class dest_type, class source_type>
134  struct subranged_float<dest_type, source_type, true>
135  {
136  static bool const value = boost::numeric::is_subranged<dest_type, source_type>::value &&
137  (boost::numeric::conversion_traits<dest_type,source_type>::int_float_mixture::value ==
138  boost::numeric::integral_to_float ||
139  boost::numeric::conversion_traits<dest_type,source_type>::int_float_mixture::value ==
140  boost::numeric::float_to_float);
141  };
142 
143  // subranged_float_round
144  template <class dest_type, class source_type,
145  bool B = nrt_traits<dest_type>::is_arithmetic && nrt_traits<source_type>::is_arithmetic>
146  struct subranged_float_round : std::false_type {};
147 
148  template <class dest_type, class source_type>
149  struct subranged_float_round<dest_type, source_type, true>
150  {
151  static bool const value = boost::numeric::is_subranged<dest_type, source_type>::value &&
152  boost::numeric::conversion_traits<dest_type,source_type>::int_float_mixture::value ==
153  boost::numeric::float_to_integral;
154  };
155 }
156 
157 #endif // INCLUDE_NRT_CORE_TYPING_DETAILS_CONVERSIONHELPERS_H
158