github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/cxx/osfuns.cc (about)

     1  /* Support for operator<< routines.
     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 either:
    13  
    14    * the GNU Lesser General Public License as published by the Free
    15      Software Foundation; either version 3 of the License, or (at your
    16      option) any later version.
    17  
    18  or
    19  
    20    * the GNU General Public License as published by the Free Software
    21      Foundation; either version 2 of the License, or (at your option) any
    22      later version.
    23  
    24  or both in parallel, as here.
    25  
    26  The GNU MP Library is distributed in the hope that it will be useful, but
    27  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    28  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    29  for more details.
    30  
    31  You should have received copies of the GNU General Public License and the
    32  GNU Lesser General Public License along with the GNU MP Library.  If not,
    33  see https://www.gnu.org/licenses/.  */
    34  
    35  #include <iostream>
    36  #include <stdarg.h>    /* for va_list and hence doprnt_funs_t */
    37  #include <string.h>
    38  
    39  #include "gmp.h"
    40  #include "gmp-impl.h"
    41  
    42  using namespace std;
    43  
    44  
    45  /* Don't need "format" for operator<< routines, just "memory" and "reps".
    46     Omitting gmp_asprintf_format lets us avoid dragging vsnprintf into the
    47     link.  __gmp_asprintf_final will be called directly and doesn't need to
    48     be in the struct.  */
    49  
    50  const struct doprnt_funs_t  __gmp_asprintf_funs_noformat = {
    51    NULL,
    52    (doprnt_memory_t) __gmp_asprintf_memory,
    53    (doprnt_reps_t)   __gmp_asprintf_reps,
    54    NULL
    55  };
    56  
    57  
    58  void
    59  __gmp_doprnt_params_from_ios (struct doprnt_params_t *p, ios &o)
    60  {
    61    if ((o.flags() & ios::basefield) == ios::hex)
    62      {
    63        p->expfmt = "@%c%02d";
    64        p->base = (o.flags() & ios::uppercase ? -16 : 16);
    65      }
    66    else
    67      {
    68        p->expfmt = (o.flags() & ios::uppercase ? "E%c%02d" : "e%c%02d");
    69        if ((o.flags() & ios::basefield) == ios::oct)
    70          p->base = 8;
    71        else
    72          p->base = 10;
    73      }
    74  
    75    /* "general" if none or more than one bit set */
    76    if ((o.flags() & ios::floatfield) == ios::fixed)
    77      p->conv = DOPRNT_CONV_FIXED;
    78    else if ((o.flags() & ios::floatfield) == ios::scientific)
    79      p->conv = DOPRNT_CONV_SCIENTIFIC;
    80    else
    81      p->conv = DOPRNT_CONV_GENERAL;
    82  
    83    p->exptimes4 = 0;
    84  
    85    p->fill = o.fill();
    86  
    87    /* "right" if more than one bit set */
    88    if ((o.flags() & ios::adjustfield) == ios::left)
    89      p->justify = DOPRNT_JUSTIFY_LEFT;
    90    else if ((o.flags() & ios::adjustfield) == ios::internal)
    91      p->justify = DOPRNT_JUSTIFY_INTERNAL;
    92    else
    93      p->justify = DOPRNT_JUSTIFY_RIGHT;
    94  
    95    /* ios::fixed allows prec==0, others take 0 as the default 6.
    96       Don't allow negatives (they do bad things to __gmp_doprnt_float_cxx).  */
    97    p->prec = MAX (0, o.precision());
    98    if (p->prec == 0 && p->conv != DOPRNT_CONV_FIXED)
    99      p->prec = 6;
   100  
   101    /* for hex showbase is always, for octal only non-zero */
   102    if (o.flags() & ios::showbase)
   103      p->showbase = ((o.flags() & ios::basefield) == ios::hex
   104                     ? DOPRNT_SHOWBASE_YES : DOPRNT_SHOWBASE_NONZERO);
   105    else
   106      p->showbase = DOPRNT_SHOWBASE_NO;
   107  
   108    p->showpoint = ((o.flags() & ios::showpoint) != 0);
   109  
   110    /* in fixed and scientific always show trailing zeros, in general format
   111       show them if showpoint is set (or so it seems) */
   112    if ((o.flags() & ios::floatfield) == ios::fixed
   113        || (o.flags() & ios::floatfield) == ios::scientific)
   114      p->showtrailing = 1;
   115    else
   116      p->showtrailing = p->showpoint;
   117  
   118    p->sign = (o.flags() & ios::showpos ? '+' : '\0');
   119  
   120    p->width = o.width();
   121  
   122    /* reset on each output */
   123    o.width (0);
   124  }