Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.2 KiB

  1. // ios_base -- ios_base basic members
  2. #include <new>
  3. #include <xiosbase>
  4. #include <xstddef>
  5. _STD_BEGIN
  6. #define NSTDSTR 8 /* cin, wcin, etc. */
  7. extern _CRTIMP2 const fpos_t _Fpz;
  8. int ios_base::_Index = 0;
  9. bool ios_base::_Sync = true;
  10. const fpos_t _Fpz = {0};
  11. static ios_base *stdstr[NSTDSTR + 1] = {0};
  12. static char stdopens[NSTDSTR + 1] = {0};
  13. void ios_base::clear(iostate ns, bool ex)
  14. { // clear all but selected state bits
  15. _State = (iostate)(ns & _Statmask);
  16. if ((_State & _Except) == 0)
  17. ;
  18. else if (ex)
  19. _RERAISE;
  20. else
  21. _THROW(failure,
  22. _State & _Except & badbit ? "ios::badbit set"
  23. : _State & _Except & failbit ? "ios::failbit set"
  24. : "ios::eofbit set");
  25. }
  26. ios_base& ios_base::copyfmt(const ios_base& rhs)
  27. { // copy format info from another ios_base
  28. if (this != &rhs)
  29. { // copy all but _State
  30. _Tidy();
  31. _Loc = rhs._Loc;
  32. _Fmtfl = rhs._Fmtfl;
  33. _Prec = rhs._Prec;
  34. _Wide = rhs._Wide;
  35. _Iosarray *p = rhs._Arr;
  36. for (_Arr = 0; p != 0; p = p->_Next)
  37. if (p->_Lo != 0 || p->_Vp != 0)
  38. { // copy over nonzero array values
  39. iword(p->_Index) = p->_Lo;
  40. pword(p->_Index) = p->_Vp;
  41. }
  42. _Callfns(copyfmt_event);
  43. exceptions(rhs._Except); // cause any throw at end
  44. }
  45. return (*this);
  46. }
  47. locale ios_base::imbue(const locale& _Ln)
  48. { // imbue a new locale into stream
  49. locale _Lo = _Loc;
  50. _Loc = _Ln;
  51. _Callfns(imbue_event);
  52. return (_Lo);
  53. }
  54. void ios_base::register_callback(event_callback _P, int _Idx)
  55. { // register a callback function
  56. if ((_Calls = new _Fnarray(_Idx, _P, _Calls)) == 0)
  57. _Nomemory();
  58. }
  59. ios_base::~ios_base()
  60. { // destruct an ios_base
  61. if (0 < _Stdstr && 0 < --stdopens[_Stdstr])
  62. return;
  63. _Tidy();
  64. }
  65. void ios_base::_Callfns(event ev)
  66. { // call registered functions
  67. _Fnarray *p;
  68. for (p = _Calls; p != 0; p = p->_Next)
  69. (*p->_Pfn)(ev, *this, p->_Index);
  70. }
  71. ios_base::_Iosarray& ios_base::_Findarr(int idx)
  72. { // locate or make a variable array element
  73. _Iosarray *p, *q;
  74. if (idx < 0)
  75. _THROW(failure, "invalid ios::iword/pword index");
  76. for (p = _Arr, q = 0; p != 0; p = p->_Next)
  77. if (p->_Index == idx)
  78. return (*p);
  79. else if (q == 0 && p->_Lo == 0 && p->_Vp == 0)
  80. q = p;
  81. if (q != 0)
  82. { // recycle existing element
  83. q->_Index = idx;
  84. return (*q);
  85. }
  86. if ((_Arr = new _Iosarray(idx, _Arr)) == 0)
  87. _Nomemory();
  88. return (*_Arr);
  89. }
  90. void ios_base::_Addstd()
  91. { // add standard stream to destructor list
  92. _Lockit _Lk;
  93. for (; _Stdstr < NSTDSTR; ++_Stdstr)
  94. if (stdstr[_Stdstr] == 0 || stdstr[_Stdstr] == this)
  95. break;
  96. stdstr[_Stdstr] = this;
  97. ++stdopens[_Stdstr];
  98. }
  99. void ios_base::_Init()
  100. { // initialize a new ios_base
  101. new (&_Loc) locale;
  102. _Except = goodbit;
  103. _Fmtfl = skipws | dec;
  104. _Prec = 6;
  105. _Wide = 0;
  106. _Arr = 0;
  107. _Calls = 0;
  108. clear(goodbit);
  109. }
  110. void ios_base::_Tidy()
  111. { // discard storage for an ios_base
  112. _Callfns(erase_event);
  113. _Iosarray *q1, *q2;
  114. for (q1 = _Arr; q1 != 0; q1 = q2)
  115. q2 = q1->_Next, delete q1;
  116. _Arr = 0;
  117. _Fnarray *q3, *q4;
  118. for (q3 = _Calls; q3 != 0; q3 = q4)
  119. q4 = q3->_Next, delete q3;
  120. _Calls = 0;
  121. }
  122. _STD_END
  123. /*
  124. * Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
  125. * Consult your license regarding permissions and restrictions.
  126. */