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