1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_iostream_string.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,140 @@
1.4 +/*
1.5 + * Copyright (c) 2004
1.6 + * Francois Dumont
1.7 + *
1.8 + * This material is provided "as is", with absolutely no warranty expressed
1.9 + * or implied. Any use is at your own risk.
1.10 + *
1.11 + * Permission to use or copy this software for any purpose is hereby granted
1.12 + * without fee, provided the above notices are retained on all copies.
1.13 + * Permission to modify the code and to distribute modified code is granted,
1.14 + * provided the above notices are retained, and a notice that the code was
1.15 + * modified is included with the above copyright notice.
1.16 + *
1.17 + */
1.18 +
1.19 + /*
1.20 + * This is an internal string for the STLport own iostream implementation.
1.21 + * The only diference rely on the allocator used to instanciate the basic_string.
1.22 + * Its goals is to improve performance limitating the number of dynamic allocation
1.23 + * that could occur when requesting a big float ouput for instance. This allocator
1.24 + * is not standard conformant as it has an internal state (the static buffer)
1.25 + */
1.26 +
1.27 +
1.28 +#ifndef _STLP_INTERNAL_IOSTREAM_STRING_H
1.29 +#define _STLP_INTERNAL_IOSTREAM_STRING_H
1.30 +
1.31 +#ifndef _STLP_INTERNAL_ALLOC_H
1.32 +# include <stl/_alloc.h>
1.33 +#endif /* _STLP_INTERNAL_ALLOC_H */
1.34 +
1.35 +#ifndef _STLP_INTERNAL_STRING_H
1.36 +# include <stl/_string.h>
1.37 +#endif /* _STLP_INTERNAL_STRING_H */
1.38 +
1.39 +_STLP_BEGIN_NAMESPACE
1.40 +
1.41 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.42 +
1.43 +template <class _CharT>
1.44 +class __iostring_allocator : public allocator<_CharT> {
1.45 +public:
1.46 + enum { _STR_SIZE = 256 };
1.47 +
1.48 +private:
1.49 + enum { _BUF_SIZE = _STR_SIZE + 1 };
1.50 + typedef allocator<_CharT> _Base;
1.51 + _CharT _M_static_buf[_BUF_SIZE];
1.52 +
1.53 +public:
1.54 + typedef typename _Base::size_type size_type;
1.55 + typedef typename _Base::pointer pointer;
1.56 +#if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
1.57 + template <class _Tp1> struct rebind {
1.58 +# if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1300)
1.59 + typedef __iostring_allocator<_Tp1> other;
1.60 +# else
1.61 + typedef _STLP_PRIV __iostring_allocator<_Tp1> other;
1.62 +# endif
1.63 + };
1.64 +#endif
1.65 +
1.66 + _CharT* allocate(size_type __n, const void* __ptr = 0) {
1.67 + if (__n > _BUF_SIZE) {
1.68 + return _Base::allocate(__n, __ptr);
1.69 + }
1.70 + return _M_static_buf;
1.71 + }
1.72 + void deallocate(pointer __p, size_type __n) {
1.73 + if (__p != _M_static_buf) _Base::deallocate(__p, __n);
1.74 + }
1.75 +};
1.76 +
1.77 +#if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) || !defined (_STLP_MEMBER_TEMPLATES)
1.78 +/*
1.79 + * As the __iostring_allocator allocator will only be used in the basic_string implementation
1.80 + * we known that it is never going to be bound to another type that the one used to instantiate
1.81 + * the basic_string. This is why the associated __stl_alloc_rebind has only one template
1.82 + * parameter.
1.83 + */
1.84 +_STLP_MOVE_TO_STD_NAMESPACE
1.85 +
1.86 +template <class _Tp>
1.87 +inline _STLP_PRIV __iostring_allocator<_Tp>& _STLP_CALL
1.88 +__stl_alloc_rebind(_STLP_PRIV __iostring_allocator<_Tp>& __a, const _Tp*)
1.89 +{ return __a; }
1.90 +template <class _Tp>
1.91 +inline _STLP_PRIV __iostring_allocator<_Tp> _STLP_CALL
1.92 +__stl_alloc_create(const _STLP_PRIV __iostring_allocator<_Tp>&, const _Tp*)
1.93 +{ return _STLP_PRIV __iostring_allocator<_Tp>(); }
1.94 +
1.95 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.96 +#endif /* _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE */
1.97 +
1.98 +#if !defined (_STLP_DEBUG)
1.99 +template <class _CharT>
1.100 +struct __basic_iostring : public basic_string<_CharT, char_traits<_CharT>, __iostring_allocator<_CharT> > {
1.101 + /*
1.102 + * A consequence of the non standard conformant allocator is that a string using it
1.103 + * must always be presized to the allocator static buffer size because the basic_string implementation
1.104 + * do not manage an allocator returning always the same memory adress as long as the
1.105 + * requested memory block size is under a certain value.
1.106 + */
1.107 + typedef __basic_iostring<_CharT> _Self;
1.108 + typedef basic_string<_CharT, char_traits<_CharT>, __iostring_allocator<_CharT> > _Base;
1.109 + typedef typename _Base::_Reserve_t _Reserve_t;
1.110 +
1.111 + __basic_iostring() : _Base(_Reserve_t(), __iostring_allocator<_CharT>::_STR_SIZE)
1.112 + {}
1.113 +
1.114 + _Self& operator=(const _CharT* __s) {
1.115 + _Base::operator=(__s);
1.116 + return *this;
1.117 + }
1.118 +};
1.119 +
1.120 +typedef __basic_iostring<char> __iostring;
1.121 +
1.122 +# if !defined (_STLP_NO_WCHAR_T)
1.123 +typedef __basic_iostring<wchar_t> __iowstring;
1.124 +# endif
1.125 +
1.126 +# define _STLP_BASIC_IOSTRING(_CharT) _STLP_PRIV __basic_iostring<_CharT>
1.127 +
1.128 +#else
1.129 +
1.130 +typedef string __iostring;
1.131 +# if !defined (_STLP_NO_WCHAR_T)
1.132 +typedef wstring __iowstring;
1.133 +# endif
1.134 +
1.135 +# define _STLP_BASIC_IOSTRING(_CharT) basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
1.136 +
1.137 +#endif
1.138 +
1.139 +_STLP_MOVE_TO_STD_NAMESPACE
1.140 +
1.141 +_STLP_END_NAMESPACE
1.142 +
1.143 +#endif /* _STLP_INTERNAL_IOSTREAM_STRING_H */