ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_string_base.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1997-1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * Copyright (c) 2003
00009  * Francois Dumont
00010  *
00011  * This material is provided "as is", with absolutely no warranty expressed
00012  * or implied. Any use is at your own risk.
00013  *
00014  * Permission to use or copy this software for any purpose is hereby granted
00015  * without fee, provided the above notices are retained on all copies.
00016  * Permission to modify the code and to distribute modified code is granted,
00017  * provided the above notices are retained, and a notice that the code was
00018  * modified is included with the above copyright notice.
00019  *
00020  */
00021 
00022 #ifndef _STLP_STRING_BASE_H
00023 #define _STLP_STRING_BASE_H
00024 
00025 // ------------------------------------------------------------
00026 // Class _String_base.
00027 
00028 // _String_base is a helper class that makes it it easier to write an
00029 // exception-safe version of basic_string.  The constructor allocates,
00030 // but does not initialize, a block of memory.  The destructor
00031 // deallocates, but does not destroy elements within, a block of
00032 // memory.  The destructor assumes that _M_start either is null, or else
00033 // points to a block of memory that was allocated using _String_base's
00034 // allocator and whose size is _M_end_of_storage - _M_start_of_storage._M_data.
00035 
00036 _STLP_BEGIN_NAMESPACE
00037 
00038 _STLP_MOVE_TO_PRIV_NAMESPACE
00039 
00040 template <class _Tp, class _Alloc>
00041 class _String_base {
00042     typedef _String_base<_Tp, _Alloc> _Self;
00043 protected:
00044   _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
00045 public:
00046   //dums: Some compiler(MSVC6) require it to be public not simply protected!
00047   enum {_DEFAULT_SIZE = 4 * sizeof( void * )};
00048   //This is needed by the full move framework
00049   typedef _Alloc allocator_type;
00050   typedef _STLP_alloc_proxy<_Tp*, _Tp, allocator_type> _AllocProxy;
00051   typedef size_t size_type;
00052 private:
00053 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00054   union _Buffers {
00055     _Tp*  _M_end_of_storage;
00056     _Tp   _M_static_buf[_DEFAULT_SIZE];
00057   } _M_buffers;
00058 #else
00059   _Tp*    _M_end_of_storage;
00060 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00061 protected:
00062 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00063   bool _M_using_static_buf() const
00064   { return (_M_start_of_storage._M_data == _M_buffers._M_static_buf); }
00065   _Tp const* _M_Start() const { return _M_start_of_storage._M_data; }
00066   _Tp* _M_Start() { return _M_start_of_storage._M_data; }
00067   _Tp const* _M_End() const
00068   { return _M_using_static_buf() ? _M_buffers._M_static_buf + _DEFAULT_SIZE : _M_buffers._M_end_of_storage; }
00069   _Tp* _M_End()
00070   { return _M_using_static_buf() ? _M_buffers._M_static_buf + _DEFAULT_SIZE : _M_buffers._M_end_of_storage; }
00071   size_type _M_capacity() const
00072   { return _M_using_static_buf() ? _DEFAULT_SIZE : _M_buffers._M_end_of_storage - _M_start_of_storage._M_data; }
00073   size_type _M_rest() const
00074   { return  _M_using_static_buf() ? _DEFAULT_SIZE - (_M_finish - _M_buffers._M_static_buf) : _M_buffers._M_end_of_storage - _M_finish; }
00075 #else
00076   _Tp const* _M_Start() const { return _M_start_of_storage._M_data; }
00077   _Tp* _M_Start() { return _M_start_of_storage._M_data; }
00078   _Tp const* _M_End() const { return _M_end_of_storage; }
00079   _Tp* _M_End() { return _M_end_of_storage; }
00080   size_type _M_capacity() const
00081   { return _M_end_of_storage - _M_start_of_storage._M_data; }
00082   size_type _M_rest() const
00083   { return _M_end_of_storage - _M_finish; }
00084 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00085 
00086   _Tp*    _M_finish;
00087   _AllocProxy _M_start_of_storage;
00088 
00089   _Tp const* _M_Finish() const {return _M_finish;}
00090   _Tp* _M_Finish() {return _M_finish;}
00091 
00092   // Precondition: 0 < __n <= max_size().
00093   void _M_allocate_block(size_t __n = _DEFAULT_SIZE);
00094   void _M_deallocate_block() {
00095 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00096     if (!_M_using_static_buf() && (_M_start_of_storage._M_data != 0))
00097       _M_start_of_storage.deallocate(_M_start_of_storage._M_data, _M_buffers._M_end_of_storage - _M_start_of_storage._M_data);
00098 #else
00099     if (_M_start_of_storage._M_data != 0)
00100       _M_start_of_storage.deallocate(_M_start_of_storage._M_data, _M_end_of_storage - _M_start_of_storage._M_data);
00101 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00102   }
00103 
00104   size_t max_size() const {
00105     const size_type __string_max_size = size_type(-1) / sizeof(_Tp);
00106     typename allocator_type::size_type __alloc_max_size = _M_start_of_storage.max_size();
00107     return (min)(__alloc_max_size, __string_max_size) - 1;
00108   }
00109 
00110   _String_base(const allocator_type& __a)
00111 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00112     : _M_finish(_M_buffers._M_static_buf), _M_start_of_storage(__a, _M_buffers._M_static_buf)
00113 #else
00114     : _M_end_of_storage(0), _M_finish(0), _M_start_of_storage(__a, (_Tp*)0)
00115 #endif
00116     {}
00117 
00118   _String_base(const allocator_type& __a, size_t __n)
00119 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00120     : _M_finish(_M_buffers._M_static_buf), _M_start_of_storage(__a, _M_buffers._M_static_buf) {
00121 #else
00122     : _M_end_of_storage(0), _M_finish(0), _M_start_of_storage(__a, (_Tp*)0) {
00123 #endif
00124       _M_allocate_block(__n);
00125     }
00126 
00127 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00128   void _M_move_src (_Self &src) {
00129     if (src._M_using_static_buf()) {
00130       _M_buffers = src._M_buffers;
00131       _M_finish = _M_buffers._M_static_buf + (src._M_finish - src._M_start_of_storage._M_data);
00132       _M_start_of_storage._M_data = _M_buffers._M_static_buf;
00133     }
00134     else {
00135       _M_start_of_storage._M_data = src._M_start_of_storage._M_data;
00136       _M_finish = src._M_finish;
00137       _M_buffers._M_end_of_storage = src._M_buffers._M_end_of_storage;
00138       src._M_start_of_storage._M_data = 0;
00139     }
00140   }
00141 #endif
00142 
00143 #if !defined (_STLP_NO_MOVE_SEMANTIC)
00144   _String_base(__move_source<_Self> src)
00145 #  if defined (_STLP_USE_SHORT_STRING_OPTIM)
00146     : _M_start_of_storage(__move_source<_AllocProxy>(src.get()._M_start_of_storage)) {
00147       _M_move_src(src.get());
00148 #  else
00149     : _M_end_of_storage(src.get()._M_end_of_storage), _M_finish(src.get()._M_finish),
00150       _M_start_of_storage(__move_source<_AllocProxy>(src.get()._M_start_of_storage)) {
00151       src.get()._M_start_of_storage._M_data = 0;
00152 #  endif
00153     }
00154 #endif
00155 
00156   ~_String_base() { _M_deallocate_block(); }
00157 
00158   void _M_reset(_Tp *__start, _Tp *__finish, _Tp *__end_of_storage) {
00159 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00160     _M_buffers._M_end_of_storage = __end_of_storage;
00161 #else
00162     _M_end_of_storage = __end_of_storage;
00163 #endif
00164     _M_finish = __finish;
00165     _M_start_of_storage._M_data = __start;
00166   }
00167 
00168   void _M_swap(_Self &__s) {
00169 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00170     if (_M_using_static_buf()) {
00171       if (__s._M_using_static_buf()) {
00172         _STLP_STD::swap(_M_buffers, __s._M_buffers);
00173         _Tp *__tmp = _M_finish;
00174         _M_finish = _M_start_of_storage._M_data + (__s._M_finish - __s._M_start_of_storage._M_data);
00175         __s._M_finish = __s._M_buffers._M_static_buf + (__tmp - _M_start_of_storage._M_data);
00176         //We need to swap _M_start_of_storage for allocators with state:
00177         _M_start_of_storage.swap(__s._M_start_of_storage);
00178         _M_start_of_storage._M_data = _M_buffers._M_static_buf;
00179         __s._M_start_of_storage._M_data = __s._M_buffers._M_static_buf;
00180       } else {
00181         __s._M_swap(*this);
00182         return;
00183       }
00184     }
00185     else if (__s._M_using_static_buf()) {
00186       _Tp *__tmp = _M_start_of_storage._M_data;
00187       _Tp *__tmp_finish = _M_finish;
00188       _Tp *__tmp_end_data = _M_buffers._M_end_of_storage;
00189       _M_buffers = __s._M_buffers;
00190       //We need to swap _M_start_of_storage for allocators with state:
00191       _M_start_of_storage.swap(__s._M_start_of_storage);
00192       _M_start_of_storage._M_data = _M_buffers._M_static_buf;
00193       _M_finish = _M_buffers._M_static_buf + (__s._M_finish - __s._M_buffers._M_static_buf);
00194       __s._M_buffers._M_end_of_storage = __tmp_end_data;
00195       __s._M_start_of_storage._M_data = __tmp;
00196       __s._M_finish = __tmp_finish;
00197     }
00198     else {
00199       _STLP_STD::swap(_M_buffers._M_end_of_storage, __s._M_buffers._M_end_of_storage);
00200       _M_start_of_storage.swap(__s._M_start_of_storage);
00201       _STLP_STD::swap(_M_finish, __s._M_finish);
00202     }
00203 #else
00204     _STLP_STD::swap(_M_end_of_storage, __s._M_end_of_storage);
00205     _M_start_of_storage.swap(__s._M_start_of_storage);
00206     _STLP_STD::swap(_M_finish, __s._M_finish);
00207 #endif
00208   }
00209 
00210   void _STLP_FUNCTION_THROWS _M_throw_length_error() const;
00211   void _STLP_FUNCTION_THROWS _M_throw_out_of_range() const;
00212 };
00213 
00214 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00215 _STLP_EXPORT_TEMPLATE_CLASS _String_base<char, allocator<char> >;
00216 #  if defined (_STLP_HAS_WCHAR_T)
00217 _STLP_EXPORT_TEMPLATE_CLASS _String_base<wchar_t, allocator<wchar_t> >;
00218 #  endif
00219 #endif /* _STLP_USE_TEMPLATE_EXPORT */
00220 
00221 _STLP_MOVE_TO_STD_NAMESPACE
00222 
00223 _STLP_END_NAMESPACE
00224 
00225 #endif /* _STLP_STRING_BASE_H */
00226 
00227 /*
00228  * Local Variables:
00229  * mode:C++
00230  * End:
00231  */

Generated on Sat May 26 2012 04:28:13 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.