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;
95 if (isFloatingPoint()) {
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>());
106 if (isFloatingPoint()) {
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>());
117 if (isFloatingPoint()) {
118 f(identity<float>());
121 f(identity<int32_t>());
123 f(identity<uint32_t>());
128 if (isFloatingPoint()) {
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!");
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;
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...
Definition: NumberTypeManipulation.h:91
bool isFloatingPoint() const
is the type a floating-point type?
Definition: NumberTypeManipulation.h:84
Definition: NonLinearOptimization.cpp:107
Definition: RunLoopManager.h:42
Runtime data on numeric types.
Definition: NumberTypeManipulation.h:47
bool isSigned() const
is the type a signed integer?
Definition: NumberTypeManipulation.h:81
static NumberTypeData get()
Get runtime data on a given numeric type, passed as the template argument.
Definition: NumberTypeManipulation.h:168
Header wrapping the C99 standard stdint header.
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
Definition: newuoa.h:1888
NumberTypeData(size_t size, bool isTypeSigned, bool isTypeFloating)
Construct a runtime number type descriptor.
Definition: NumberTypeManipulation.h:63
NumberTypeData()
Default constructor, for an unsigned 1-byte (8 bit) type.
Definition: NumberTypeManipulation.h:54
Definition: NumberTypeManipulation.h:152
size_t getSize() const
Get the size in bytes of the type.
Definition: NumberTypeManipulation.h:87