From 5ffe591d55f4a3714927a4f82a525960f68168bf Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 5 Nov 2013 14:28:52 +0000 Subject: [PATCH] Refactor floating point code for num_get::do_get into a template. No functionality change git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@194080 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/locale | 112 ++++++++++--------------------------------------- 1 file changed, 23 insertions(+), 89 deletions(-) diff --git a/include/locale b/include/locale index ab7a7d45..2a1085d7 100644 --- a/include/locale +++ b/include/locale @@ -813,6 +813,11 @@ protected: ios_base::iostate& __err, long double& __v) const; virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const; + + template + iter_type __do_get_floating_point + (iter_type __b, iter_type __e, ios_base& __iob, + ios_base::iostate& __err, _Fp& __v) const; }; template @@ -1234,12 +1239,15 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, return __b; } +// floating point + template +template _InputIterator -num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, +num_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, - float& __v) const + _Fp& __v) const { // Stage 1, nothing to do // Stage 2 @@ -1277,7 +1285,7 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 - __v = __num_get_float(__a, __a_end, __err); + __v = __num_get_float<_Fp>(__a, __a_end, __err); // Digit grouping checked __check_grouping(__grouping, __g, __g_end, __err); // EOF checked @@ -1286,6 +1294,16 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, return __b; } +template +_InputIterator +num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, + ios_base& __iob, + ios_base::iostate& __err, + float& __v) const +{ + return this->__do_get_floating_point(__b, __e, __iob, __err, __v ); +} + template _InputIterator num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, @@ -1293,49 +1311,7 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, ios_base::iostate& __err, double& __v) const { - // Stage 1, nothing to do - // Stage 2 - char_type __atoms[32]; - char_type __decimal_point; - char_type __thousands_sep; - string __grouping = this->__stage2_float_prep(__iob, __atoms, - __decimal_point, - __thousands_sep); - string __buf; - __buf.resize(__buf.capacity()); - char* __a = &__buf[0]; - char* __a_end = __a; - unsigned __g[__num_get_base::__num_get_buf_sz]; - unsigned* __g_end = __g; - unsigned __dc = 0; - bool __in_units = true; - char __exp = 'E'; - for (; __b != __e; ++__b) - { - if (__a_end - __a == __buf.size()) - { - size_t __tmp = __buf.size(); - __buf.resize(2*__buf.size()); - __buf.resize(__buf.capacity()); - __a = &__buf[0]; - __a_end = __a + __tmp; - } - if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, - __decimal_point, __thousands_sep, - __grouping, __g, __g_end, - __dc, __atoms)) - break; - } - if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) - *__g_end++ = __dc; - // Stage 3 - __v = __num_get_float(__a, __a_end, __err); - // Digit grouping checked - __check_grouping(__grouping, __g, __g_end, __err); - // EOF checked - if (__b == __e) - __err |= ios_base::eofbit; - return __b; + return this->__do_get_floating_point(__b, __e, __iob, __err, __v ); } template @@ -1345,49 +1321,7 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, ios_base::iostate& __err, long double& __v) const { - // Stage 1, nothing to do - // Stage 2 - char_type __atoms[32]; - char_type __decimal_point; - char_type __thousands_sep; - string __grouping = this->__stage2_float_prep(__iob, __atoms, - __decimal_point, - __thousands_sep); - string __buf; - __buf.resize(__buf.capacity()); - char* __a = &__buf[0]; - char* __a_end = __a; - unsigned __g[__num_get_base::__num_get_buf_sz]; - unsigned* __g_end = __g; - unsigned __dc = 0; - bool __in_units = true; - char __exp = 'E'; - for (; __b != __e; ++__b) - { - if (__a_end - __a == __buf.size()) - { - size_t __tmp = __buf.size(); - __buf.resize(2*__buf.size()); - __buf.resize(__buf.capacity()); - __a = &__buf[0]; - __a_end = __a + __tmp; - } - if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, - __decimal_point, __thousands_sep, - __grouping, __g, __g_end, - __dc, __atoms)) - break; - } - if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) - *__g_end++ = __dc; - // Stage 3 - __v = __num_get_float(__a, __a_end, __err); - // Digit grouping checked - __check_grouping(__grouping, __g, __g_end, __err); - // EOF checked - if (__b == __e) - __err |= ios_base::eofbit; - return __b; + return this->__do_get_floating_point(__b, __e, __iob, __err, __v ); } template