📄 xiosbase
字号:
void __CLR_OR_THIS_CALL setstate(iostate _State, bool _Exreraise)
{ // merge in state argument, possibly reraise exception
if (_State != goodbit)
clear((iostate)((int)rdstate() | (int)_State), _Exreraise);
}
void __CLR_OR_THIS_CALL setstate(iostate _State)
{ // merge in state argument
if (_State != goodbit)
clear((iostate)((int)rdstate() | (int)_State), false);
}
void __CLR_OR_THIS_CALL setstate(io_state _State)
{ // merge in state argument, old style
setstate((iostate)_State);
}
bool __CLR_OR_THIS_CALL good() const
{ // test if no state bits are set
return (rdstate() == goodbit);
}
bool __CLR_OR_THIS_CALL eof() const
{ // test if eofbit is set in stream state
return ((int)rdstate() & (int)eofbit);
}
bool __CLR_OR_THIS_CALL fail() const
{ // test if badbit or failbit is set in stream state
return (((int)rdstate()
& ((int)badbit | (int)failbit)) != 0);
}
bool __CLR_OR_THIS_CALL bad() const
{ // test if badbit is set in stream state
return (((int)rdstate() & (int)badbit) != 0);
}
iostate __CLR_OR_THIS_CALL exceptions() const
{ // return exception mask
return (_Except);
}
void __CLR_OR_THIS_CALL exceptions(iostate _Newexcept)
{ // set exception mask to argument
_Except = (iostate)((int)_Newexcept & (int)_Statmask);
clear(_Mystate);
}
void __CLR_OR_THIS_CALL exceptions(io_state _State)
{ // set exception mask to argument, old style
exceptions((iostate)_State);
}
fmtflags __CLR_OR_THIS_CALL flags() const
{ // return format flags
return (_Fmtfl);
}
fmtflags __CLR_OR_THIS_CALL flags(fmtflags _Newfmtflags)
{ // set format flags to argument
fmtflags _Oldfmtflags = _Fmtfl;
_Fmtfl = (fmtflags)((int)_Newfmtflags & (int)_Fmtmask);
return (_Oldfmtflags);
}
fmtflags __CLR_OR_THIS_CALL setf(fmtflags _Newfmtflags)
{ // merge in format flags argument
ios_base::fmtflags _Oldfmtflags = _Fmtfl;
_Fmtfl = (fmtflags)((int)_Fmtfl
| (int)_Newfmtflags & (int)_Fmtmask);
return (_Oldfmtflags);
}
fmtflags __CLR_OR_THIS_CALL setf(fmtflags _Newfmtflags, fmtflags _Mask)
{ // merge in format flags argument under mask argument
ios_base::fmtflags _Oldfmtflags = _Fmtfl;
_Fmtfl = (fmtflags)(((int)_Fmtfl & (int)~_Mask)
| ((int)_Newfmtflags & (int)_Mask & (int)_Fmtmask));
return (_Oldfmtflags);
}
void __CLR_OR_THIS_CALL unsetf(fmtflags _Mask)
{ // clear format flags under mask argument
_Fmtfl = (fmtflags)((int)_Fmtfl & (int)~_Mask);
}
streamsize __CLR_OR_THIS_CALL precision() const
{ // return precision
return (_Prec);
}
streamsize __CLR_OR_THIS_CALL precision(streamsize _Newprecision)
{ // set precision to argument
streamsize _Oldprecision = _Prec;
_Prec = _Newprecision;
return (_Oldprecision);
}
streamsize __CLR_OR_THIS_CALL width() const
{ // return width
return (_Wide);
}
streamsize __CLR_OR_THIS_CALL width(streamsize _Newwidth)
{ // set width to argument
streamsize _Oldwidth = _Wide;
_Wide = _Newwidth;
return (_Oldwidth);
}
locale __CLR_OR_THIS_CALL getloc() const
{ // get locale
return (*_Ploc);
}
locale __CLR_OR_THIS_CALL imbue(const locale& _Loc)
{ // set locale to argument
locale _Oldlocale = *_Ploc;
*_Ploc = _Loc;
_Callfns(imbue_event);
return (_Oldlocale);
}
static int __CLRCALL_OR_CDECL xalloc()
{ // allocate new iword/pword index
_BEGIN_LOCK(_LOCK_STREAM) // lock thread to ensure atomicity
return (_Index++);
_END_LOCK()
}
long& __CLR_OR_THIS_CALL iword(int _Idx)
{ // return reference to long element
return (_Findarr(_Idx)._Lo);
}
void *& __CLR_OR_THIS_CALL pword(int _Idx)
{ // return reference to pointer element
return (_Findarr(_Idx)._Vp);
}
void __CLR_OR_THIS_CALL register_callback(event_callback _Pfn,
int _Idx)
{ // register event handler
_Calls = _NEW_CRT _Fnarray(_Idx, _Pfn, _Calls);
}
ios_base& __CLR_OR_THIS_CALL copyfmt(const ios_base& _Other)
{ // copy format stuff
if (this != &_Other)
{ // copy all but _Mystate
_Tidy();
*_Ploc = *_Other._Ploc;
_Fmtfl = _Other._Fmtfl;
_Prec = _Other._Prec;
_Wide = _Other._Wide;
_Iosarray *_Ptr = _Other._Arr;
for (_Arr = 0; _Ptr != 0; _Ptr = _Ptr->_Next)
if (_Ptr->_Lo != 0 || _Ptr->_Vp != 0)
{ // copy over nonzero array values
iword(_Ptr->_Index) = _Ptr->_Lo;
pword(_Ptr->_Index) = _Ptr->_Vp;
}
for (_Fnarray *_Pfa = _Other._Calls; _Pfa != 0;
_Pfa = _Pfa->_Next)
register_callback(_Pfa->_Pfn, _Pfa->_Index);
_Callfns(copyfmt_event); // call callbacks
exceptions(_Other._Except); // cause any throw at end
}
return (*this);
}
static bool __CLRCALL_OR_CDECL sync_with_stdio(bool _Newsync = true)
{ // set C/C++ synchronization flag from argument
_BEGIN_LOCK(_LOCK_STREAM) // lock thread to ensure atomicity
const bool _Oldsync = _Sync;
_Sync = _Newsync;
return (_Oldsync);
_END_LOCK()
}
void __CLR_OR_THIS_CALL swap(ios_base& _Right)
{ // swap with _Right
if (this != &_Right)
{ // different, do the move
_STD swap(_Mystate, _Right._Mystate);
_STD swap(_Except, _Right._Except);
_STD swap(_Fmtfl, _Right._Fmtfl);
_STD swap(_Prec, _Right._Prec);
_STD swap(_Wide, _Right._Wide);
_STD swap(_Arr, _Right._Arr);
_STD swap(_Calls, _Right._Calls);
_STD swap(_Ploc, _Right._Ploc);
}
}
virtual __CLR_OR_THIS_CALL ~ios_base() // destroy the object
{ // destroy the object
_Ios_base_dtor(this);
}
static _MRTIMP2_PURE_NPURE void __CLRCALL_PURE_OR_CDECL _Addstd(ios_base *); // add standard stream
size_t _Stdstr; // if > 0 index of standard stream to suppress destruction
protected:
__CLR_OR_THIS_CALL ios_base()
{ // default constructor
}
void __CLR_OR_THIS_CALL _Init()
{ // initialize a new ios_base
_Ploc = 0;
_Stdstr = 0;
_Except = goodbit;
_Fmtfl = (fmtflags)(skipws | dec);
_Prec = 6;
_Wide = 0;
_Arr = 0;
_Calls = 0;
clear(goodbit);
_Ploc = _NEW_CRT locale;
}
private:
// STRUCT _Iosarray
struct _Iosarray
{ // list element for open-ended sparse array of longs/pointers
public:
__CLR_OR_THIS_CALL _Iosarray(int _Idx, _Iosarray *_Link)
: _Next(_Link), _Index(_Idx), _Lo(0), _Vp(0)
{ // construct node for index _Idx and link it in
}
_Iosarray *_Next; // pointer to next node
int _Index; // index of this node
long _Lo; // stored long value
void *_Vp; // stored pointer value
};
// STRUCT _Fnarray
struct _Fnarray
{ // list element for open-ended sparse array of event handlers
__CLR_OR_THIS_CALL _Fnarray(int _Idx, event_callback _Pnew, _Fnarray *_Link)
: _Next(_Link), _Index(_Idx), _Pfn(_Pnew)
{ // construct node for index _Idx and link it in
}
_Fnarray *_Next; // pointer to next node
int _Index; // index of this node
event_callback _Pfn; // pointer to event handler
};
void __CLR_OR_THIS_CALL _Callfns(event _Ev)
{ // call all event handlers, reporting event
for (_Fnarray *_Pfa = _Calls; _Pfa != 0; _Pfa = _Pfa->_Next)
(*_Pfa->_Pfn)(_Ev, *this, _Pfa->_Index);
}
_Iosarray& __CLR_OR_THIS_CALL _Findarr(int _Idx)
{ // locate or make a variable array element
_Iosarray *_Ptr1, *_Ptr2;
for (_Ptr1 = _Arr, _Ptr2 = 0; _Ptr1 != 0; _Ptr1 = _Ptr1->_Next)
if (_Ptr1->_Index == _Idx)
return (*_Ptr1); // found element, return it
else if (_Ptr2 == 0 && _Ptr1->_Lo == 0 && _Ptr1->_Vp == 0)
_Ptr2 = _Ptr1; // found recycling candidate
if (_Ptr2 != 0)
{ // recycle existing element
_Ptr2->_Index = _Idx;
return (*_Ptr2);
}
_Arr = _NEW_CRT _Iosarray(_Idx, _Arr); // make a new element
return (*_Arr);
}
void __CLR_OR_THIS_CALL _Tidy()
{ // discard storage for an ios_base
_Callfns(erase_event);
_Iosarray *_Ptr1, *_Ptr2;
for (_Ptr1 = _Arr; _Ptr1 != 0; _Ptr1 = _Ptr2)
{ // delete array element
_Ptr2 = _Ptr1->_Next;
_DELETE_CRT(_Ptr1);
}
_Arr = 0;
_Fnarray *_Pfa1, *_Pfa2;
for (_Pfa1 = _Calls; _Pfa1 != 0; _Pfa1 = _Pfa2)
{ // delete callback element
_Pfa2 = _Pfa1->_Next;
_DELETE_CRT(_Pfa1);
}
_Calls = 0;
}
iostate _Mystate; // stream state
iostate _Except; // exception mask
fmtflags _Fmtfl; // format flags
streamsize _Prec; // field precision
streamsize _Wide; // field width
_Iosarray *_Arr; // pointer to first node of long/pointer array
_Fnarray *_Calls; // pointer to first node of call list
locale *_Ploc; // pointer to locale
__PURE_APPDOMAIN_GLOBAL static int _Index;
__PURE_APPDOMAIN_GLOBAL static bool _Sync;
static _MRTIMP2_PURE_NPURE void __CLRCALL_PURE_OR_CDECL _Ios_base_dtor(ios_base *);
};
_BITMASK_OPS(ios_base::_Fmtflags)
_BITMASK_OPS(ios_base::_Iostate)
_BITMASK_OPS(ios_base::_Openmode)
_BITMASK_OPS(ios_base::_Seekdir)
_STD_END
#pragma pop_macro("new")
#pragma warning(pop)
#pragma pack(pop)
#endif /* RC_INVOKED */
#endif /* _XIOSBASE_ */
/*
* Copyright (c) 1992-2009 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
V5.20:0009 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -