ReactOS 0.4.15-dev-7889-g76290a6
_iostream_string.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004
3 * Francois Dumont
4 *
5 * This material is provided "as is", with absolutely no warranty expressed
6 * or implied. Any use is at your own risk.
7 *
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.
13 *
14 */
15
16 /*
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)
22 */
23
24
25#ifndef _STLP_INTERNAL_IOSTREAM_STRING_H
26#define _STLP_INTERNAL_IOSTREAM_STRING_H
27
28#ifndef _STLP_INTERNAL_ALLOC_H
29# include <stl/_alloc.h>
30#endif /* _STLP_INTERNAL_ALLOC_H */
31
32#ifndef _STLP_INTERNAL_STRING_H
33# include <stl/_string.h>
34#endif /* _STLP_INTERNAL_STRING_H */
35
37
39
40template <class _CharT>
41class __iostring_allocator : public allocator<_CharT> {
42public:
43 enum { _STR_SIZE = 256 };
44
45private:
46 enum { _BUF_SIZE = _STR_SIZE + 1 };
49
50public:
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)
57# else
59# endif
60 };
61#endif
62
63 _CharT* allocate(size_type __n, const void* __ptr = 0) {
64 if (__n > _BUF_SIZE) {
65 return _Base::allocate(__n, __ptr);
66 }
67 return _M_static_buf;
68 }
70 if (__p != _M_static_buf) _Base::deallocate(__p, __n);
71 }
72};
73
74#if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) || !defined (_STLP_MEMBER_TEMPLATES)
75/*
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
79 * parameter.
80 */
82
83template <class _Tp>
86{ return __a; }
87template <class _Tp>
91
93#endif /* _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE */
94
95#if !defined (_STLP_DEBUG)
96template <class _CharT>
97struct __basic_iostring : public basic_string<_CharT, char_traits<_CharT>, __iostring_allocator<_CharT> > {
98 /*
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 address as long as the
102 * requested memory block size is under a certain value.
103 */
107
109 {}
110
111 _Self& operator=(const _CharT* __s) {
112 _Base::operator=(__s);
113 return *this;
114 }
115};
116
118
119# if !defined (_STLP_NO_WCHAR_T)
121# endif
122
123# define _STLP_BASIC_IOSTRING(_CharT) _STLP_PRIV __basic_iostring<_CharT>
124
125#else
126
127typedef string __iostring;
128# if !defined (_STLP_NO_WCHAR_T)
129typedef wstring __iowstring;
130# endif
131
132# define _STLP_BASIC_IOSTRING(_CharT) basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
133
134#endif
135
137
139
140#endif /* _STLP_INTERNAL_IOSTREAM_STRING_H */
return __n
Definition: _algo.h:75
#define _STLP_CALL
Definition: _bc.h:131
#define _STLP_PRIV
Definition: _dm.h:70
__basic_iostring< wchar_t > __iowstring
_STLP_MOVE_TO_STD_NAMESPACE _STLP_PRIV __iostring_allocator< _Tp > &_STLP_CALL __stl_alloc_rebind(_STLP_PRIV __iostring_allocator< _Tp > &__a, const _Tp *)
__basic_iostring< char > __iostring
_STLP_PRIV __iostring_allocator< _Tp > _STLP_CALL __stl_alloc_create(const _STLP_PRIV __iostring_allocator< _Tp > &, const _Tp *)
_Base::size_type size_type
allocator< _CharT > _Base
void deallocate(pointer __p, size_type __n)
_CharT * allocate(size_type __n, const void *__ptr=0)
_Base::pointer pointer
_CharT _M_static_buf[_BUF_SIZE]
void deallocate(pointer __p, size_type __n)
Definition: _alloc.h:317
_CharT * pointer
Definition: _alloc.h:278
size_t size_type
Definition: _alloc.h:282
_CharT * allocate(size_type __n, const void *=0)
Definition: _alloc.h:301
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
int other
Definition: msacm.c:1376
__basic_iostring< _CharT > _Self
basic_string< _CharT, char_traits< _CharT >, __iostring_allocator< _CharT > > _Base
_Self & operator=(const _CharT *__s)
_Base::_Reserve_t _Reserve_t