libpnicore
checked_convertible.hpp
1 //
2 // (c) Copyright 2014 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpnicore.
5 //
6 // libpnicore is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpnicore is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpnicore. If not, see <http://www.gnu.org/licenses/>.
18 //
19 // ============================================================================
20 //
21 // Created on: Dec 18, 2014
22 // Author: Eugen Wintersberger
23 //
24 #pragma once
25 
26 #include <boost/mpl/pair.hpp>
27 #include <boost/mpl/vector.hpp>
28 #include <boost/mpl/contains.hpp>
29 #include <boost/mpl/map.hpp>
30 #include <boost/mpl/at.hpp>
31 #include "id_type_map.hpp"
32 
33 namespace pni{
34 namespace core{
35 
36 
43  typedef boost::mpl::map<
44  //-------------source type uint8--------------------------------------
45  boost::mpl::pair<uint8,boost::mpl::vector<int8>>,
46 
47  //----------------source type uint16----------------------------------
48  boost::mpl::pair<
49  uint16,
50  boost::mpl::vector<uint8,int8,int16>
51  >,
52 
53  //----------------------source type uint32----------------------------
54  boost::mpl::pair<
55  uint32,
56  boost::mpl::vector<uint8,uint16,
58  >,
59 
60  //--------------------------source type uint64------------------------
61  boost::mpl::pair<
62  uint64,
63  boost::mpl::vector<uint8,uint16,uint32,
65  >,
66 
67  //------------------------source type int8 ---------------------------
68  boost::mpl::pair<
69  int8,
70  boost::mpl::vector<uint8,uint16,uint32,uint64>
71  >,
72 
73  //-----------------------source type int16----------------------------
74  boost::mpl::pair<
75  int16,
76  boost::mpl::vector<uint8,uint16,uint32,uint64,int8>
77  >,
78 
79  //------------------------source type int32---------------------------
80  boost::mpl::pair<
81  int32,
82  boost::mpl::vector<uint8,uint16,uint32,uint64,
83  int8,int16>
84  >,
85 
86  //------------------------source type int64----------------------------
87  boost::mpl::pair<
88  int64,
89  boost::mpl::vector<uint8,uint16,uint32,uint64,
90  int8,int16,int32>
91  >,
92 
93  //-------------------------source type float64------------------------
94  boost::mpl::pair<float32,boost::mpl::vector<>>,
95  boost::mpl::pair<float64,boost::mpl::vector<float32,complex32> >,
96 
97  //-------------------source type float128-----------------------------
98  boost::mpl::pair<float128,boost::mpl::vector<float32,float64,
100 
101  //-------------------source type complex64----------------------------
102  boost::mpl::pair<complex32,boost::mpl::vector<>>,
103  boost::mpl::pair<
104  complex64,
105  boost::mpl::vector<complex32>
106  >,
107 
108  //-------------------source type complex128---------------------------
109  boost::mpl::pair<complex128,boost::mpl::vector<complex32,complex64>>,
110 
111  boost::mpl::pair<string,boost::mpl::vector<>>,
112  boost::mpl::pair<binary,boost::mpl::vector<>>,
113  boost::mpl::pair<bool_t,boost::mpl::vector<>>
114 
116 
117  //------------------------------------------------------------------------
127  template<
128  typename ST,
129  typename TT
130  >
132  {
134  typedef typename boost::mpl::at<checked_type_vectors,ST>::type map_element;
136  typedef boost::mpl::contains<map_element,TT> c;
138  static const bool value = c::value;
139  };
140 
141 
142 //end of namespace
143 }
144 }
std::complex< float32 > complex32
32Bit complex floating point type
Definition: types/types.hpp:62
long double float128
128Bit IEEE floating point type
Definition: types/types.hpp:58
float float32
32Bit IEEE floating point type
Definition: types/types.hpp:57
check if a type is unchecked convertible
Definition: checked_convertible.hpp:131
Definition: add_op.hpp:29
boost::mpl::at< checked_type_vectors, ST >::type map_element
select the type vector
Definition: checked_convertible.hpp:134
std::complex< float64 > complex64
64Bit complex floating point type
Definition: types/types.hpp:64
int32_t int32
32Bit signed integer type
Definition: types/types.hpp:50
boost::mpl::map< boost::mpl::pair< uint8, boost::mpl::vector< int8 > >, boost::mpl::pair< uint16, boost::mpl::vector< uint8, int8, int16 > >, boost::mpl::pair< uint32, boost::mpl::vector< uint8, uint16, int8, int16, int32 > >, boost::mpl::pair< uint64, boost::mpl::vector< uint8, uint16, uint32, int8, int16, int32, int64 > >, boost::mpl::pair< int8, boost::mpl::vector< uint8, uint16, uint32, uint64 > >, boost::mpl::pair< int16, boost::mpl::vector< uint8, uint16, uint32, uint64, int8 > >, boost::mpl::pair< int32, boost::mpl::vector< uint8, uint16, uint32, uint64, int8, int16 > >, boost::mpl::pair< int64, boost::mpl::vector< uint8, uint16, uint32, uint64, int8, int16, int32 > >, boost::mpl::pair< float32, boost::mpl::vector<> >, boost::mpl::pair< float64, boost::mpl::vector< float32, complex32 > >, boost::mpl::pair< float128, boost::mpl::vector< float32, float64, complex32, complex64 > >, boost::mpl::pair< complex32, boost::mpl::vector<> >, boost::mpl::pair< complex64, boost::mpl::vector< complex32 > >, boost::mpl::pair< complex128, boost::mpl::vector< complex32, complex64 > >, boost::mpl::pair< string, boost::mpl::vector<> >, boost::mpl::pair< binary, boost::mpl::vector<> >, boost::mpl::pair< bool_t, boost::mpl::vector<> > > checked_type_vectors
unchecked convertible map
Definition: checked_convertible.hpp:115
uint8_t uint8
8Bit unsigned integer type
Definition: types/types.hpp:47
uint16_t uint16
16Bit unsigned integer type
Definition: types/types.hpp:49
uint64_t uint64
64Bit unsigned integer type
Definition: types/types.hpp:53
int64_t int64
64Bit signed integer type
Definition: types/types.hpp:52
double float64
64Bit IEEE floating point type
Definition: types/types.hpp:56
int16_t int16
16Bit signed integer type
Definition: types/types.hpp:48
boost::mpl::contains< map_element, TT > c
type to check if TT is in the map
Definition: checked_convertible.hpp:136
int8_t int8
8Bit signed integer type
Definition: types/types.hpp:46
type erasure for POD data
Definition: value.hpp:46
uint32_t uint32
32Bit unsigned integer type
Definition: types/types.hpp:51