epoc32/include/tools/stlport/stl/_num_put.c
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
/*
williamr@4
     2
 * Copyright (c) 1999
williamr@4
     3
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     4
 *
williamr@4
     5
 * Copyright (c) 1999
williamr@4
     6
 * Boris Fomitchev
williamr@4
     7
 *
williamr@4
     8
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
     9
 * or implied. Any use is at your own risk.
williamr@4
    10
 *
williamr@4
    11
 * Permission to use or copy this software for any purpose is hereby granted
williamr@4
    12
 * without fee, provided the above notices are retained on all copies.
williamr@4
    13
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    14
 * provided the above notices are retained, and a notice that the code was
williamr@4
    15
 * modified is included with the above copyright notice.
williamr@4
    16
 *
williamr@4
    17
 */
williamr@4
    18
#ifndef _STLP_NUM_PUT_C
williamr@4
    19
#define _STLP_NUM_PUT_C
williamr@4
    20
williamr@4
    21
#ifndef _STLP_INTERNAL_NUM_PUT_H
williamr@4
    22
#  include <stl/_num_put.h>
williamr@4
    23
#endif
williamr@4
    24
williamr@4
    25
#ifndef _STLP_INTERNAL_LIMITS
williamr@4
    26
#  include <stl/_limits.h>
williamr@4
    27
#endif
williamr@4
    28
williamr@4
    29
_STLP_BEGIN_NAMESPACE
williamr@4
    30
williamr@4
    31
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
    32
williamr@4
    33
// __do_put_float and its helper functions.  Strategy: write the output
williamr@4
    34
// to a buffer of char, transform the buffer to _CharT, and then copy
williamr@4
    35
// it to the output.
williamr@4
    36
williamr@4
    37
//----------------------------------------------------------------------
williamr@4
    38
// num_put facet
williamr@4
    39
williamr@4
    40
template <class _CharT, class _OutputIter>
williamr@4
    41
_OutputIter  _STLP_CALL
williamr@4
    42
__copy_float_and_fill(const _CharT* __first, const _CharT* __last,
williamr@4
    43
                      _OutputIter __oi,
williamr@4
    44
                      ios_base::fmtflags __flags,
williamr@4
    45
                      streamsize __width, _CharT __fill,
williamr@4
    46
                      _CharT __xplus, _CharT __xminus) {
williamr@4
    47
  if (__width <= __last - __first)
williamr@4
    48
    return copy(__first, __last, __oi);
williamr@4
    49
  else {
williamr@4
    50
    streamsize __pad = __width - (__last - __first);
williamr@4
    51
    ios_base::fmtflags __dir = __flags & ios_base::adjustfield;
williamr@4
    52
williamr@4
    53
    if (__dir == ios_base::left) {
williamr@4
    54
      __oi = copy(__first, __last, __oi);
williamr@4
    55
      return __fill_n(__oi, __pad, __fill);
williamr@4
    56
    }
williamr@4
    57
    else if (__dir == ios_base::internal && __first != __last &&
williamr@4
    58
             (*__first == __xplus || *__first == __xminus)) {
williamr@4
    59
      *__oi++ = *__first++;
williamr@4
    60
      __oi = __fill_n(__oi, __pad, __fill);
williamr@4
    61
      return copy(__first, __last, __oi);
williamr@4
    62
    }
williamr@4
    63
    else {
williamr@4
    64
      __oi = __fill_n(__oi, __pad, __fill);
williamr@4
    65
      return copy(__first, __last, __oi);
williamr@4
    66
    }
williamr@4
    67
  }
williamr@4
    68
}
williamr@4
    69
williamr@4
    70
#if !defined (_STLP_NO_WCHAR_T)
williamr@4
    71
// Helper routine for wchar_t
williamr@4
    72
template <class _OutputIter>
williamr@4
    73
_OutputIter  _STLP_CALL
williamr@4
    74
__put_float(__iostring &__str, _OutputIter __oi,
williamr@4
    75
            ios_base& __f, wchar_t __fill,
williamr@4
    76
            wchar_t __decimal_point, wchar_t __sep,
williamr@4
    77
            size_t __group_pos, const string& __grouping) {
williamr@4
    78
  const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet());
williamr@4
    79
williamr@4
    80
  __iowstring __wbuf;
williamr@4
    81
  __convert_float_buffer(__str, __wbuf, __ct, __decimal_point);
williamr@4
    82
williamr@4
    83
  if (!__grouping.empty()) {
williamr@4
    84
    __insert_grouping(__wbuf, __group_pos, __grouping,
williamr@4
    85
                      __sep, __ct.widen('+'), __ct.widen('-'), 0);
williamr@4
    86
  }
williamr@4
    87
williamr@4
    88
  return __copy_float_and_fill(__CONST_CAST(wchar_t*, __wbuf.data()),
williamr@4
    89
                               __CONST_CAST(wchar_t*, __wbuf.data()) + __wbuf.size(), __oi,
williamr@4
    90
                               __f.flags(), __f.width(0), __fill, __ct.widen('+'), __ct.widen('-'));
williamr@4
    91
}
williamr@4
    92
#endif /* WCHAR_T */
williamr@4
    93
williamr@4
    94
// Helper routine for char
williamr@4
    95
template <class _OutputIter>
williamr@4
    96
_OutputIter  _STLP_CALL
williamr@4
    97
__put_float(__iostring &__str, _OutputIter __oi,
williamr@4
    98
            ios_base& __f, char __fill,
williamr@4
    99
            char __decimal_point, char __sep,
williamr@4
   100
            size_t __group_pos, const string& __grouping) {
williamr@4
   101
  if ((__group_pos < __str.size()) && (__str[__group_pos] == '.')) {
williamr@4
   102
    __str[__group_pos] = __decimal_point;
williamr@4
   103
  }
williamr@4
   104
williamr@4
   105
  if (!__grouping.empty()) {
williamr@4
   106
    __insert_grouping(__str, __group_pos,
williamr@4
   107
                      __grouping, __sep, '+', '-', 0);
williamr@4
   108
  }
williamr@4
   109
williamr@4
   110
  return __copy_float_and_fill(__CONST_CAST(char*, __str.data()),
williamr@4
   111
                               __CONST_CAST(char*, __str.data()) + __str.size(), __oi,
williamr@4
   112
                               __f.flags(), __f.width(0), __fill, '+', '-');
williamr@4
   113
}
williamr@4
   114
williamr@4
   115
template <class _CharT, class _OutputIter, class _Float>
williamr@4
   116
_OutputIter _STLP_CALL
williamr@4
   117
__do_put_float(_OutputIter __s, ios_base& __f,
williamr@4
   118
                _CharT __fill, _Float __x) {
williamr@4
   119
  __iostring __buf;
williamr@4
   120
williamr@4
   121
  size_t __group_pos = __write_float(__buf, __f.flags(), (int)__f.precision(), __x);
williamr@4
   122
williamr@4
   123
  const numpunct<_CharT>& __np = *__STATIC_CAST(const numpunct<_CharT>*, __f._M_numpunct_facet());
williamr@4
   124
williamr@4
   125
  return __put_float(__buf, __s, __f, __fill,
williamr@4
   126
                     __np.decimal_point(), __np.thousands_sep(),
williamr@4
   127
                     __group_pos, __f._M_grouping());
williamr@4
   128
}
williamr@4
   129
williamr@4
   130
inline void __get_money_digits_aux (__iostring &__buf, ios_base &, _STLP_LONGEST_FLOAT_TYPE __x)
williamr@4
   131
{ __get_floor_digits(__buf, __x); }
williamr@4
   132
williamr@4
   133
#if !defined (_STLP_NO_WCHAR_T)
williamr@4
   134
inline void __get_money_digits_aux (__iowstring &__wbuf, ios_base &__f, _STLP_LONGEST_FLOAT_TYPE __x) {
williamr@4
   135
  __iostring __buf;
williamr@4
   136
  __get_floor_digits(__buf, __x);
williamr@4
   137
williamr@4
   138
  const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet());
williamr@4
   139
  __convert_float_buffer(__buf, __wbuf, __ct, wchar_t(0), false);
williamr@4
   140
}
williamr@4
   141
#endif
williamr@4
   142
williamr@4
   143
template <class _CharT>
williamr@4
   144
void _STLP_CALL __get_money_digits(_STLP_BASIC_IOSTRING(_CharT) &__buf, ios_base& __f, _STLP_LONGEST_FLOAT_TYPE __x)
williamr@4
   145
{ __get_money_digits_aux(__buf, __f, __x); }
williamr@4
   146
williamr@4
   147
// _M_do_put_integer and its helper functions.
williamr@4
   148
williamr@4
   149
template <class _CharT, class _OutputIter>
williamr@4
   150
_OutputIter _STLP_CALL
williamr@4
   151
__copy_integer_and_fill(const _CharT* __buf, ptrdiff_t __len,
williamr@4
   152
                        _OutputIter __oi,
williamr@4
   153
                        ios_base::fmtflags __flg, streamsize __wid, _CharT __fill,
williamr@4
   154
                        _CharT __xplus, _CharT __xminus) {
williamr@4
   155
  if (__len >= __wid)
williamr@4
   156
    return copy(__buf, __buf + __len, __oi);
williamr@4
   157
  else {
williamr@4
   158
    //casting numeric_limits<ptrdiff_t>::max to streamsize only works is ptrdiff_t is signed or streamsize representation
williamr@4
   159
    //is larger than ptrdiff_t one.
williamr@4
   160
    _STLP_STATIC_ASSERT((sizeof(streamsize) > sizeof(ptrdiff_t)) ||
williamr@4
   161
                        (sizeof(streamsize) == sizeof(ptrdiff_t)) && numeric_limits<ptrdiff_t>::is_signed)
williamr@4
   162
    ptrdiff_t __pad = __STATIC_CAST(ptrdiff_t, (min) (__STATIC_CAST(streamsize, (numeric_limits<ptrdiff_t>::max)()),
williamr@4
   163
                                                      __STATIC_CAST(streamsize, __wid - __len)));
williamr@4
   164
    ios_base::fmtflags __dir = __flg & ios_base::adjustfield;
williamr@4
   165
williamr@4
   166
    if (__dir == ios_base::left) {
williamr@4
   167
      __oi = copy(__buf, __buf + __len, __oi);
williamr@4
   168
      return __fill_n(__oi, __pad, __fill);
williamr@4
   169
    }
williamr@4
   170
    else if (__dir == ios_base::internal && __len != 0 &&
williamr@4
   171
             (__buf[0] == __xplus || __buf[0] == __xminus)) {
williamr@4
   172
      *__oi++ = __buf[0];
williamr@4
   173
      __oi = __fill_n(__oi, __pad, __fill);
williamr@4
   174
      return copy(__buf + 1, __buf + __len, __oi);
williamr@4
   175
    }
williamr@4
   176
    else if (__dir == ios_base::internal && __len >= 2  &&
williamr@4
   177
             (__flg & ios_base::showbase) &&
williamr@4
   178
             (__flg & ios_base::basefield) == ios_base::hex) {
williamr@4
   179
      *__oi++ = __buf[0];
williamr@4
   180
      *__oi++ = __buf[1];
williamr@4
   181
      __oi = __fill_n(__oi, __pad, __fill);
williamr@4
   182
      return copy(__buf + 2, __buf + __len, __oi);
williamr@4
   183
    }
williamr@4
   184
    else {
williamr@4
   185
      __oi = __fill_n(__oi, __pad, __fill);
williamr@4
   186
      return copy(__buf, __buf + __len, __oi);
williamr@4
   187
    }
williamr@4
   188
  }
williamr@4
   189
}
williamr@4
   190
williamr@4
   191
#if !defined (_STLP_NO_WCHAR_T)
williamr@4
   192
// Helper function for wchar_t
williamr@4
   193
template <class _OutputIter>
williamr@4
   194
_OutputIter _STLP_CALL
williamr@4
   195
__put_integer(char* __buf, char* __iend, _OutputIter __s,
williamr@4
   196
              ios_base& __f,
williamr@4
   197
              ios_base::fmtflags __flags, wchar_t __fill) {
williamr@4
   198
  locale __loc = __f.getloc();
williamr@4
   199
  //  const ctype<wchar_t>& __ct = use_facet<ctype<wchar_t> >(__loc);
williamr@4
   200
  const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet());
williamr@4
   201
williamr@4
   202
  wchar_t __xplus  = __ct.widen('+');
williamr@4
   203
  wchar_t __xminus = __ct.widen('-');
williamr@4
   204
williamr@4
   205
  wchar_t __wbuf[64];
williamr@4
   206
  __ct.widen(__buf, __iend, __wbuf);
williamr@4
   207
  ptrdiff_t __len = __iend - __buf;
williamr@4
   208
  wchar_t* __eend = __wbuf + __len;
williamr@4
   209
williamr@4
   210
  //  const numpunct<wchar_t>& __np = use_facet<numpunct<wchar_t> >(__loc);
williamr@4
   211
  //  const string& __grouping = __np.grouping();
williamr@4
   212
williamr@4
   213
  const numpunct<wchar_t>& __np = *__STATIC_CAST(const numpunct<wchar_t>*, __f._M_numpunct_facet());
williamr@4
   214
  const string& __grouping = __f._M_grouping();
williamr@4
   215
williamr@4
   216
  if (!__grouping.empty()) {
williamr@4
   217
    int __basechars;
williamr@4
   218
    if (__flags & ios_base::showbase)
williamr@4
   219
      switch (__flags & ios_base::basefield) {
williamr@4
   220
        case ios_base::hex: __basechars = 2; break;
williamr@4
   221
        case ios_base::oct: __basechars = 1; break;
williamr@4
   222
        default: __basechars = 0;
williamr@4
   223
      }
williamr@4
   224
    else
williamr@4
   225
      __basechars = 0;
williamr@4
   226
williamr@4
   227
    __len = __insert_grouping(__wbuf, __eend, __grouping, __np.thousands_sep(),
williamr@4
   228
                              __xplus, __xminus, __basechars);
williamr@4
   229
  }
williamr@4
   230
williamr@4
   231
  return __copy_integer_and_fill((wchar_t*)__wbuf, __len, __s,
williamr@4
   232
                                 __flags, __f.width(0), __fill, __xplus, __xminus);
williamr@4
   233
}
williamr@4
   234
#endif
williamr@4
   235
williamr@4
   236
// Helper function for char
williamr@4
   237
template <class _OutputIter>
williamr@4
   238
_OutputIter _STLP_CALL
williamr@4
   239
__put_integer(char* __buf, char* __iend, _OutputIter __s,
williamr@4
   240
              ios_base& __f, ios_base::fmtflags __flags, char __fill) {
williamr@4
   241
  char __grpbuf[64];
williamr@4
   242
  ptrdiff_t __len = __iend - __buf;
williamr@4
   243
williamr@4
   244
  //  const numpunct<char>& __np = use_facet<numpunct<char> >(__f.getloc());
williamr@4
   245
  //  const string& __grouping = __np.grouping();
williamr@4
   246
williamr@4
   247
  const numpunct<char>& __np = *__STATIC_CAST(const numpunct<char>*, __f._M_numpunct_facet());
williamr@4
   248
  const string& __grouping = __f._M_grouping();
williamr@4
   249
williamr@4
   250
  if (!__grouping.empty()) {
williamr@4
   251
    int __basechars;
williamr@4
   252
    if (__flags & ios_base::showbase)
williamr@4
   253
      switch (__flags & ios_base::basefield) {
williamr@4
   254
        case ios_base::hex: __basechars = 2; break;
williamr@4
   255
        case ios_base::oct: __basechars = 1; break;
williamr@4
   256
        default: __basechars = 0;
williamr@4
   257
      }
williamr@4
   258
    else
williamr@4
   259
      __basechars = 0;
williamr@4
   260
williamr@4
   261
     // make sure there is room at the end of the buffer
williamr@4
   262
     // we pass to __insert_grouping
williamr@4
   263
    copy(__buf, __iend, (char *) __grpbuf);
williamr@4
   264
    __buf = __grpbuf;
williamr@4
   265
    __iend = __grpbuf + __len;
williamr@4
   266
    __len = __insert_grouping(__buf, __iend, __grouping, __np.thousands_sep(),
williamr@4
   267
                              '+', '-', __basechars);
williamr@4
   268
  }
williamr@4
   269
williamr@4
   270
  return __copy_integer_and_fill(__buf, __len, __s, __flags, __f.width(0), __fill, '+', '-');
williamr@4
   271
}
williamr@4
   272
williamr@4
   273
#if defined (_STLP_LONG_LONG)
williamr@4
   274
typedef _STLP_LONG_LONG __max_int_t;
williamr@4
   275
typedef unsigned _STLP_LONG_LONG __umax_int_t;
williamr@4
   276
#else
williamr@4
   277
typedef long __max_int_t;
williamr@4
   278
typedef unsigned long __umax_int_t;
williamr@4
   279
#endif
williamr@4
   280
williamr@4
   281
_STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo();
williamr@4
   282
_STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi();
williamr@4
   283
williamr@4
   284
template <class _Integer>
williamr@4
   285
inline char* _STLP_CALL
williamr@4
   286
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __true_type& /* is_signed */) {
williamr@4
   287
  const bool __negative = __x < 0 ;
williamr@4
   288
  __max_int_t __temp = __x;
williamr@4
   289
  __umax_int_t __utemp = __negative?-__temp:__temp;
williamr@4
   290
williamr@4
   291
  for (; __utemp != 0; __utemp /= 10)
williamr@4
   292
    *--__ptr = (char)((int)(__utemp % 10) + '0');
williamr@4
   293
  // put sign if needed or requested
williamr@4
   294
  if (__negative)
williamr@4
   295
    *--__ptr = '-';
williamr@4
   296
  else if (__flags & ios_base::showpos)
williamr@4
   297
    *--__ptr = '+';
williamr@4
   298
  return __ptr;
williamr@4
   299
}
williamr@4
   300
williamr@4
   301
template <class _Integer>
williamr@4
   302
inline char* _STLP_CALL
williamr@4
   303
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __false_type& /* is_signed */) {
williamr@4
   304
  for (; __x != 0; __x /= 10)
williamr@4
   305
    *--__ptr = (char)((int)(__x % 10) + '0');
williamr@4
   306
  // put sign if requested
williamr@4
   307
  if (__flags & ios_base::showpos)
williamr@4
   308
    *--__ptr = '+';
williamr@4
   309
  return __ptr;
williamr@4
   310
}
williamr@4
   311
williamr@4
   312
template <class _Integer>
williamr@4
   313
char* _STLP_CALL
williamr@4
   314
__write_integer_backward(char* __buf, ios_base::fmtflags __flags, _Integer __x) {
williamr@4
   315
  char* __ptr = __buf;
williamr@4
   316
williamr@4
   317
  if (__x == 0) {
williamr@4
   318
    *--__ptr = '0';
williamr@4
   319
    if ((__flags & ios_base::showpos) && ((__flags & (ios_base::oct | ios_base::hex)) == 0))
williamr@4
   320
      *--__ptr = '+';
williamr@4
   321
    // oct or hex base shall not be added to the 0 value (see '#' flag in C formating strings)
williamr@4
   322
  }
williamr@4
   323
  else {
williamr@4
   324
    switch (__flags & ios_base::basefield) {
williamr@4
   325
      case ios_base::oct:
williamr@4
   326
        {
williamr@4
   327
          __umax_int_t __temp = __x;
williamr@4
   328
          // if the size of integer is less than 8, clear upper part
williamr@4
   329
          if ( sizeof(__x) < 8  && sizeof(__umax_int_t) >= 8 )
williamr@4
   330
            __temp &= 0xFFFFFFFF;
williamr@4
   331
williamr@4
   332
          for (; __temp != 0; __temp >>=3)
williamr@4
   333
            *--__ptr = (char)((((unsigned)__temp)& 0x7) + '0');
williamr@4
   334
williamr@4
   335
          // put leading '0' if showbase is set
williamr@4
   336
          if (__flags & ios_base::showbase)
williamr@4
   337
            *--__ptr = '0';
williamr@4
   338
        }
williamr@4
   339
        break;
williamr@4
   340
      case ios_base::hex:
williamr@4
   341
        {
williamr@4
   342
          const char* __table_ptr = (__flags & ios_base::uppercase) ?
williamr@4
   343
            __hex_char_table_hi() : __hex_char_table_lo();
williamr@4
   344
          __umax_int_t __temp = __x;
williamr@4
   345
          // if the size of integer is less than 8, clear upper part
williamr@4
   346
          if ( sizeof(__x) < 8  && sizeof(__umax_int_t) >= 8 )
williamr@4
   347
            __temp &= 0xFFFFFFFF;
williamr@4
   348
williamr@4
   349
          for (; __temp != 0; __temp >>=4)
williamr@4
   350
            *--__ptr = __table_ptr[((unsigned)__temp & 0xF)];
williamr@4
   351
williamr@4
   352
          if (__flags & ios_base::showbase) {
williamr@4
   353
            *--__ptr = __table_ptr[16];
williamr@4
   354
            *--__ptr = '0';
williamr@4
   355
          }
williamr@4
   356
        }
williamr@4
   357
        break;
williamr@4
   358
      //case ios_base::dec:
williamr@4
   359
      default:
williamr@4
   360
        {
williamr@4
   361
#if defined(__HP_aCC) && (__HP_aCC == 1)
williamr@4
   362
          bool _IsSigned = !((_Integer)-1 > 0);
williamr@4
   363
          if (_IsSigned)
williamr@4
   364
            __ptr = __write_decimal_backward(__ptr, __x, __flags, __true_type() );
williamr@4
   365
          else
williamr@4
   366
            __ptr = __write_decimal_backward(__ptr, __x, __flags, __false_type() );
williamr@4
   367
#else
williamr@4
   368
          typedef typename __bool2type<numeric_limits<_Integer>::is_signed>::_Ret _IsSigned;
williamr@4
   369
          __ptr = __write_decimal_backward(__ptr, __x, __flags, _IsSigned());
williamr@4
   370
#endif
williamr@4
   371
        }
williamr@4
   372
        break;
williamr@4
   373
    }
williamr@4
   374
  }
williamr@4
   375
williamr@4
   376
  // return pointer to beginning of the string
williamr@4
   377
  return __ptr;
williamr@4
   378
}
williamr@4
   379
williamr@4
   380
template <class _CharT, class _OutputIter, class _Integer>
williamr@4
   381
_OutputIter _STLP_CALL
williamr@4
   382
__do_put_integer(_OutputIter __s, ios_base& __f, _CharT __fill, _Integer __x) {
williamr@4
   383
  // buffer size = number of bytes * number of digit necessary in the smallest Standard base (base 8, 3 digits/byte)
williamr@4
   384
  //               plus the longest base representation '0x'
williamr@4
   385
  // Do not use __buf_size to define __buf static buffer, some compilers (HP aCC) do not accept const variable as
williamr@4
   386
  // the specification of a static buffer size.
williamr@4
   387
  char __buf[sizeof(_Integer) * 3 + 2];
williamr@4
   388
  const ptrdiff_t __buf_size = sizeof(__buf) / sizeof(char);
williamr@4
   389
  ios_base::fmtflags __flags = __f.flags();
williamr@4
   390
  char* __ibeg = __write_integer_backward((char*)__buf+__buf_size, __flags, __x);
williamr@4
   391
  return __put_integer(__ibeg, (char*)__buf+__buf_size, __s, __f, __flags, __fill);
williamr@4
   392
}
williamr@4
   393
williamr@4
   394
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   395
williamr@4
   396
//
williamr@4
   397
// num_put<>
williamr@4
   398
//
williamr@4
   399
williamr@4
   400
#if (_STLP_STATIC_TEMPLATE_DATA > 0)
williamr@4
   401
williamr@4
   402
#  if !defined (__BORLANDC__)
williamr@4
   403
template <class _CharT, class _OutputIterator>
williamr@4
   404
locale::id num_put<_CharT, _OutputIterator>::id;
williamr@4
   405
#  endif
williamr@4
   406
williamr@4
   407
#  if (defined (__CYGWIN__) || defined (__MINGW32__)) && \
williamr@4
   408
       defined (_STLP_USE_DYNAMIC_LIB) && !defined (__BUILDING_STLPORT)
williamr@4
   409
/*
williamr@4
   410
 * Under cygwin, when STLport is used as a shared library, the id needs
williamr@4
   411
 * to be specified as imported otherwise they will be duplicated in the
williamr@4
   412
 * calling executable.
williamr@4
   413
 */
williamr@4
   414
template <>
williamr@4
   415
_STLP_DECLSPEC locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
williamr@4
   416
/*
williamr@4
   417
template <>
williamr@4
   418
_STLP_DECLSPEC locale::id num_put<char, char*>::id;
williamr@4
   419
*/
williamr@4
   420
williamr@4
   421
#    if !defined (_STLP_NO_WCHAR_T)
williamr@4
   422
template <>
williamr@4
   423
_STLP_DECLSPEC locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
williamr@4
   424
/*
williamr@4
   425
template <>
williamr@4
   426
_STLP_DECLSPEC locale::id num_put<wchar_t, wchar_t*>::id;
williamr@4
   427
*/
williamr@4
   428
#    endif
williamr@4
   429
williamr@4
   430
#  endif /* __CYGWIN__ && _STLP_USE_DYNAMIC_LIB */
williamr@4
   431
williamr@4
   432
#else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
williamr@4
   433
williamr@4
   434
//typedef num_put<char, char*> num_put_char;
williamr@4
   435
typedef num_put<char, ostreambuf_iterator<char, char_traits<char> > > num_put_char_2;
williamr@4
   436
williamr@4
   437
//__DECLARE_INSTANCE(locale::id, num_put_char::id, );
williamr@4
   438
__DECLARE_INSTANCE(locale::id, num_put_char_2::id, );
williamr@4
   439
williamr@4
   440
#  if !defined (_STLP_NO_WCHAR_T)
williamr@4
   441
williamr@4
   442
//typedef num_put<wchar_t, wchar_t*> num_put_wchar_t;
williamr@4
   443
typedef num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > num_put_wchar_t_2;
williamr@4
   444
williamr@4
   445
//__DECLARE_INSTANCE(locale::id, num_put_wchar_t::id, );
williamr@4
   446
__DECLARE_INSTANCE(locale::id, num_put_wchar_t_2::id, );
williamr@4
   447
williamr@4
   448
#  endif
williamr@4
   449
williamr@4
   450
#endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
williamr@4
   451
williamr@4
   452
// issue 118
williamr@4
   453
williamr@4
   454
#if !defined (_STLP_NO_BOOL)
williamr@4
   455
template <class _CharT, class _OutputIter>
williamr@4
   456
_OutputIter
williamr@4
   457
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f,
williamr@4
   458
                                     char_type __fill,  bool __val) const {
williamr@4
   459
  if (!(__f.flags() & ios_base::boolalpha))
williamr@4
   460
    return this->do_put(__s, __f, __fill, __STATIC_CAST(long,__val));
williamr@4
   461
williamr@4
   462
  locale __loc = __f.getloc();
williamr@4
   463
  //  typedef numpunct<_CharT> _Punct;
williamr@4
   464
  //  const _Punct& __np = use_facet<_Punct>(__loc);
williamr@4
   465
williamr@4
   466
  const numpunct<_CharT>& __np = *__STATIC_CAST(const numpunct<_CharT>*, __f._M_numpunct_facet());
williamr@4
   467
williamr@4
   468
  basic_string<_CharT> __str = __val ? __np.truename() : __np.falsename();
williamr@4
   469
williamr@4
   470
  // Reuse __copy_integer_and_fill.  Since internal padding makes no
williamr@4
   471
  // sense for bool, though, make sure we use something else instead.
williamr@4
   472
  // The last two argument to __copy_integer_and_fill are dummies.
williamr@4
   473
  ios_base::fmtflags __flags = __f.flags();
williamr@4
   474
  if ((__flags & ios_base::adjustfield) == ios_base::internal)
williamr@4
   475
    __flags = (__flags & ~ios_base::adjustfield) | ios_base::right;
williamr@4
   476
williamr@4
   477
  return _STLP_PRIV __copy_integer_and_fill(__str.c_str(), __str.size(), __s,
williamr@4
   478
                                            __flags, __f.width(0), __fill,
williamr@4
   479
                                            (_CharT) 0, (_CharT) 0);
williamr@4
   480
}
williamr@4
   481
williamr@4
   482
#endif
williamr@4
   483
williamr@4
   484
template <class _CharT, class _OutputIter>
williamr@4
   485
_OutputIter
williamr@4
   486
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   487
                                     long __val) const
williamr@4
   488
{ return _STLP_PRIV __do_put_integer(__s, __f, __fill, __val); }
williamr@4
   489
williamr@4
   490
template <class _CharT, class _OutputIter>
williamr@4
   491
_OutputIter
williamr@4
   492
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   493
                                     unsigned long __val) const
williamr@4
   494
{ return _STLP_PRIV __do_put_integer(__s, __f, __fill, __val); }
williamr@4
   495
williamr@4
   496
template <class _CharT, class _OutputIter>
williamr@4
   497
_OutputIter
williamr@4
   498
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   499
                                     double __val) const
williamr@4
   500
{ return _STLP_PRIV __do_put_float(__s, __f, __fill, __val); }
williamr@4
   501
williamr@4
   502
#if !defined (_STLP_NO_LONG_DOUBLE)
williamr@4
   503
template <class _CharT, class _OutputIter>
williamr@4
   504
_OutputIter
williamr@4
   505
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   506
                                     long double __val) const
williamr@4
   507
{ return _STLP_PRIV __do_put_float(__s, __f, __fill, __val); }
williamr@4
   508
#endif
williamr@4
   509
williamr@4
   510
#if defined (_STLP_LONG_LONG)
williamr@4
   511
template <class _CharT, class _OutputIter>
williamr@4
   512
_OutputIter
williamr@4
   513
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   514
                                     _STLP_LONG_LONG __val) const
williamr@4
   515
{ return _STLP_PRIV __do_put_integer(__s, __f, __fill, __val); }
williamr@4
   516
williamr@4
   517
template <class _CharT, class _OutputIter>
williamr@4
   518
_OutputIter
williamr@4
   519
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   520
                                     unsigned _STLP_LONG_LONG __val) const
williamr@4
   521
{ return _STLP_PRIV __do_put_integer(__s, __f, __fill, __val); }
williamr@4
   522
#endif /* _STLP_LONG_LONG */
williamr@4
   523
williamr@4
   524
williamr@4
   525
// lib.facet.num.put.virtuals "12 For conversion from void* the specifier is %p."
williamr@4
   526
template <class _CharT, class _OutputIter>
williamr@4
   527
_OutputIter
williamr@4
   528
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT /*__fill*/,
williamr@4
   529
                                     const void* __val) const {
williamr@4
   530
  const ctype<_CharT>& __c_type = *__STATIC_CAST(const ctype<_CharT>*, __f._M_ctype_facet());
williamr@4
   531
  ios_base::fmtflags __save_flags = __f.flags();
williamr@4
   532
williamr@4
   533
  __f.setf(ios_base::hex, ios_base::basefield);
williamr@4
   534
  __f.setf(ios_base::showbase);
williamr@4
   535
  __f.setf(ios_base::internal, ios_base::adjustfield);
williamr@4
   536
  __f.width((sizeof(void*) * 2) + 2); // digits in pointer type plus '0x' prefix
williamr@4
   537
# if defined(_STLP_LONG_LONG) && !defined(__MRC__) //*ty 11/24/2001 - MrCpp can not cast from void* to long long
williamr@4
   538
  _OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned _STLP_LONG_LONG,__val));
williamr@4
   539
# else
williamr@4
   540
  _OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned long,__val));
williamr@4
   541
# endif
williamr@4
   542
  __f.flags(__save_flags);
williamr@4
   543
  return result;
williamr@4
   544
}
williamr@4
   545
williamr@4
   546
_STLP_END_NAMESPACE
williamr@4
   547
williamr@4
   548
#endif /* _STLP_NUM_PUT_C */
williamr@4
   549
williamr@4
   550
// Local Variables:
williamr@4
   551
// mode:C++
williamr@4
   552
// End: