epoc32/include/tools/stlport/stl/_iostream_string.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
/*
williamr@2
     2
 * Copyright (c) 2004
williamr@2
     3
 * Francois Dumont
williamr@2
     4
 *
williamr@2
     5
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
     6
 * or implied. Any use is at your own risk.
williamr@2
     7
 *
williamr@2
     8
 * Permission to use or copy this software for any purpose is hereby granted
williamr@2
     9
 * without fee, provided the above notices are retained on all copies.
williamr@2
    10
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    11
 * provided the above notices are retained, and a notice that the code was
williamr@2
    12
 * modified is included with the above copyright notice.
williamr@2
    13
 *
williamr@2
    14
 */
williamr@2
    15
williamr@2
    16
 /*
williamr@2
    17
  * This is an internal string for the STLport own iostream implementation.
williamr@2
    18
  * The only diference rely on the allocator used to instanciate the basic_string.
williamr@2
    19
  * Its goals is to improve performance limitating the number of dynamic allocation
williamr@2
    20
  * that could occur when requesting a big float ouput for instance. This allocator
williamr@2
    21
  * is not standard conformant as it has an internal state (the static buffer)
williamr@2
    22
  */
williamr@2
    23
williamr@2
    24
williamr@2
    25
#ifndef _STLP_INTERNAL_IOSTREAM_STRING_H
williamr@2
    26
#define _STLP_INTERNAL_IOSTREAM_STRING_H
williamr@2
    27
williamr@2
    28
#ifndef _STLP_INTERNAL_ALLOC_H
williamr@2
    29
#  include <stl/_alloc.h>
williamr@2
    30
#endif /* _STLP_INTERNAL_ALLOC_H */
williamr@2
    31
williamr@2
    32
#ifndef _STLP_INTERNAL_STRING_H
williamr@2
    33
#  include <stl/_string.h>
williamr@2
    34
#endif /* _STLP_INTERNAL_STRING_H */
williamr@2
    35
williamr@2
    36
_STLP_BEGIN_NAMESPACE
williamr@2
    37
williamr@2
    38
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@2
    39
williamr@2
    40
template <class _CharT>
williamr@2
    41
class __iostring_allocator : public allocator<_CharT> {
williamr@2
    42
public:
williamr@2
    43
  enum { _STR_SIZE = 256 };
williamr@2
    44
williamr@2
    45
private:
williamr@2
    46
  enum { _BUF_SIZE = _STR_SIZE + 1 };
williamr@2
    47
  typedef allocator<_CharT> _Base;
williamr@2
    48
  _CharT _M_static_buf[_BUF_SIZE];
williamr@2
    49
williamr@2
    50
public:
williamr@2
    51
  typedef typename _Base::size_type size_type;
williamr@2
    52
  typedef typename _Base::pointer pointer;
williamr@2
    53
#if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
williamr@2
    54
  template <class _Tp1> struct rebind {
williamr@2
    55
#  if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1300)
williamr@2
    56
    typedef __iostring_allocator<_Tp1> other;
williamr@2
    57
#  else
williamr@2
    58
    typedef _STLP_PRIV __iostring_allocator<_Tp1> other;
williamr@2
    59
#  endif
williamr@2
    60
  };
williamr@2
    61
#endif
williamr@2
    62
williamr@2
    63
  _CharT* allocate(size_type __n, const void* __ptr = 0) {
williamr@2
    64
    if (__n > _BUF_SIZE) {
williamr@2
    65
      return _Base::allocate(__n, __ptr);
williamr@2
    66
    }
williamr@2
    67
    return _M_static_buf;
williamr@2
    68
  }
williamr@2
    69
  void deallocate(pointer __p, size_type __n) {
williamr@2
    70
    if (__p != _M_static_buf) _Base::deallocate(__p, __n);
williamr@2
    71
  }
williamr@2
    72
};
williamr@2
    73
williamr@2
    74
#if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) || !defined (_STLP_MEMBER_TEMPLATES)
williamr@2
    75
/*
williamr@2
    76
 * As the __iostring_allocator allocator will only be used in the basic_string implementation
williamr@2
    77
 * we known that it is never going to be bound to another type that the one used to instantiate
williamr@2
    78
 * the basic_string. This is why the associated __stl_alloc_rebind has only one template
williamr@2
    79
 * parameter.
williamr@2
    80
 */
williamr@2
    81
_STLP_MOVE_TO_STD_NAMESPACE
williamr@2
    82
williamr@2
    83
template <class _Tp>
williamr@2
    84
inline _STLP_PRIV __iostring_allocator<_Tp>& _STLP_CALL
williamr@2
    85
__stl_alloc_rebind(_STLP_PRIV __iostring_allocator<_Tp>& __a, const _Tp*)
williamr@2
    86
{ return __a; }
williamr@2
    87
template <class _Tp>
williamr@2
    88
inline _STLP_PRIV __iostring_allocator<_Tp> _STLP_CALL
williamr@2
    89
__stl_alloc_create(const _STLP_PRIV __iostring_allocator<_Tp>&, const _Tp*)
williamr@2
    90
{ return _STLP_PRIV __iostring_allocator<_Tp>(); }
williamr@2
    91
williamr@2
    92
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@2
    93
#endif /* _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE */
williamr@2
    94
williamr@2
    95
#if !defined (_STLP_DEBUG)
williamr@2
    96
template <class _CharT>
williamr@2
    97
struct __basic_iostring : public basic_string<_CharT, char_traits<_CharT>, __iostring_allocator<_CharT> > {
williamr@2
    98
  /*
williamr@2
    99
   * A consequence of the non standard conformant allocator is that a string using it
williamr@2
   100
   * must always be presized to the allocator static buffer size because the basic_string implementation
williamr@2
   101
   * do not manage an allocator returning always the same memory adress as long as the
williamr@2
   102
   * requested memory block size is under a certain value.
williamr@2
   103
   */
williamr@2
   104
  typedef __basic_iostring<_CharT> _Self;
williamr@2
   105
  typedef basic_string<_CharT, char_traits<_CharT>, __iostring_allocator<_CharT> > _Base;
williamr@2
   106
  typedef typename _Base::_Reserve_t _Reserve_t;
williamr@2
   107
williamr@2
   108
  __basic_iostring() : _Base(_Reserve_t(), __iostring_allocator<_CharT>::_STR_SIZE)
williamr@2
   109
  {}
williamr@2
   110
williamr@2
   111
  _Self& operator=(const _CharT* __s) {
williamr@2
   112
    _Base::operator=(__s);
williamr@2
   113
    return *this;
williamr@2
   114
  }
williamr@2
   115
};
williamr@2
   116
williamr@2
   117
typedef __basic_iostring<char> __iostring;
williamr@2
   118
williamr@2
   119
#  if !defined (_STLP_NO_WCHAR_T)
williamr@2
   120
typedef __basic_iostring<wchar_t> __iowstring;
williamr@2
   121
#  endif
williamr@2
   122
williamr@2
   123
#  define _STLP_BASIC_IOSTRING(_CharT) _STLP_PRIV __basic_iostring<_CharT>
williamr@2
   124
williamr@2
   125
#else
williamr@2
   126
williamr@2
   127
typedef string __iostring;
williamr@2
   128
#  if !defined (_STLP_NO_WCHAR_T)
williamr@2
   129
typedef wstring __iowstring;
williamr@2
   130
#  endif
williamr@2
   131
williamr@2
   132
#  define _STLP_BASIC_IOSTRING(_CharT) basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
williamr@2
   133
williamr@2
   134
#endif
williamr@2
   135
williamr@2
   136
_STLP_MOVE_TO_STD_NAMESPACE
williamr@2
   137
williamr@2
   138
_STLP_END_NAMESPACE
williamr@2
   139
williamr@2
   140
#endif /* _STLP_INTERNAL_IOSTREAM_STRING_H */