1 #ifndef _STDEX_VALUE_TRAITS_HPP_INCLUDED_
2 #define _STDEX_VALUE_TRAITS_HPP_INCLUDED_
4 /******************************************************************************
6 * Copyright (c) 2019 AT&T Intellectual Property.
7 * Copyright (c) 2018-2019 Nokia.
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 ******************************************************************************/
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>
29 #include "type_defs.h"
34 namespace mpl = boost::mpl;
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;
46 template<int num_bits>
47 struct bits_to_bytes : mpl::int_< (num_bits + 7) / 8 > {};
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;
57 struct traits<LEN, typename boost::enable_if<
58 mpl::less_equal<LEN, _8>
62 typedef _8 value_length;
63 typedef u8 value_type;
64 typedef value_type param_type;
68 struct traits<LEN, typename boost::enable_if<
69 mpl::and_<mpl::greater<LEN, _8>, mpl::less_equal<LEN, _16> >
73 typedef _16 value_length;
74 typedef u16 value_type;
75 typedef value_type param_type;
79 struct traits<LEN, typename boost::enable_if<
80 mpl::and_<mpl::greater<LEN, _16>, mpl::less_equal<LEN, _24> >
84 typedef _24 value_length;
85 typedef u32 value_type;
86 typedef value_type param_type;
90 struct traits<LEN, typename boost::enable_if<
91 mpl::and_<mpl::greater<LEN, _24>, mpl::less_equal<LEN, _32> >
95 typedef _32 value_length;
96 typedef u32 value_type;
97 typedef value_type param_type;
101 struct traits<LEN, typename boost::enable_if<
102 mpl::and_<mpl::greater<LEN, _32>, mpl::less_equal<LEN, _40> >
106 typedef _40 value_length;
107 typedef u64 value_type;
108 typedef value_type param_type;
112 struct traits<LEN, typename boost::enable_if<
113 mpl::and_<mpl::greater<LEN, _40>, mpl::less_equal<LEN, _48> >
117 typedef _48 value_length;
118 typedef u64 value_type;
119 typedef value_type param_type;
123 struct traits<LEN, typename boost::enable_if<
124 mpl::and_<mpl::greater<LEN, _48>, mpl::less_equal<LEN, _56> >
128 typedef _56 value_length;
129 typedef u64 value_type;
130 typedef value_type param_type;
134 struct traits<LEN, typename boost::enable_if<
135 mpl::and_<mpl::greater<LEN, _56>, mpl::less_equal<LEN, _64> >
139 typedef _64 value_length;
140 typedef u64 value_type;
141 typedef value_type param_type;
145 struct traits<LEN, typename boost::enable_if<
146 mpl::greater<LEN, _64>
150 typedef LEN value_length;
151 struct value_type {u8 value[bits_to_bytes<LEN::value>::value];};
152 typedef value_type const& param_type;
156 //template <class LEN>
158 // typename boost::enable_if<
159 // mpl::greater<LEN, _32>
163 // typedef LEN value_length;
164 // struct value_type {unsigned char value[LEN::value/8];};
165 // typedef value_type const& param_type;
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> >
179 } //end: namespace value
181 } //end: namespace stdex
184 #pragma component( mintypeinfo, off )
187 #endif //_STDEX_VALUE_TRAITS_HPP_INCLUDED_