25 #ifndef INCLUDED_NumberTypeManipulation_h_GUID_D6AC63FF_9257_488B_E06B_0B3FF403E822
26 #define INCLUDED_NumberTypeManipulation_h_GUID_D6AC63FF_9257_488B_E06B_0B3FF403E822
32 #include <boost/mpl/identity.hpp>
33 #include <boost/noncopyable.hpp>
34 #include <boost/type_traits/is_floating_point.hpp>
35 #include <boost/type_traits/is_signed.hpp>
43 class NumberTypeDecompositionFunctor;
64 : m_signed(isTypeSigned), m_sizeof(size), m_float(isTypeFloating) {
75 throw std::logic_error(
76 "Can't describe a numeric type of that size!");
87 size_t getSize()
const {
return m_sizeof; }
92 using boost::mpl::identity;
96 throw std::logic_error(
97 "Can't construct a 1-byte floating point type!");
100 f(identity<int8_t>());
102 f(identity<uint8_t>());
107 throw std::logic_error(
108 "Can't construct a 2-byte floating point type!");
111 f(identity<int16_t>());
113 f(identity<uint16_t>());
118 f(identity<float>());
121 f(identity<int32_t>());
123 f(identity<uint32_t>());
129 f(identity<double>());
132 f(identity<int64_t>());
134 f(identity<uint64_t>());
139 throw std::logic_error(
140 "Can't construct a numeric type of that size!");
148 friend class detail::NumberTypeDecompositionFunctor;
152 class NumberTypeDecompositionFunctor : boost::noncopyable {
154 NumberTypeDecompositionFunctor(NumberTypeData &data)
156 template <
typename WrappedT>
void operator()(WrappedT
const &) {
157 typedef typename WrappedT::type T;
158 m_data.m_sizeof =
sizeof(T);
159 m_data.m_float = boost::is_floating_point<T>::value;
160 m_data.m_signed = boost::is_signed<T>::value;
164 NumberTypeData &m_data;
170 detail::NumberTypeDecompositionFunctor f(d);
171 f(boost::mpl::identity<T>());
177 #endif // INCLUDED_NumberTypeManipulation_h_GUID_D6AC63FF_9257_488B_E06B_0B3FF403E822
void callFunctorWithType(Functor &f)
Calls the user-provided functor with the type described by this runtime data, wrapped in a boost::mpl...
Runtime data on numeric types.
bool isSigned() const
is the type a signed integer?
bool isFloatingPoint() const
is the type a floating-point type?
static NumberTypeData get()
Get runtime data on a given numeric type, passed as the template argument.
Header wrapping the C99 standard stdint header.
The main namespace for all C++ elements of the framework, internal and external.
detail::size< coerce_list< Ts...>> size
Get the size of a list (number of elements.)
NumberTypeData(size_t size, bool isTypeSigned, bool isTypeFloating)
Construct a runtime number type descriptor.
size_t getSize() const
Get the size in bytes of the type.
NumberTypeData()
Default constructor, for an unsigned 1-byte (8 bit) type.