epoc32/include/stdapis/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
 * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
williamr@4
     3
 *
williamr@4
     4
 * Copyright (c) 1999
williamr@4
     5
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     6
 *
williamr@4
     7
 * Copyright (c) 1999 
williamr@4
     8
 * Boris Fomitchev
williamr@4
     9
 *
williamr@4
    10
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
    11
 * or implied. Any use is at your own risk.
williamr@4
    12
 *
williamr@4
    13
 * Permission to use or copy this software for any purpose is hereby granted 
williamr@4
    14
 * without fee, provided the above notices are retained on all copies.
williamr@4
    15
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    16
 * provided the above notices are retained, and a notice that the code was
williamr@4
    17
 * modified is included with the above copyright notice.
williamr@4
    18
 *
williamr@4
    19
 */ 
williamr@4
    20
#ifndef _STLP_NUM_PUT_C
williamr@4
    21
#define _STLP_NUM_PUT_C
williamr@4
    22
williamr@4
    23
#ifndef _STLP_INTERNAL_NUM_PUT_H
williamr@4
    24
# include <stl/_num_put.h>
williamr@4
    25
#endif
williamr@4
    26
williamr@4
    27
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
williamr@4
    28
williamr@4
    29
#ifndef _STLP_LIMITS_H
williamr@4
    30
# include <stl/_limits.h>
williamr@4
    31
#endif
williamr@4
    32
williamr@4
    33
_STLP_BEGIN_NAMESPACE
williamr@4
    34
williamr@4
    35
// _M_do_put_float and its helper functions.  Strategy: write the output
williamr@4
    36
// to a buffer of char, transform the buffer to _CharT, and then copy
williamr@4
    37
// it to the output.
williamr@4
    38
williamr@4
    39
template <class _CharT, class _OutputIter,class _Float>
williamr@4
    40
_OutputIter _STLP_CALL
williamr@4
    41
_M_do_put_float(_OutputIter __s, ios_base& __f, _CharT __fill,_Float    __x);
williamr@4
    42
williamr@4
    43
williamr@4
    44
//----------------------------------------------------------------------
williamr@4
    45
// num_put facet
williamr@4
    46
williamr@4
    47
template <class _CharT, class _OutputIter>
williamr@4
    48
_OutputIter  _STLP_CALL
williamr@4
    49
__copy_float_and_fill(const _CharT* __first, const _CharT* __last,
williamr@4
    50
                      _OutputIter __stl_out,
williamr@4
    51
                      ios_base::fmtflags __flags,
williamr@4
    52
                      streamsize __width, _CharT __fill,
williamr@4
    53
                      _CharT __xplus, _CharT __xminus) {
williamr@4
    54
  if (__width <= __last - __first)
williamr@4
    55
    return copy(__first, __last, __stl_out);
williamr@4
    56
  else {
williamr@4
    57
    streamsize __pad = __width - (__last - __first);
williamr@4
    58
    ios_base::fmtflags __dir = __flags & ios_base::adjustfield;
williamr@4
    59
williamr@4
    60
    if (__dir == ios_base::left) {
williamr@4
    61
      __stl_out = copy(__first, __last, __stl_out);
williamr@4
    62
      return fill_n(__stl_out, __pad, __fill);
williamr@4
    63
    }
williamr@4
    64
    else if (__dir == ios_base::internal && __first != __last &&
williamr@4
    65
             (*__first == __xplus || *__first == __xminus)) {
williamr@4
    66
      *__stl_out++ = *__first++;
williamr@4
    67
      __stl_out = fill_n(__stl_out, __pad, __fill);
williamr@4
    68
      return copy(__first, __last, __stl_out);
williamr@4
    69
    }
williamr@4
    70
    else {
williamr@4
    71
      __stl_out = fill_n(__stl_out, __pad, __fill);
williamr@4
    72
      return copy(__first, __last, __stl_out);
williamr@4
    73
    }
williamr@4
    74
  }
williamr@4
    75
}
williamr@4
    76
williamr@4
    77
#ifndef _STLP_NO_WCHAR_T
williamr@4
    78
// Helper routine for wchar_t
williamr@4
    79
template <class _OutputIter>
williamr@4
    80
_OutputIter  _STLP_CALL
williamr@4
    81
__put_float(char* __ibuf, char* __iend, _OutputIter __stl_out,
williamr@4
    82
            ios_base& __f, wchar_t __fill,
williamr@4
    83
            wchar_t __decimal_point,
williamr@4
    84
            wchar_t __sep, const string& __grouping)
williamr@4
    85
{
williamr@4
    86
  //const ctype<wchar_t>& __ct = *(ctype<wchar_t>*)__f._M_ctype_facet() ;
williamr@4
    87
    const ctype<wchar_t>& __ct  = use_facet< ctype<wchar_t> >(__f.getloc());
williamr@4
    88
williamr@4
    89
 // wchar_t __wbuf[128]; //stdcxx fix
williamr@4
    90
  wchar_t __wbuf[256+10];
williamr@4
    91
  wchar_t* __eend = __convert_float_buffer(__ibuf, __iend, __wbuf,
williamr@4
    92
                                           __ct, __decimal_point);
williamr@4
    93
  if (!__grouping.empty()) {
williamr@4
    94
    // In order to do separator-insertion only to the left of the
williamr@4
    95
    // decimal point, we adjust the size of the first (right-most)
williamr@4
    96
    // group.  We need to be careful if there is only one entry in
williamr@4
    97
    // grouping:  in this case we need to duplicate the first entry.
williamr@4
    98
williamr@4
    99
    string __new_grouping = __grouping;
williamr@4
   100
    wchar_t* __decimal_pos = find(__wbuf, __eend, __decimal_point);
williamr@4
   101
    if (__grouping.size() == 1)
williamr@4
   102
      __new_grouping.push_back(__grouping[0]);
williamr@4
   103
williamr@4
   104
	// dwa 1/24/00 - try as I might, there doesn't seem to be a way
williamr@4
   105
    // to suppress the warning
williamr@4
   106
    __new_grouping[0] += __STATIC_CAST(char, __eend - __decimal_pos);
williamr@4
   107
    ptrdiff_t __len = __insert_grouping(__wbuf, __eend, __new_grouping,
williamr@4
   108
					__sep,
williamr@4
   109
					__ct.widen('+'), __ct.widen('-'),
williamr@4
   110
					0);
williamr@4
   111
    __eend = __wbuf + __len;
williamr@4
   112
  }
williamr@4
   113
williamr@4
   114
  return __copy_float_and_fill(__wbuf, __eend, __stl_out,
williamr@4
   115
                               __f.flags(), __f.width(0), __fill,
williamr@4
   116
                               __ct.widen('+'), __ct.widen('-')); 
williamr@4
   117
}
williamr@4
   118
# endif /* WCHAR_T */
williamr@4
   119
williamr@4
   120
#ifdef __SYMBIAN32__
williamr@4
   121
template<class _CharT>
williamr@4
   122
ptrdiff_t _STLP_CALL
williamr@4
   123
__insert_grouping(_CharT * first, _CharT * last, const string& grouping,
williamr@4
   124
		  _CharT separator, _CharT Plus, _CharT Minus, int basechars)
williamr@4
   125
{
williamr@4
   126
	int length = last-first;
williamr@4
   127
	ptrdiff_t res;	
williamr@4
   128
	char*	str = new char(length+64); //morespace for seperators
williamr@4
   129
	memset(str,'\0',length+64);
williamr@4
   130
	memcpy(str,first, length);
williamr@4
   131
	char _separator = (char)separator;
williamr@4
   132
	char _Plus = (char)Plus;
williamr@4
   133
	char _Minus = (char)Minus;
williamr@4
   134
	
williamr@4
   135
  	res = __insert_grouping(str, str+length, grouping, 
williamr@4
   136
			       _separator, _Plus, _Minus, basechars);
williamr@4
   137
	memcpy(first,str,res);
williamr@4
   138
	delete str;
williamr@4
   139
	return res;
williamr@4
   140
	
williamr@4
   141
}
williamr@4
   142
williamr@4
   143
#endif
williamr@4
   144
// Helper routine for char
williamr@4
   145
template <class _OutputIter>
williamr@4
   146
_OutputIter  _STLP_CALL
williamr@4
   147
__put_float(char* __ibuf, char* __iend, _OutputIter __stl_out,
williamr@4
   148
            ios_base& __f, char __fill,
williamr@4
   149
            char __decimal_point,
williamr@4
   150
            char __sep, const string& __grouping)
williamr@4
   151
{
williamr@4
   152
  __adjust_float_buffer(__ibuf, __iend, __decimal_point);
williamr@4
   153
  if (!__grouping.empty()) {
williamr@4
   154
    string __new_grouping = __grouping;
williamr@4
   155
    const char * __decimal_pos = find(__ibuf, __iend, __decimal_point);
williamr@4
   156
    if (__grouping.size() == 1)
williamr@4
   157
      __new_grouping.push_back(__grouping[0]);
williamr@4
   158
    __new_grouping[0] += __STATIC_CAST(char, (__iend - __decimal_pos));
williamr@4
   159
    ptrdiff_t __len = __insert_grouping(__ibuf, __iend, __new_grouping,
williamr@4
   160
					__sep, '+', '-', 0);
williamr@4
   161
    __iend = __ibuf + __len;
williamr@4
   162
  }
williamr@4
   163
williamr@4
   164
  return __copy_float_and_fill(__ibuf, __iend, __stl_out,
williamr@4
   165
                               __f.flags(), __f.width(0), __fill, '+', '-');
williamr@4
   166
}
williamr@4
   167
williamr@4
   168
#ifdef __SYMBIAN32__
williamr@4
   169
williamr@4
   170
template <class _CharT, class _OutputIter>
williamr@4
   171
_OutputIter  _STLP_CALL
williamr@4
   172
__put_float(char* __ibuf, char* __iend, _OutputIter __stl_out,
williamr@4
   173
            ios_base& __f, _CharT __fill,
williamr@4
   174
            _CharT __decimal_point,
williamr@4
   175
            _CharT __sep, const string& __grouping)
williamr@4
   176
{
williamr@4
   177
  __adjust_float_buffer(__ibuf, __iend, __decimal_point);
williamr@4
   178
  if (!__grouping.empty()) {
williamr@4
   179
    string __new_grouping = __grouping;
williamr@4
   180
    const char * __decimal_pos = find(__ibuf, __iend, __decimal_point);
williamr@4
   181
    if (__grouping.size() == 1)
williamr@4
   182
      __new_grouping.push_back(__grouping[0]);
williamr@4
   183
    __new_grouping[0] += __STATIC_CAST(char, (__iend - __decimal_pos));
williamr@4
   184
    ptrdiff_t __len = __insert_grouping(__ibuf, __iend, __new_grouping,
williamr@4
   185
					__sep, '+', '-', 0);
williamr@4
   186
    __iend = __ibuf + __len;
williamr@4
   187
  }
williamr@4
   188
williamr@4
   189
	_CharT __wbuf[64];
williamr@4
   190
	locale __loc = __f.getloc();
williamr@4
   191
	const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
williamr@4
   192
	__ct.widen(__ibuf, __iend, __wbuf);
williamr@4
   193
	
williamr@4
   194
 	ptrdiff_t __len  =  __iend - __ibuf; 
williamr@4
   195
  return __copy_float_and_fill(__wbuf, __wbuf+__len, __stl_out,
williamr@4
   196
                               __f.flags(), __f.width(0), __fill, (_CharT)'+', (_CharT)'-');
williamr@4
   197
}
williamr@4
   198
williamr@4
   199
williamr@4
   200
#endif
williamr@4
   201
template <class _CharT, class _OutputIter, class _Float>
williamr@4
   202
_OutputIter _STLP_CALL
williamr@4
   203
_M_do_put_float(_OutputIter __s, ios_base& __f,
williamr@4
   204
                _CharT __fill, _Float __x)
williamr@4
   205
{
williamr@4
   206
  string __buf;
williamr@4
   207
  __buf.reserve(256+10); //+2 - 10/1/07
williamr@4
   208
  __write_float(__buf, __f.flags(), (int)__f.precision(), __x);
williamr@4
   209
williamr@4
   210
  //const numpunct<_CharT>& __np = *(const numpunct<_CharT>*)__f._M_numpunct_facet();
williamr@4
   211
  const numpunct<_CharT>& __np = use_facet< numpunct<_CharT> >(__f.getloc());
williamr@4
   212
  
williamr@4
   213
  return __put_float(__CONST_CAST(char*, __buf.c_str()), 
williamr@4
   214
                     __CONST_CAST(char*, __buf.c_str()) + __buf.size(),
williamr@4
   215
                     __s, __f, __fill,
williamr@4
   216
                     __np.decimal_point(),
williamr@4
   217
	//	                 __np.thousands_sep(), __f._M_grouping()); //stdcxx fix - 17/1/07
williamr@4
   218
			__np.thousands_sep(), __np.grouping());
williamr@4
   219
}
williamr@4
   220
williamr@4
   221
// _M_do_put_integer and its helper functions.
williamr@4
   222
williamr@4
   223
template <class _CharT, class _OutputIter>
williamr@4
   224
_OutputIter _STLP_CALL
williamr@4
   225
__copy_integer_and_fill(const _CharT* __buf, ptrdiff_t __len,
williamr@4
   226
                        _OutputIter __stl_out,
williamr@4
   227
                        ios_base::fmtflags __flg, streamsize __wid, _CharT __fill,
williamr@4
   228
                        _CharT __xplus, _CharT __xminus)
williamr@4
   229
{
williamr@4
   230
  if (__len >= __wid)
williamr@4
   231
    return copy(__buf, __buf + __len, __stl_out);
williamr@4
   232
  else {
williamr@4
   233
    ptrdiff_t __pad = __wid - __len;
williamr@4
   234
    ios_base::fmtflags __dir = __flg & ios_base::adjustfield;
williamr@4
   235
williamr@4
   236
    if (__dir == ios_base::left) {
williamr@4
   237
      __stl_out = copy(__buf, __buf + __len, __stl_out);
williamr@4
   238
      return fill_n(__stl_out, __pad, __fill);
williamr@4
   239
    }
williamr@4
   240
    else if (__dir == ios_base::internal && __len != 0 &&
williamr@4
   241
             (__buf[0] == __xplus || __buf[0] == __xminus)) {
williamr@4
   242
      *__stl_out++ = __buf[0];
williamr@4
   243
      __stl_out = fill_n(__stl_out, __pad, __fill);
williamr@4
   244
      return copy(__buf + 1, __buf + __len, __stl_out);
williamr@4
   245
    }
williamr@4
   246
    else if (__dir == ios_base::internal && __len >= 2 &&
williamr@4
   247
             (__flg & ios_base::showbase) &&
williamr@4
   248
             (__flg & ios_base::basefield) == ios_base::hex) {
williamr@4
   249
      *__stl_out++ = __buf[0];
williamr@4
   250
      *__stl_out++ = __buf[1];
williamr@4
   251
      __stl_out = fill_n(__stl_out, __pad, __fill);
williamr@4
   252
      return copy(__buf + 2, __buf + __len, __stl_out);
williamr@4
   253
    }
williamr@4
   254
    else {
williamr@4
   255
      __stl_out = fill_n(__stl_out, __pad, __fill);
williamr@4
   256
      return copy(__buf, __buf + __len, __stl_out);
williamr@4
   257
    }
williamr@4
   258
  }
williamr@4
   259
}
williamr@4
   260
williamr@4
   261
#ifndef _STLP_NO_WCHAR_T
williamr@4
   262
// Helper function for wchar_t
williamr@4
   263
template <class _OutputIter>
williamr@4
   264
_OutputIter _STLP_CALL
williamr@4
   265
__put_integer(char* __buf, char* __iend, _OutputIter __s,
williamr@4
   266
              ios_base& __f,
williamr@4
   267
              ios_base::fmtflags __flags, wchar_t __fill)
williamr@4
   268
{
williamr@4
   269
  locale __loc = __f.getloc();
williamr@4
   270
   const ctype<wchar_t>& __ct = use_facet<ctype<wchar_t> >(__loc);
williamr@4
   271
  //const ctype<wchar_t>& __ct = *(const ctype<wchar_t>*)__f._M_ctype_facet();
williamr@4
   272
williamr@4
   273
  wchar_t __xplus  = __ct.widen('+');
williamr@4
   274
  wchar_t __xminus = __ct.widen('-');
williamr@4
   275
williamr@4
   276
  wchar_t __wbuf[64];
williamr@4
   277
  __ct.widen(__buf, __iend, __wbuf);
williamr@4
   278
  ptrdiff_t __len = __iend - __buf;
williamr@4
   279
  wchar_t* __eend = __wbuf + __len;
williamr@4
   280
williamr@4
   281
    const numpunct<wchar_t>& __np = use_facet<numpunct<wchar_t> >(__loc);
williamr@4
   282
    const string& __grouping = __np.grouping();
williamr@4
   283
williamr@4
   284
  //const numpunct<wchar_t>& __np = *(const numpunct<wchar_t>*)__f._M_numpunct_facet();
williamr@4
   285
 // const string& __grouping = __f._M_grouping();
williamr@4
   286
williamr@4
   287
  if (!__grouping.empty()) {
williamr@4
   288
    int __basechars;
williamr@4
   289
    if (__flags & ios_base::showbase)
williamr@4
   290
      switch (__flags & ios_base::basefield) {
williamr@4
   291
	case ios_base::hex: __basechars = 2; break;
williamr@4
   292
	case ios_base::oct: __basechars = 1; break;
williamr@4
   293
	default: __basechars = 0;
williamr@4
   294
      }
williamr@4
   295
    else
williamr@4
   296
      __basechars = 0;
williamr@4
   297
williamr@4
   298
    __len = __insert_grouping(__wbuf, __eend, __grouping, __np.thousands_sep(),
williamr@4
   299
			      __xplus, __xminus, __basechars);
williamr@4
   300
  }
williamr@4
   301
williamr@4
   302
  return __copy_integer_and_fill((wchar_t*)__wbuf, __len, __s,
williamr@4
   303
                                 __flags, __f.width(0), __fill, __xplus, __xminus);
williamr@4
   304
}
williamr@4
   305
#endif
williamr@4
   306
williamr@4
   307
#ifdef	__SYMBIAN32__
williamr@4
   308
template <class _CharT, class _OutputIter>
williamr@4
   309
_OutputIter _STLP_CALL
williamr@4
   310
__put_integer(char* __buf, char* __iend, _OutputIter __s,
williamr@4
   311
              ios_base& __f,
williamr@4
   312
              ios_base::fmtflags __flags, _CharT __fill)
williamr@4
   313
{
williamr@4
   314
  locale __loc = __f.getloc();
williamr@4
   315
   const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
williamr@4
   316
  //const ctype<wchar_t>& __ct = *(const ctype<wchar_t>*)__f._M_ctype_facet();
williamr@4
   317
williamr@4
   318
  _CharT __xplus  = '+';
williamr@4
   319
  _CharT __xminus = '-';
williamr@4
   320
williamr@4
   321
  _CharT __wbuf[64];
williamr@4
   322
  
williamr@4
   323
  ptrdiff_t __len = __iend - __buf;
williamr@4
   324
  _CharT* __eend = __wbuf + __len;
williamr@4
   325
williamr@4
   326
williamr@4
   327
    const numpunct<char>& __np = use_facet<numpunct<char> >(__loc);
williamr@4
   328
    const string& __grouping = __np.grouping();
williamr@4
   329
williamr@4
   330
  //const numpunct<wchar_t>& __np = *(const numpunct<wchar_t>*)__f._M_numpunct_facet();
williamr@4
   331
 // const string& __grouping = __f._M_grouping();
williamr@4
   332
williamr@4
   333
  if (!__grouping.empty()) {
williamr@4
   334
    int __basechars;
williamr@4
   335
    if (__flags & ios_base::showbase)
williamr@4
   336
      switch (__flags & ios_base::basefield) {
williamr@4
   337
	case ios_base::hex: __basechars = 2; break;
williamr@4
   338
	case ios_base::oct: __basechars = 1; break;
williamr@4
   339
	default: __basechars = 0;
williamr@4
   340
      }
williamr@4
   341
    else
williamr@4
   342
      __basechars = 0;
williamr@4
   343
williamr@4
   344
    __len = __insert_grouping(__buf, __iend, __grouping, __np.thousands_sep(),
williamr@4
   345
			     __ct.narrow( __xplus, '+'), __ct.narrow(__xminus, '-'), __basechars);
williamr@4
   346
	__ct.widen(__buf, __iend, __wbuf);
williamr@4
   347
	
williamr@4
   348
  }
williamr@4
   349
williamr@4
   350
  return __copy_integer_and_fill(__wbuf, __len, __s,
williamr@4
   351
                                 __flags, __f.width(0), __fill, __xplus, __xminus);
williamr@4
   352
}
williamr@4
   353
williamr@4
   354
williamr@4
   355
#endif
williamr@4
   356
// Helper function for char
williamr@4
   357
template <class _OutputIter>
williamr@4
   358
_OutputIter _STLP_CALL
williamr@4
   359
__put_integer(char* __buf, char* __iend, _OutputIter __s,
williamr@4
   360
              ios_base& __f, ios_base::fmtflags __flags, char __fill)
williamr@4
   361
{
williamr@4
   362
  ptrdiff_t __len = __iend - __buf;
williamr@4
   363
  char __grpbuf[64];
williamr@4
   364
williamr@4
   365
  //  const numpunct<char>& __np = use_facet<numpunct<char> >(__f.getloc());
williamr@4
   366
  //  const string& __grouping = __np.grouping();
williamr@4
   367
williamr@4
   368
  const numpunct<char>& __np = *(const numpunct<char>*)__f._M_numpunct_facet();
williamr@4
   369
//  const string& __grouping = __f._M_grouping(); //stdcxx fix, 17/1/07
williamr@4
   370
  const string& __grouping = __np.grouping();
williamr@4
   371
williamr@4
   372
  if (!__grouping.empty()) {
williamr@4
   373
    int __basechars;
williamr@4
   374
    if (__flags & ios_base::showbase)
williamr@4
   375
      switch (__flags & ios_base::basefield) {
williamr@4
   376
	case ios_base::hex: __basechars = 2; break;
williamr@4
   377
	case ios_base::oct: __basechars = 1; break;
williamr@4
   378
	default: __basechars = 0;
williamr@4
   379
      }
williamr@4
   380
    else
williamr@4
   381
      __basechars = 0;
williamr@4
   382
 
williamr@4
   383
     // make sure there is room at the end of the buffer
williamr@4
   384
     // we pass to __insert_grouping
williamr@4
   385
williamr@4
   386
    copy(__buf, __iend, (char *) __grpbuf);
williamr@4
   387
    __buf = __grpbuf;
williamr@4
   388
    __iend = __grpbuf + __len; 
williamr@4
   389
    __len = __insert_grouping(__buf, __iend, __grouping, __np.thousands_sep(), 
williamr@4
   390
                              '+', '-', __basechars);
williamr@4
   391
  }
williamr@4
   392
  
williamr@4
   393
  return __copy_integer_and_fill(__buf, __len, __s, __flags, __f.width(0), __fill, '+', '-');
williamr@4
   394
}
williamr@4
   395
williamr@4
   396
#ifdef _STLP_LONG_LONG
williamr@4
   397
typedef _STLP_LONG_LONG __max_int_t;
williamr@4
   398
typedef unsigned _STLP_LONG_LONG __umax_int_t;
williamr@4
   399
#else
williamr@4
   400
typedef long __max_int_t;
williamr@4
   401
typedef unsigned long __umax_int_t;
williamr@4
   402
#endif
williamr@4
   403
williamr@4
   404
extern _STLP_DECLSPEC const char* get_hex_char_table_lo();
williamr@4
   405
extern _STLP_DECLSPEC const char* get_hex_char_table_hi();
williamr@4
   406
williamr@4
   407
template <class _Integer>
williamr@4
   408
inline char* _STLP_CALL
williamr@4
   409
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __true_type& /* is_signed */)
williamr@4
   410
{
williamr@4
   411
  const bool __negative = __x < 0 ;
williamr@4
   412
  __max_int_t __temp = __x;
williamr@4
   413
  __umax_int_t __utemp = __negative?-__temp:__temp;
williamr@4
   414
williamr@4
   415
  for (; __utemp != 0; __utemp /= 10)
williamr@4
   416
    *--__ptr = (int)(__utemp % 10) + '0';	  
williamr@4
   417
  // put sign if needed or requested
williamr@4
   418
  if (__negative)
williamr@4
   419
    *--__ptr = '-';
williamr@4
   420
  else if (__flags & ios_base::showpos)
williamr@4
   421
    *--__ptr = '+';
williamr@4
   422
  return __ptr;
williamr@4
   423
}
williamr@4
   424
williamr@4
   425
template <class _Integer>
williamr@4
   426
inline char* _STLP_CALL
williamr@4
   427
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __false_type& /* is_signed */)
williamr@4
   428
{
williamr@4
   429
  for (; __x != 0; __x /= 10)
williamr@4
   430
    *--__ptr = (int)(__x % 10) + '0';
williamr@4
   431
  // put sign if requested
williamr@4
   432
  if (__flags & ios_base::showpos)
williamr@4
   433
    *--__ptr = '+';
williamr@4
   434
  return __ptr;
williamr@4
   435
}
williamr@4
   436
williamr@4
   437
template <class _Integer>
williamr@4
   438
char* _STLP_CALL
williamr@4
   439
__write_integer_backward(char* __buf, ios_base::fmtflags __flags, _Integer __x)
williamr@4
   440
{
williamr@4
   441
  char* __ptr = __buf;
williamr@4
   442
  __umax_int_t __temp;
williamr@4
   443
williamr@4
   444
  if (__x == 0) {
williamr@4
   445
    *--__ptr = '0';
williamr@4
   446
    if ((__flags & ios_base::showpos) && ( (__flags & (ios_base::hex | ios_base::oct)) == 0 ))
williamr@4
   447
      *--__ptr = '+';
williamr@4
   448
  }
williamr@4
   449
  else {
williamr@4
   450
    
williamr@4
   451
    switch (__flags & ios_base::basefield) {
williamr@4
   452
    case ios_base::oct:
williamr@4
   453
      __temp = __x;
williamr@4
   454
      // if the size of integer is less than 8, clear upper part
williamr@4
   455
      if ( sizeof(__x) < 8  && sizeof(__umax_int_t) >= 8 )
williamr@4
   456
        __temp &= 0xFFFFFFFF;
williamr@4
   457
williamr@4
   458
      for (; __temp != 0; __temp >>=3)
williamr@4
   459
        *--__ptr = (((unsigned)__temp)& 0x7) + '0';
williamr@4
   460
      
williamr@4
   461
      // put leading '0' is showbase is set
williamr@4
   462
      if (__flags & ios_base::showbase)
williamr@4
   463
        *--__ptr = '0';
williamr@4
   464
      break;
williamr@4
   465
    case ios_base::hex: 
williamr@4
   466
      {
williamr@4
   467
        const char* __table_ptr = (__flags & ios_base::uppercase) ? 
williamr@4
   468
          get_hex_char_table_hi() : get_hex_char_table_lo();
williamr@4
   469
      __temp = __x;
williamr@4
   470
      // if the size of integer is less than 8, clear upper part
williamr@4
   471
      if ( sizeof(__x) < 8  && sizeof(__umax_int_t) >= 8 )
williamr@4
   472
        __temp &= 0xFFFFFFFF;
williamr@4
   473
williamr@4
   474
        for (; __temp != 0; __temp >>=4)
williamr@4
   475
          *--__ptr = __table_ptr[((unsigned)__temp & 0xF)];
williamr@4
   476
        
williamr@4
   477
        if (__flags & ios_base::showbase) {
williamr@4
   478
          *--__ptr = __table_ptr[16];
williamr@4
   479
          *--__ptr = '0';
williamr@4
   480
        }
williamr@4
   481
      }
williamr@4
   482
      break;
williamr@4
   483
    default: 
williamr@4
   484
      {
williamr@4
   485
#if defined(__HP_aCC) && (__HP_aCC == 1)
williamr@4
   486
        bool _IsSigned = !((_Integer)-1 > 0);
williamr@4
   487
	if (_IsSigned)
williamr@4
   488
	  __ptr = __write_decimal_backward(__ptr, __x, __flags, __true_type() );
williamr@4
   489
        else
williamr@4
   490
	  __ptr = __write_decimal_backward(__ptr, __x, __flags, __false_type() );
williamr@4
   491
#else
williamr@4
   492
	typedef typename __bool2type<numeric_limits<_Integer>::is_signed>::_Ret _IsSigned;
williamr@4
   493
	__ptr = __write_decimal_backward(__ptr, __x, __flags, _IsSigned());
williamr@4
   494
# endif
williamr@4
   495
      }
williamr@4
   496
      break;
williamr@4
   497
    }  
williamr@4
   498
  }
williamr@4
   499
  // return pointer to beginning of the string
williamr@4
   500
  return __ptr;
williamr@4
   501
}
williamr@4
   502
williamr@4
   503
//
williamr@4
   504
// num_put<>
williamr@4
   505
//
williamr@4
   506
williamr@4
   507
# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
williamr@4
   508
# if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
williamr@4
   509
template <class _CharT, class _OutputIterator>
williamr@4
   510
locale::id num_put<_CharT, _OutputIterator>::id;
williamr@4
   511
#endif
williamr@4
   512
# else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
williamr@4
   513
williamr@4
   514
typedef num_put<char, const char*> num_put_char;
williamr@4
   515
typedef num_put<char, char*> num_put_char_2;
williamr@4
   516
typedef num_put<char, ostreambuf_iterator<char, char_traits<char> > > num_put_char_3;
williamr@4
   517
typedef num_put<char, back_insert_iterator<string> > num_put_char_4;
williamr@4
   518
williamr@4
   519
#ifndef __SYMBIAN32__
williamr@4
   520
__DECLARE_INSTANCE(locale::id, num_put_char::id, );
williamr@4
   521
__DECLARE_INSTANCE(locale::id, num_put_char_2::id, );
williamr@4
   522
__DECLARE_INSTANCE(locale::id, num_put_char_3::id, );
williamr@4
   523
#endif
williamr@4
   524
williamr@4
   525
# ifndef _STLP_NO_WCHAR_T
williamr@4
   526
williamr@4
   527
typedef num_put<wchar_t, const wchar_t*> num_put_wchar_t;
williamr@4
   528
typedef num_put<wchar_t, wchar_t*> num_put_wchar_t_2;
williamr@4
   529
typedef num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > num_put_wchar_t_3;
williamr@4
   530
williamr@4
   531
#ifndef __SYMBIAN32__
williamr@4
   532
__DECLARE_INSTANCE(locale::id, num_put_wchar_t::id, );
williamr@4
   533
__DECLARE_INSTANCE(locale::id, num_put_wchar_t_2::id, );
williamr@4
   534
__DECLARE_INSTANCE(locale::id, num_put_wchar_t_3::id, );
williamr@4
   535
#endif
williamr@4
   536
williamr@4
   537
# endif
williamr@4
   538
williamr@4
   539
# endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
williamr@4
   540
williamr@4
   541
// issue 118
williamr@4
   542
williamr@4
   543
# ifndef _STLP_NO_BOOL
williamr@4
   544
williamr@4
   545
template <class _CharT, class _OutputIter>  
williamr@4
   546
_OutputIter 
williamr@4
   547
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, 
williamr@4
   548
                                     char_type __fill,  bool __val) const {
williamr@4
   549
  if (!(__f.flags() & ios_base::boolalpha))
williamr@4
   550
    return this->do_put(__s, __f, __fill, __STATIC_CAST(long,__val));
williamr@4
   551
williamr@4
   552
  locale __loc = __f.getloc();
williamr@4
   553
    typedef numpunct<_CharT> _Punct;
williamr@4
   554
    const _Punct& __np = use_facet<_Punct>(__loc);
williamr@4
   555
williamr@4
   556
  //const numpunct<_CharT>& __np = *(const numpunct<_CharT>*)__f._M_numpunct_facet();
williamr@4
   557
williamr@4
   558
  basic_string<_CharT> __str = __val ? __np.truename() : __np.falsename();
williamr@4
   559
williamr@4
   560
  // Reuse __copy_integer_and_fill.  Since internal padding makes no
williamr@4
   561
  // sense for bool, though, make sure we use something else instead.
williamr@4
   562
  // The last two argument to __copy_integer_and_fill are dummies.
williamr@4
   563
  ios_base::fmtflags __flags = __f.flags();
williamr@4
   564
  if ((__flags & ios_base::adjustfield) == ios_base::internal)
williamr@4
   565
    __flags = (__flags & ~ios_base::adjustfield) | ios_base::right;
williamr@4
   566
williamr@4
   567
  return __copy_integer_and_fill(__str.c_str(), __str.size(), __s,
williamr@4
   568
                                 __flags, __f.width(0), __fill,
williamr@4
   569
                                 (_CharT) 0, (_CharT) 0);
williamr@4
   570
}
williamr@4
   571
williamr@4
   572
# endif
williamr@4
   573
williamr@4
   574
template <class _CharT, class _OutputIter>
williamr@4
   575
_OutputIter 
williamr@4
   576
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   577
                                     long __val) const {
williamr@4
   578
williamr@4
   579
  char __buf[64];               // Large enough for a base 8 64-bit integer,
williamr@4
   580
                                // plus any necessary grouping.  
williamr@4
   581
  ios_base::fmtflags __flags = __f.flags();
williamr@4
   582
  char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);  
williamr@4
   583
  return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
williamr@4
   584
}
williamr@4
   585
williamr@4
   586
williamr@4
   587
template <class _CharT, class _OutputIter>  
williamr@4
   588
_OutputIter 
williamr@4
   589
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   590
				     unsigned long __val) const {
williamr@4
   591
  char __buf[64];               // Large enough for a base 8 64-bit integer,
williamr@4
   592
                                // plus any necessary grouping.
williamr@4
   593
  
williamr@4
   594
  ios_base::fmtflags __flags = __f.flags();
williamr@4
   595
  char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
williamr@4
   596
  return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
williamr@4
   597
}
williamr@4
   598
williamr@4
   599
template <class _CharT, class _OutputIter>  
williamr@4
   600
_OutputIter 
williamr@4
   601
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   602
                                     double __val) const {
williamr@4
   603
  return _M_do_put_float(__s, __f, __fill, __val);
williamr@4
   604
}
williamr@4
   605
williamr@4
   606
#ifndef _STLP_NO_LONG_DOUBLE
williamr@4
   607
template <class _CharT, class _OutputIter>  
williamr@4
   608
_OutputIter 
williamr@4
   609
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   610
                                     long double __val) const {
williamr@4
   611
  return _M_do_put_float(__s, __f, __fill, __val);
williamr@4
   612
}
williamr@4
   613
#endif
williamr@4
   614
williamr@4
   615
#ifdef _STLP_LONG_LONG
williamr@4
   616
template <class _CharT, class _OutputIter>  
williamr@4
   617
_OutputIter 
williamr@4
   618
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   619
                                     _STLP_LONG_LONG __val) const {
williamr@4
   620
  char __buf[64];               // Large enough for a base 8 64-bit integer,
williamr@4
   621
                                // plus any necessary grouping.
williamr@4
   622
  
williamr@4
   623
  ios_base::fmtflags __flags = __f.flags();
williamr@4
   624
  char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
williamr@4
   625
  return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
williamr@4
   626
}
williamr@4
   627
williamr@4
   628
template <class _CharT, class _OutputIter>  
williamr@4
   629
_OutputIter 
williamr@4
   630
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
williamr@4
   631
                                     unsigned _STLP_LONG_LONG __val) const {
williamr@4
   632
  char __buf[64];               // Large enough for a base 8 64-bit integer,
williamr@4
   633
                                // plus any necessary grouping.
williamr@4
   634
  
williamr@4
   635
  ios_base::fmtflags __flags = __f.flags();
williamr@4
   636
  char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);  
williamr@4
   637
  return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
williamr@4
   638
}
williamr@4
   639
williamr@4
   640
#endif /* _STLP_LONG_LONG */
williamr@4
   641
williamr@4
   642
williamr@4
   643
// lib.facet.num.put.virtuals "12 For conversion from void* the specifier is %p."
williamr@4
   644
template <class _CharT, class _OutputIter>
williamr@4
   645
_OutputIter
williamr@4
   646
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT /*__fill*/,
williamr@4
   647
				     const void* __val) const {
williamr@4
   648
  //const ctype<_CharT>& __c_type = *(const ctype<_CharT>*)__f._M_ctype_facet();
williamr@4
   649
  const ctype<_CharT>& __c_type  = use_facet< ctype<_CharT> >(__f.getloc());
williamr@4
   650
  ios_base::fmtflags __save_flags = __f.flags();
williamr@4
   651
williamr@4
   652
  __f.setf(ios_base::hex, ios_base::basefield);
williamr@4
   653
  __f.setf(ios_base::showbase);
williamr@4
   654
  __f.setf(ios_base::internal, ios_base::adjustfield);
williamr@4
   655
  //__f.width((sizeof(void*) * 2) + 2); // digits in pointer type plus '0x' prefix //making output equal to linux.
williamr@4
   656
# if defined(_STLP_LONG_LONG) && !defined(__MRC__) //*ty 11/24/2001 - MrCpp can not cast from void* to long long
williamr@4
   657
  _OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned _STLP_LONG_LONG,__val));
williamr@4
   658
# else
williamr@4
   659
  _OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned long,__val));
williamr@4
   660
# endif
williamr@4
   661
  __f.flags(__save_flags);
williamr@4
   662
  return result;
williamr@4
   663
}
williamr@4
   664
williamr@4
   665
_STLP_END_NAMESPACE
williamr@4
   666
williamr@4
   667
# endif /* _STLP_EXPOSE_STREAM_IMPLEMENTATION */
williamr@4
   668
williamr@4
   669
#endif /* _STLP_NUM_PUT_C */
williamr@4
   670
williamr@4
   671
// Local Variables:
williamr@4
   672
// mode:C++
williamr@4
   673
// End: