Enhanced SIM for E2AP v1 for TS UC
[sim/e2-interface.git] / e2sim / e2apv1sim / src / ASN1 / asn / value_traits.hpp
1 #ifndef _STDEX_VALUE_TRAITS_HPP_INCLUDED_
2 #define _STDEX_VALUE_TRAITS_HPP_INCLUDED_
3
4 /******************************************************************************
5 *
6 *   Copyright (c) 2019 AT&T Intellectual Property.
7 *   Copyright (c) 2018-2019 Nokia.
8 *
9 *   Licensed under the Apache License, Version 2.0 (the "License");
10 *   you may not use this file except in compliance with the License.
11 *   You may obtain a copy of the License at
12 *
13 *       http://www.apache.org/licenses/LICENSE-2.0
14 *
15 *   Unless required by applicable law or agreed to in writing, software
16 *   distributed under the License is distributed on an "AS IS" BASIS,
17 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 *   See the License for the specific language governing permissions and
19 *   limitations under the License.
20 *
21 ******************************************************************************/
22
23 #include <boost/utility.hpp>
24 #include <boost/mpl/int.hpp>
25 #include <boost/mpl/less_equal.hpp>
26 #include <boost/mpl/greater.hpp>
27 #include <boost/mpl/and.hpp>
28
29 #include "type_defs.h"
30
31 namespace stdex {
32 namespace value {
33
34 namespace mpl = boost::mpl;
35
36 //NOTE! length is in bits
37 typedef mpl::int_<8>    _8;
38 typedef mpl::int_<16>   _16;
39 typedef mpl::int_<24>   _24;
40 typedef mpl::int_<32>   _32;
41 typedef mpl::int_<40>   _40;
42 typedef mpl::int_<48>   _48;
43 typedef mpl::int_<56>   _56;
44 typedef mpl::int_<64>   _64;
45
46 template<int num_bits>
47 struct bits_to_bytes : mpl::int_< (num_bits + 7) / 8 > {};
48
49 /******************************************************************************
50 * Class:                value::traits<LEN>
51 * Description:  select min integer type to fit LEN bits
52 * Notes:                LEN is positive integer type (mpl::int_) = number of bits
53 ******************************************************************************/
54 template <class LEN, typename Enabler = void> struct traits;
55
56 template <class LEN>
57 struct traits<LEN, typename boost::enable_if<
58                 mpl::less_equal<LEN, _8>
59         >::type
60 >
61 {
62         typedef _8            value_length;
63         typedef u8            value_type;
64         typedef value_type    param_type;
65 };
66
67 template <class LEN>
68 struct traits<LEN, typename boost::enable_if<
69                 mpl::and_<mpl::greater<LEN, _8>, mpl::less_equal<LEN, _16> >
70         >::type
71 >
72 {
73         typedef _16           value_length;
74         typedef u16           value_type;
75         typedef value_type    param_type;
76 };
77
78 template <class LEN>
79 struct traits<LEN, typename boost::enable_if<
80                 mpl::and_<mpl::greater<LEN, _16>, mpl::less_equal<LEN, _24> >
81         >::type
82 >
83 {
84         typedef _24           value_length;
85         typedef u32           value_type;
86         typedef value_type    param_type;
87 };
88
89 template <class LEN>
90 struct traits<LEN, typename boost::enable_if<
91                 mpl::and_<mpl::greater<LEN, _24>, mpl::less_equal<LEN, _32> >
92         >::type
93 >
94 {
95         typedef _32           value_length;
96         typedef u32           value_type;
97         typedef value_type    param_type;
98 };
99
100 template <class LEN>
101 struct traits<LEN, typename boost::enable_if<
102                 mpl::and_<mpl::greater<LEN, _32>, mpl::less_equal<LEN, _40> >
103         >::type
104 >
105 {
106         typedef _40           value_length;
107         typedef u64           value_type;
108         typedef value_type    param_type;
109 };
110
111 template <class LEN>
112 struct traits<LEN, typename boost::enable_if<
113                 mpl::and_<mpl::greater<LEN, _40>, mpl::less_equal<LEN, _48> >
114         >::type
115 >
116 {
117         typedef _48           value_length;
118         typedef u64           value_type;
119         typedef value_type    param_type;
120 };
121
122 template <class LEN>
123 struct traits<LEN, typename boost::enable_if<
124                 mpl::and_<mpl::greater<LEN, _48>, mpl::less_equal<LEN, _56> >
125         >::type
126 >
127 {
128         typedef _56           value_length;
129         typedef u64           value_type;
130         typedef value_type    param_type;
131 };
132
133 template <class LEN>
134 struct traits<LEN, typename boost::enable_if<
135                 mpl::and_<mpl::greater<LEN, _56>, mpl::less_equal<LEN, _64> >
136         >::type
137 >
138 {
139         typedef _64           value_length;
140         typedef u64           value_type;
141         typedef value_type    param_type;
142 };
143
144 template <class LEN>
145 struct traits<LEN, typename boost::enable_if<
146                 mpl::greater<LEN, _64>
147         >::type
148 >
149 {
150         typedef LEN                         value_length;
151         struct value_type {u8 value[bits_to_bytes<LEN::value>::value];};
152         typedef value_type const&           param_type;
153 };
154
155
156 //template <class LEN>
157 //struct traits<LEN,
158 //      typename boost::enable_if<
159 //              mpl::greater<LEN, _32>
160 //      >::type
161 //>
162 //{
163 //      typedef LEN                                     value_length;
164 //      struct value_type {unsigned char value[LEN::value/8];};
165 //      typedef value_type const&       param_type;
166 //
167 //};
168
169 /******************************************************************************
170 * Class:                value::traits_c<BITS>
171 * Description:  select min integer type to fit BITS bits
172 * Notes:                N is positive integer value = number of bits
173 ******************************************************************************/
174 template <size_t BITS>
175 struct traits_c : traits<boost::mpl::int_<BITS> >
176 {
177 };
178
179 }       //end:  namespace value
180
181 }       //end:  namespace stdex
182
183 #ifdef _MSC_VER
184 #pragma component( mintypeinfo, off )
185 #endif
186
187 #endif  //_STDEX_VALUE_TRAITS_HPP_INCLUDED_