ReactOS  0.4.13-dev-464-g6b95727
_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 
40 template <class _CharT>
41 class __iostring_allocator : public allocator<_CharT> {
42 public:
43  enum { _STR_SIZE = 256 };
44 
45 private:
46  enum { _BUF_SIZE = _STR_SIZE + 1 };
49 
50 public:
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 
83 template <class _Tp>
86 { return __a; }
87 template <class _Tp>
91 
93 #endif /* _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE */
94 
95 #if !defined (_STLP_DEBUG)
96 template <class _CharT>
97 struct __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 adress as long as the
102  * requested memory block size is under a certain value.
103  */
106  typedef typename _Base::_Reserve_t _Reserve_t;
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 
127 typedef string __iostring;
128 # if !defined (_STLP_NO_WCHAR_T)
129 typedef 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
__basic_iostring< wchar_t > __iowstring
_STLP_PRIV __iostring_allocator< _Tp > _STLP_CALL __stl_alloc_create(const _STLP_PRIV __iostring_allocator< _Tp > &, const _Tp *)
size_t size_type
Definition: _alloc.h:282
int other
Definition: msacm.c:1364
_Self & operator=(const _CharT *__s)
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
_CharT _M_static_buf[_BUF_SIZE]
_Base::pointer pointer
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
__basic_iostring< _CharT > _Self
void deallocate(pointer __p, size_type __n)
Definition: _alloc.h:317
__basic_iostring< char > __iostring
_CharT * allocate(size_type __n, const void *__ptr=0)
allocator< _CharT > _Base
#define _STLP_PRIV
Definition: _dm.h:70
basic_string< _CharT, char_traits< _CharT >, __iostring_allocator< _CharT > > _Base
_STLP_MOVE_TO_STD_NAMESPACE _STLP_PRIV __iostring_allocator< _Tp > &_STLP_CALL __stl_alloc_rebind(_STLP_PRIV __iostring_allocator< _Tp > &__a, const _Tp *)
_CharT * allocate(size_type __n, const void *=0)
Definition: _alloc.h:301
void deallocate(pointer __p, size_type __n)
#define _STLP_END_NAMESPACE
Definition: features.h:503
_CharT * pointer
Definition: _alloc.h:278
_Base::_Reserve_t _Reserve_t
_Base::size_type size_type
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_CALL
Definition: _bc.h:131