38 #ifndef IE_CORE_HEXCONVERSION_H
39 #define IE_CORE_HEXCONVERSION_H
45 #include "boost/type_traits/is_integral.hpp"
50 template<
typename T,
typename OutputIterator>
51 inline void decToHex( T value, OutputIterator result )
53 BOOST_STATIC_ASSERT( boost::is_integral<T>::value );
54 typedef typename std::iterator_traits<OutputIterator>::value_type CharType;
55 BOOST_STATIC_ASSERT( ( boost::is_same<CharType, char>::value ) );
57 for(
int i =
sizeof( T ) * 2 - 1; i >= 0 ; --i )
59 int m = ( value >> (i * 4) ) & 0xF;
60 *result =
"0123456789ABCDEF"[m];
65 template<
typename InputIterator,
typename OutputIterator>
66 inline void decToHex( InputIterator first, InputIterator last, OutputIterator result )
68 for( ; first!=last; ++first )
70 decToHex( *first, result );
75 template<
typename RandomAccessIterator>
76 inline std::string decToHex( RandomAccessIterator first, RandomAccessIterator last )
78 typedef typename std::iterator_traits<RandomAccessIterator>::value_type ValueType;
79 std::string result; result.resize(
sizeof( ValueType ) * 2 * ( last - first ) );
80 decToHex( first, last, result.begin() );
85 inline std::string decToHex( T n )
87 BOOST_STATIC_ASSERT( boost::is_integral<T>::value );
89 std::string r; r.resize(
sizeof( T ) * 2 );
90 decToHex( n, r.begin() );
95 template<
typename T,
typename InputIterator>
96 inline T hexToDec( InputIterator first, InputIterator last )
98 BOOST_STATIC_ASSERT( boost::is_integral<T>::value );
99 typedef typename std::iterator_traits<InputIterator>::value_type CharType;
100 BOOST_STATIC_ASSERT( ( boost::is_same<CharType, char>::value ) );
104 for( ; first != last; ++first )
173 inline T hexToDec(
const std::string &s )
175 assert( s.size() <=
sizeof( T ) * 2 );
176 return hexToDec<T>( s.begin(), s.end() );
179 template<
typename T,
typename InputIterator,
typename OutputIterator>
180 inline void hexToDec( InputIterator first, InputIterator last, OutputIterator result )
182 typedef typename std::iterator_traits<InputIterator>::value_type CharType;
183 BOOST_STATIC_ASSERT( ( boost::is_same<CharType, char>::value ) );
185 for( ; first != last; first +=
sizeof( T ) * 2 )
187 *result = hexToDec<T>( first, first +
sizeof( T ) * 2 );
194 #endif // IE_CORE_HEXCONVERSION_H
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43