1 /* __gmp_doprnt_integer_ios -- integer formatted output to an ostream. 2 3 THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST 4 CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN 5 FUTURE GNU MP RELEASES. 6 7 Copyright 2001 Free Software Foundation, Inc. 8 9 This file is part of the GNU MP Library. 10 11 The GNU MP Library is free software; you can redistribute it and/or modify 12 it under the terms of the GNU Lesser General Public License as published by 13 the Free Software Foundation; either version 3 of the License, or (at your 14 option) any later version. 15 16 The GNU MP Library is distributed in the hope that it will be useful, but 17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 License for more details. 20 21 You should have received a copy of the GNU Lesser General Public License 22 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ 23 24 #include <iostream> 25 #include <cstdarg> /* for va_list and hence doprnt_funs_t */ 26 #include <cstring> /* for strlen */ 27 28 #include "gmp.h" 29 #include "gmp-impl.h" 30 31 using namespace std; 32 33 34 /* The gmp_asprintf support routines never give an error, so 35 __gmp_doprnt_integer shouldn't fail and it's return can just be checked 36 with an ASSERT. */ 37 38 ostream& 39 __gmp_doprnt_integer_ostream (ostream &o, struct doprnt_params_t *p, 40 char *s) 41 { 42 struct gmp_asprintf_t d; 43 char *result; 44 int ret; 45 46 /* don't show leading zeros the way printf does */ 47 p->prec = -1; 48 49 GMP_ASPRINTF_T_INIT (d, &result); 50 ret = __gmp_doprnt_integer (&__gmp_asprintf_funs_noformat, &d, p, s); 51 ASSERT (ret != -1); 52 __gmp_asprintf_final (&d); 53 (*__gmp_free_func) (s, strlen(s)+1); 54 55 gmp_allocated_string t (result); 56 return o.write (t.str, t.len); 57 } 58