5 * This material is provided "as is", with absolutely no warranty expressed
6 * or implied. Any use is at your own risk.
8 * Permission to use or copy this software for any purpose is hereby granted
9 * without fee, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
17 * This is an internal string for the STLport own iostream implementation.
18 * The only diference rely on the allocator used to instanciate the basic_string.
19 * Its goals is to improve performance limitating the number of dynamic allocation
20 * that could occur when requesting a big float ouput for instance. This allocator
21 * is not standard conformant as it has an internal state (the static buffer)
25 #ifndef _STLP_INTERNAL_IOSTREAM_STRING_H
26 #define _STLP_INTERNAL_IOSTREAM_STRING_H
28 #ifndef _STLP_INTERNAL_ALLOC_H
29 # include <stl/_alloc.h>
30 #endif /* _STLP_INTERNAL_ALLOC_H */
32 #ifndef _STLP_INTERNAL_STRING_H
33 # include <stl/_string.h>
34 #endif /* _STLP_INTERNAL_STRING_H */
38 _STLP_MOVE_TO_PRIV_NAMESPACE
40 template <class _CharT>
41 class __iostring_allocator : public allocator<_CharT> {
43 enum { _STR_SIZE = 256 };
46 enum { _BUF_SIZE = _STR_SIZE + 1 };
47 typedef allocator<_CharT> _Base;
48 _CharT _M_static_buf[_BUF_SIZE];
51 typedef typename _Base::size_type size_type;
52 typedef typename _Base::pointer pointer;
53 #if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
54 template <class _Tp1> struct rebind {
55 # if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1300)
56 typedef __iostring_allocator<_Tp1> other;
58 typedef _STLP_PRIV __iostring_allocator<_Tp1> other;
63 _CharT* allocate(size_type __n, const void* __ptr = 0) {
64 if (__n > _BUF_SIZE) {
65 return _Base::allocate(__n, __ptr);
69 void deallocate(pointer __p, size_type __n) {
70 if (__p != _M_static_buf) _Base::deallocate(__p, __n);
74 #if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) || !defined (_STLP_MEMBER_TEMPLATES)
76 * As the __iostring_allocator allocator will only be used in the basic_string implementation
77 * we known that it is never going to be bound to another type that the one used to instantiate
78 * the basic_string. This is why the associated __stl_alloc_rebind has only one template
81 _STLP_MOVE_TO_STD_NAMESPACE
84 inline _STLP_PRIV __iostring_allocator<_Tp>& _STLP_CALL
85 __stl_alloc_rebind(_STLP_PRIV __iostring_allocator<_Tp>& __a, const _Tp*)
88 inline _STLP_PRIV __iostring_allocator<_Tp> _STLP_CALL
89 __stl_alloc_create(const _STLP_PRIV __iostring_allocator<_Tp>&, const _Tp*)
90 { return _STLP_PRIV __iostring_allocator<_Tp>(); }
92 _STLP_MOVE_TO_PRIV_NAMESPACE
93 #endif /* _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE */
95 #if !defined (_STLP_DEBUG)
96 template <class _CharT>
97 struct __basic_iostring : public basic_string<_CharT, char_traits<_CharT>, __iostring_allocator<_CharT> > {
99 * A consequence of the non standard conformant allocator is that a string using it
100 * must always be presized to the allocator static buffer size because the basic_string implementation
101 * do not manage an allocator returning always the same memory adress as long as the
102 * requested memory block size is under a certain value.
104 typedef __basic_iostring<_CharT> _Self;
105 typedef basic_string<_CharT, char_traits<_CharT>, __iostring_allocator<_CharT> > _Base;
106 typedef typename _Base::_Reserve_t _Reserve_t;
108 __basic_iostring() : _Base(_Reserve_t(), __iostring_allocator<_CharT>::_STR_SIZE)
111 _Self& operator=(const _CharT* __s) {
112 _Base::operator=(__s);
117 typedef __basic_iostring<char> __iostring;
119 # if !defined (_STLP_NO_WCHAR_T)
120 typedef __basic_iostring<wchar_t> __iowstring;
123 # define _STLP_BASIC_IOSTRING(_CharT) _STLP_PRIV __basic_iostring<_CharT>
127 typedef string __iostring;
128 # if !defined (_STLP_NO_WCHAR_T)
129 typedef wstring __iowstring;
132 # define _STLP_BASIC_IOSTRING(_CharT) basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
136 _STLP_MOVE_TO_STD_NAMESPACE
140 #endif /* _STLP_INTERNAL_IOSTREAM_STRING_H */