Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2013-11-05 18:28:52 +0400
committerMarshall Clow <mclow.lists@gmail.com>2013-11-05 18:28:52 +0400
commit9d66b72aa919f0dcec3826c65048a449db921ab4 (patch)
tree03625f05165a12d1a03d0d93e0349d78b0059786 /libcxx/include/locale
parent5252325990958fcd6680cf45e81f9d9e3004473b (diff)
Refactor floating point code for num_get::do_get into a template. No functionality change
llvm-svn: 194080
Diffstat (limited to 'libcxx/include/locale')
-rw-r--r--libcxx/include/locale112
1 files changed, 23 insertions, 89 deletions
diff --git a/libcxx/include/locale b/libcxx/include/locale
index ab7a7d45a5c8..2a1085d72686 100644
--- a/libcxx/include/locale
+++ b/libcxx/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 <class _Fp>
+ iter_type __do_get_floating_point
+ (iter_type __b, iter_type __e, ios_base& __iob,
+ ios_base::iostate& __err, _Fp& __v) const;
};
template <class _CharT, class _InputIterator>
@@ -1234,12 +1239,15 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
return __b;
}
+// floating point
+
template <class _CharT, class _InputIterator>
+template <class _Fp>
_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<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
@@ -1291,51 +1299,19 @@ _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 <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+ ios_base& __iob,
+ 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<double>(__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 <class _CharT, class _InputIterator>
@@ -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<long double>(__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 <class _CharT, class _InputIterator>