Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenios.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 00019 #include "stlport_prefix.h" 00020 00021 #include <algorithm> 00022 #include <ios> 00023 #include <locale> 00024 #include <ostream> // for __get_ostreambuf definition 00025 00026 #include "aligned_buffer.h" 00027 00028 _STLP_BEGIN_NAMESPACE 00029 00030 //---------------------------------------------------------------------- 00031 // ios_base members 00032 00033 // class ios_base::failure, a subclass of exception. It's used solely 00034 // for reporting errors. 00035 00036 ios_base::failure::failure(const string& s) 00037 : __Named_exception(s) 00038 {} 00039 00040 ios_base::failure::~failure() _STLP_NOTHROW_INHERENTLY {} 00041 00042 #if !defined (_STLP_STATIC_CONST_INIT_BUG) && !defined (_STLP_NO_STATIC_CONST_DEFINITION) 00043 // Definitions of ios_base's formatting flags. 00044 const ios_base::fmtflags ios_base::left; 00045 const ios_base::fmtflags ios_base::right; 00046 const ios_base::fmtflags ios_base::internal; 00047 const ios_base::fmtflags ios_base::dec; 00048 const ios_base::fmtflags ios_base::hex; 00049 const ios_base::fmtflags ios_base::oct; 00050 const ios_base::fmtflags ios_base::fixed; 00051 const ios_base::fmtflags ios_base::scientific; 00052 const ios_base::fmtflags ios_base::boolalpha; 00053 const ios_base::fmtflags ios_base::showbase; 00054 const ios_base::fmtflags ios_base::showpoint; 00055 const ios_base::fmtflags ios_base::showpos; 00056 const ios_base::fmtflags ios_base::skipws; 00057 const ios_base::fmtflags ios_base::unitbuf; 00058 const ios_base::fmtflags ios_base::uppercase; 00059 const ios_base::fmtflags ios_base::adjustfield; 00060 const ios_base::fmtflags ios_base::basefield; 00061 const ios_base::fmtflags ios_base::floatfield; 00062 00063 // Definitions of ios_base's state flags. 00064 const ios_base::iostate ios_base::goodbit; 00065 const ios_base::iostate ios_base::badbit; 00066 const ios_base::iostate ios_base::eofbit; 00067 const ios_base::iostate ios_base::failbit; 00068 00069 // Definitions of ios_base's openmode flags. 00070 const ios_base::openmode ios_base::app; 00071 const ios_base::openmode ios_base::ate; 00072 const ios_base::openmode ios_base::binary; 00073 const ios_base::openmode ios_base::in; 00074 const ios_base::openmode ios_base::out; 00075 const ios_base::openmode ios_base::trunc; 00076 00077 // Definitions of ios_base's seekdir flags. 00078 const ios_base::seekdir ios_base::beg; 00079 const ios_base::seekdir ios_base::cur; 00080 const ios_base::seekdir ios_base::end; 00081 00082 #endif 00083 00084 // Internal functions used for managing exponentially-growing arrays of 00085 // POD types. 00086 00087 // array is a pointer to N elements of type PODType. Expands the array, 00088 // if necessary, so that array[index] is meaningful. All new elements are 00089 // initialized to zero. Returns a pointer to the new array, and the new 00090 // size. 00091 00092 template <class PODType> 00093 static pair<PODType*, size_t> 00094 _Stl_expand_array(PODType* __array, size_t N, int index) { 00095 if ((int)N < index + 1) { 00096 size_t new_N = (max)(2 * N, size_t(index + 1)); 00097 PODType* new_array 00098 = __STATIC_CAST(PODType*,realloc(__array, new_N * sizeof(PODType))); 00099 if (new_array) { 00100 fill(new_array + N, new_array + new_N, PODType()); 00101 return pair<PODType*, size_t>(new_array, new_N); 00102 } 00103 else 00104 return pair<PODType*, size_t>(__STATIC_CAST(PODType*,0), 0); 00105 } 00106 else 00107 return pair<PODType*, size_t>(__array, N); 00108 } 00109 00110 // array is a pointer to N elements of type PODType. Allocate a new 00111 // array of N elements, copying the values from the old array to the new. 00112 // Return a pointer to the new array. It is assumed that array is non-null 00113 // and N is nonzero. 00114 template <class PODType> 00115 static PODType* _Stl_copy_array(const PODType* __array, size_t N) { 00116 PODType* result = __STATIC_CAST(PODType*,malloc(N * sizeof(PODType))); 00117 if (result) 00118 copy(__array, __array + N, result); 00119 return result; 00120 } 00121 00122 locale ios_base::imbue(const locale& loc) { 00123 if (loc != _M_locale) { 00124 locale previous = _M_locale; 00125 _M_locale = loc; 00126 _M_invoke_callbacks(imbue_event); 00127 return previous; 00128 } 00129 else { 00130 _M_invoke_callbacks(imbue_event); 00131 return _M_locale; 00132 } 00133 } 00134 00135 int _STLP_CALL ios_base::xalloc() { 00136 #if defined (_STLP_THREADS) && \ 00137 defined (_STLP_WIN32THREADS) && defined (_STLP_NEW_PLATFORM_SDK) 00138 static volatile __stl_atomic_t _S_index = 0; 00139 return _STLP_ATOMIC_INCREMENT(&_S_index); 00140 #else 00141 static int _S_index = 0; 00142 static _STLP_STATIC_MUTEX __lock _STLP_MUTEX_INITIALIZER; 00143 _STLP_auto_lock sentry(__lock); 00144 return _S_index++; 00145 #endif 00146 } 00147 00148 long& ios_base::iword(int index) { 00149 static long dummy = 0; 00150 00151 pair<long*, size_t> tmp = _Stl_expand_array(_M_iwords, _M_num_iwords, index); 00152 if (tmp.first) { // The allocation, if any, succeeded. 00153 _M_iwords = tmp.first; 00154 _M_num_iwords = tmp.second; 00155 return _M_iwords[index]; 00156 } 00157 else { 00158 _M_setstate_nothrow(badbit); 00159 _M_check_exception_mask(); 00160 return dummy; 00161 } 00162 } 00163 00164 00165 void*& ios_base::pword(int index) { 00166 static void* dummy = 0; 00167 00168 pair<void**, size_t> tmp = _Stl_expand_array(_M_pwords, _M_num_pwords, index); 00169 if (tmp.first) { // The allocation, if any, succeeded. 00170 _M_pwords = tmp.first; 00171 _M_num_pwords = tmp.second; 00172 return _M_pwords[index]; 00173 } 00174 else { 00175 _M_setstate_nothrow(badbit); 00176 _M_check_exception_mask(); 00177 return dummy; 00178 } 00179 } 00180 00181 void ios_base::register_callback(event_callback __fn, int index) { 00182 pair<pair<event_callback, int>*, size_t> tmp 00183 = _Stl_expand_array(_M_callbacks, _M_num_callbacks, (int)_M_callback_index /* fbp: index ??? */ ); 00184 if (tmp.first) { 00185 _M_callbacks = tmp.first; 00186 _M_num_callbacks = tmp.second; 00187 _M_callbacks[_M_callback_index++] = make_pair(__fn, index); 00188 } 00189 else { 00190 _M_setstate_nothrow(badbit); 00191 _M_check_exception_mask(); 00192 } 00193 } 00194 00195 // Invokes all currently registered callbacks for a particular event. 00196 // Behaves correctly even if one of the callbacks adds a new callback. 00197 void ios_base::_M_invoke_callbacks(event E) { 00198 for (size_t i = _M_callback_index; i > 0; --i) { 00199 event_callback f = _M_callbacks[i-1].first; 00200 int n = _M_callbacks[i-1].second; 00201 f(E, *this, n); 00202 } 00203 } 00204 00205 // This function is called if the state, rdstate(), has a bit set 00206 // that is also set in the exception mask exceptions(). 00207 void ios_base::_M_throw_failure() { 00208 const char* arg ; 00209 # if 0 00210 char buffer[256]; 00211 char* ptr; 00212 strcpy(buffer, "ios failure: rdstate = 0x"); 00213 ptr = __write_integer(buffer+strlen(buffer), ios_base::hex, __STATIC_CAST(unsigned long,_M_iostate)); 00214 strcpy(ptr, " mask = 0x"); 00215 ptr = __write_integer(buffer+strlen(buffer), ios_base::hex, __STATIC_CAST(unsigned long,_M_exception_mask)); 00216 *ptr = 0; 00217 arg = buffer; 00218 # else 00219 arg = "ios failure"; 00220 # endif 00221 00222 # ifndef _STLP_USE_EXCEPTIONS 00223 fputs(arg, stderr); 00224 # else 00225 throw failure(arg); 00226 # endif 00227 } 00228 00229 // Copy x's state to *this. This member function is used in the 00230 // implementation of basic_ios::copyfmt. Does not copy _M_exception_mask 00231 // or _M_iostate. 00232 void ios_base::_M_copy_state(const ios_base& x) { 00233 _M_fmtflags = x._M_fmtflags; // Copy the flags, except for _M_iostate 00234 _M_openmode = x._M_openmode; // and _M_exception_mask. 00235 _M_seekdir = x._M_seekdir; 00236 _M_precision = x._M_precision; 00237 _M_width = x._M_width; 00238 _M_locale = x._M_locale; 00239 00240 if (x._M_callbacks) { 00241 pair<event_callback, int>* tmp = _Stl_copy_array(x._M_callbacks, x._M_callback_index); 00242 if (tmp) { 00243 free(_M_callbacks); 00244 _M_callbacks = tmp; 00245 _M_num_callbacks = _M_callback_index = x._M_callback_index; 00246 } 00247 else { 00248 _M_setstate_nothrow(badbit); 00249 _M_check_exception_mask(); 00250 } 00251 } 00252 00253 if (x._M_iwords) { 00254 long* tmp = _Stl_copy_array(x._M_iwords, x._M_num_iwords); 00255 if (tmp) { 00256 free(_M_iwords); 00257 _M_iwords = tmp; 00258 _M_num_iwords = x._M_num_iwords; 00259 } 00260 else { 00261 _M_setstate_nothrow(badbit); 00262 _M_check_exception_mask(); 00263 } 00264 } 00265 00266 if (x._M_pwords) { 00267 void** tmp = _Stl_copy_array(x._M_pwords, x._M_num_pwords); 00268 if (tmp) { 00269 free(_M_pwords); 00270 _M_pwords = tmp; 00271 _M_num_pwords = x._M_num_pwords; 00272 } 00273 else { 00274 _M_setstate_nothrow(badbit); 00275 _M_check_exception_mask(); 00276 } 00277 } 00278 } 00279 00280 // ios's (protected) default constructor. The standard says that all 00281 // fields have indeterminate values; we initialize them to zero for 00282 // simplicity. The only thing that really matters is that the arrays 00283 // are all initially null pointers, and the array element counts are all 00284 // initially zero. 00285 ios_base::ios_base() 00286 : _M_fmtflags(0), _M_iostate(0), _M_openmode(0), _M_seekdir(0), 00287 _M_exception_mask(0), 00288 _M_precision(0), _M_width(0), 00289 _M_locale(), 00290 _M_callbacks(0), _M_num_callbacks(0), _M_callback_index(0), 00291 _M_iwords(0), _M_num_iwords(0), 00292 _M_pwords(0), 00293 _M_num_pwords(0) 00294 {} 00295 00296 // ios's destructor. 00297 ios_base::~ios_base() { 00298 _M_invoke_callbacks(erase_event); 00299 free(_M_callbacks); 00300 free(_M_iwords); 00301 free(_M_pwords); 00302 } 00303 00304 //---------------------------------------------------------------------- 00305 // Force instantiation of basic_ios 00306 // For DLL exports, they are already instantiated. 00307 #if !defined(_STLP_NO_FORCE_INSTANTIATE) 00308 template class _STLP_CLASS_DECLSPEC basic_ios<char, char_traits<char> >; 00309 # if !defined (_STLP_NO_WCHAR_T) 00310 template class _STLP_CLASS_DECLSPEC basic_ios<wchar_t, char_traits<wchar_t> >; 00311 # endif /* _STLP_NO_WCHAR_T */ 00312 #endif 00313 00314 _STLP_END_NAMESPACE 00315 00316 // Local Variables: 00317 // mode:C++ 00318 // End: Generated on Fri May 25 2012 04:33:40 for ReactOS by
1.7.6.1
|