Upload Tizen:Base source
[external/gmp.git] / cxx / osmpf.cc
1 /* operator<< -- mpf formatted output to an ostream.
2
3 Copyright 2001, 2002 Free Software Foundation, Inc.
4
5 This file is part of the GNU MP Library.
6
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
19
20 #include <clocale>
21 #include <iostream>
22 #include <stdarg.h>    /* for va_list and hence doprnt_funs_t */
23 #include <string.h>
24
25 #include "gmp.h"
26 #include "gmp-impl.h"
27
28 using namespace std;
29
30
31 /* The gmp_asprintf support routines never give an error, so
32    __gmp_doprnt_mpf shouldn't fail and it's return can just be checked with
33    an ASSERT.  */
34
35 ostream&
36 operator<< (ostream &o, mpf_srcptr f)
37 {
38   struct doprnt_params_t  param;
39   struct gmp_asprintf_t   d;
40   char  *result;
41   int   ret;
42
43   __gmp_doprnt_params_from_ios (&param, o);
44
45 #if HAVE_STD__LOCALE
46   char  point[2];
47   point[0] = use_facet< numpunct<char> >(o.getloc()).decimal_point();
48   point[1] = '\0';
49 #else
50   const char *point = localeconv()->decimal_point;
51 #endif
52
53   GMP_ASPRINTF_T_INIT (d, &result);
54   ret = __gmp_doprnt_mpf (&__gmp_asprintf_funs_noformat, &d, &param, point, f);
55   ASSERT (ret != -1);
56   __gmp_asprintf_final (&d);
57
58   gmp_allocated_string  t (result);
59   return o.write (t.str, t.len);
60 }