windows-nt/Source/XPSP1/NT/base/crts/crtw32/stdhpp/xiosbase

446 lines
12 KiB
Plaintext
Raw Normal View History

2020-09-26 03:20:57 -05:00
// xiosbase internal header (from <ios>)
#pragma once
#ifndef _XIOSBASE_
#define _XIOSBASE_
#include <xlocale>
#pragma pack(push,8)
#pragma warning(push,3)
_STD_BEGIN
// TEMPLATE CLASS _Iosb
template<class _Dummy>
class _Iosb
{ // define templatized bitmask/enumerated types, instantiate on demand
public:
enum _Dummy_enum {_Dummy_enum_val = 1}; // don't ask
enum _Fmtflags
{ // constants for formatting options
_Fmtmask = 0x7fff, _Fmtzero = 0};
_BITMASK(_Fmtflags, fmtflags);
static const _Fmtflags skipws = (_Fmtflags)0x0001;
static const _Fmtflags unitbuf = (_Fmtflags)0x0002;
static const _Fmtflags uppercase = (_Fmtflags)0x0004;
static const _Fmtflags showbase = (_Fmtflags)0x0008;
static const _Fmtflags showpoint = (_Fmtflags)0x0010;
static const _Fmtflags showpos = (_Fmtflags)0x0020;
static const _Fmtflags left = (_Fmtflags)0x0040;
static const _Fmtflags right = (_Fmtflags)0x0080;
static const _Fmtflags internal = (_Fmtflags)0x0100;
static const _Fmtflags dec = (_Fmtflags)0x0200;
static const _Fmtflags oct = (_Fmtflags)0x0400;
static const _Fmtflags hex = (_Fmtflags)0x0800;
static const _Fmtflags scientific = (_Fmtflags)0x1000;
static const _Fmtflags fixed = (_Fmtflags)0x2000;
static const _Fmtflags boolalpha = (_Fmtflags)0x4000;
static const _Fmtflags adjustfield = (_Fmtflags)0x01c0;
static const _Fmtflags basefield = (_Fmtflags)0x0e00;
static const _Fmtflags floatfield = (_Fmtflags)0x3000;
enum _Iostate
{ // constants for stream states
_Statmask = 0x7};
_BITMASK(_Iostate, iostate);
static const _Iostate goodbit = (_Iostate)0x0;
static const _Iostate eofbit = (_Iostate)0x1;
static const _Iostate failbit = (_Iostate)0x2;
static const _Iostate badbit = (_Iostate)0x4;
enum _Openmode
{ // constants for file opening options
_Openmask = 0x3f};
_BITMASK(_Openmode, openmode);
static const _Openmode in = (_Openmode)0x01;
static const _Openmode out = (_Openmode)0x02;
static const _Openmode ate = (_Openmode)0x04;
static const _Openmode app = (_Openmode)0x08;
static const _Openmode trunc = (_Openmode)0x10;
static const _Openmode binary = (_Openmode)0x20;
enum _Seekdir
{ // constants for file positioning options
_Seekmask = 0x3};
_BITMASK(_Seekdir, seekdir);
static const _Seekdir beg = (_Seekdir)0;
static const _Seekdir cur = (_Seekdir)1;
static const _Seekdir end = (_Seekdir)2;
};
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::skipws;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::unitbuf;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::uppercase;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::showbase;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::showpoint;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::showpos;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::left;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::right;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::internal;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::dec;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::oct;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::hex;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::scientific;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::fixed;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::boolalpha;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::adjustfield;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::basefield;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::floatfield;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::goodbit;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::eofbit;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::failbit;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::badbit;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::in;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::out;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::ate;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::app;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::trunc;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::binary;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Seekdir _Iosb<_Dummy>::beg;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Seekdir _Iosb<_Dummy>::cur;
template<class _Dummy>
const typename _Iosb<_Dummy>::_Seekdir _Iosb<_Dummy>::end;
// CLASS ios_base
class _CRTIMP2 ios_base
: public _Iosb<int>
{ // base class for ios
public:
typedef std::streamoff streamoff;
typedef std::streampos streampos;
enum event
{ // constants for ios events
erase_event, imbue_event, copyfmt_event};
typedef void (__cdecl *event_callback)(event, ios_base&, int);
typedef unsigned int io_state, open_mode, seek_dir;
// CLASS failure
class failure
: public runtime_error
{ // base of all iostreams exceptions
public:
explicit failure(const string &_Message)
: runtime_error(_Message)
{ // construct with message
}
virtual ~failure()
{ // destroy the object
}
protected:
virtual void _Doraise() const
{ // report the exception
_RAISE(*this);
}
};
// CLASS Init
class _CRTIMP2 Init
{ // controller for standard-stream initialization
public:
Init(); // initialize standard streams on first construction
~Init(); // flush standard streams on last destruction
private:
static int _Init_cnt; // net constructions - destructions
};
ios_base& operator=(const ios_base& _Right)
{ // assign state and format stuff from _Right
if (this != &_Right)
{ // worth doing
_Mystate = _Right._Mystate;
copyfmt(_Right);
}
return (*this);
}
operator void *() const
{ // test if any stream operation has failed
return (fail() ? 0 : (void *)this);
}
bool operator!() const
{ // test if no stream operation has failed
return (fail());
}
void clear(iostate, bool); // set state, possibly reraise exception
void clear(iostate _State = goodbit)
{ // set state to argument
clear(_State, false);
}
void clear(io_state _State)
{ // set state to argument, old-style
clear((iostate)_State);
}
iostate rdstate() const
{ // return stream state
return (_Mystate);
}
void setstate(iostate _State, bool _Exreraise)
{ // merge in state argument, possibly reraise exception
if (_State != goodbit)
clear((iostate)((int)rdstate() | (int)_State), _Exreraise);
}
void setstate(iostate _State)
{ // merge in state argument
if (_State != goodbit)
clear((iostate)((int)rdstate() | (int)_State), false);
}
void setstate(io_state _State)
{ // merge in state argument, old style
setstate((iostate)_State);
}
bool good() const
{ // test if no state bits are set
return (rdstate() == goodbit);
}
bool eof() const
{ // test if eofbit is set in stream state
return ((int)rdstate() & (int)eofbit);
}
bool fail() const
{ // test if badbit or failbit is set in stream state
return (((int)rdstate()
& ((int)badbit | (int)failbit)) != 0);
}
bool bad() const
{ // test if badbit is set in stream state
return (((int)rdstate() & (int)badbit) != 0);
}
iostate exceptions() const
{ // return exception mask
return (_Except);
}
void exceptions(iostate _Newexcept)
{ // set exception mask to argument
_Except = (iostate)((int)_Newexcept & (int)_Statmask);
clear(_Mystate);
}
void exceptions(io_state _State)
{ // set exception mask to argument, old style
exceptions((iostate)_State);
}
fmtflags flags() const
{ // return format flags
return (_Fmtfl);
}
fmtflags flags(fmtflags _Newfmtflags)
{ // set format flags to argument
fmtflags _Oldfmtflags = _Fmtfl;
_Fmtfl = (fmtflags)((int)_Newfmtflags & (int)_Fmtmask);
return (_Oldfmtflags);
}
fmtflags setf(fmtflags _Newfmtflags)
{ // merge in format flags argument
ios_base::fmtflags _Oldfmtflags = _Fmtfl;
_Fmtfl = (fmtflags)((int)_Fmtfl
| (int)_Newfmtflags & (int)_Fmtmask);
return (_Oldfmtflags);
}
fmtflags 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 unsetf(fmtflags _Mask)
{ // clear format flags under mask argument
_Fmtfl = (fmtflags)((int)_Fmtfl & (int)~_Mask);
}
streamsize precision() const
{ // return precision
return (_Prec);
}
streamsize precision(streamsize _Newprecision)
{ // set precision to argument
streamsize _Oldprecision = _Prec;
_Prec = _Newprecision;
return (_Oldprecision);
}
streamsize width() const
{ // return width
return (_Wide);
}
streamsize width(streamsize _Newwidth)
{ // set width to argument
streamsize _Oldwidth = _Wide;
_Wide = _Newwidth;
return (_Oldwidth);
}
locale getloc() const
{ // get locale
return (*_Ploc);
}
locale imbue(const locale&); // set locale to argument
static int __cdecl xalloc()
{ // allocate new iword/pword index
_Lockit _Lock(_LOCK_STREAM); // lock thread to ensure atomicity
return (_Index++);
}
long& iword(int _Idx)
{ // return reference to long element
return (_Findarr(_Idx)._Lo);
}
void *& pword(int _Idx)
{ // return reference to pointer element
return (_Findarr(_Idx)._Vp);
}
void register_callback(event_callback, int); // register event handler
ios_base& copyfmt(const ios_base&); // copy format stuff
virtual ~ios_base(); // destroy the object
static bool __cdecl sync_with_stdio(bool _Newsync = true)
{ // set C/C++ synchronization flag from argument
_Lockit _Lock(_LOCK_STREAM); // lock thread to ensure atomicity
const bool _Oldsync = _Sync;
_Sync = _Newsync;
return (_Oldsync);
}
void _Addstd(); // add this to list of standard streams
protected:
ios_base()
: _Stdstr(0)
{ // default constructor
}
void _Init(); // initialize to standard values
private:
// STRUCT _Iosarray
struct _Iosarray
{ // list element for open-ended sparse array of longs/pointers
public:
_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
_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 _Callfns(event); // call all event handlers, reporting event
_Iosarray& _Findarr(int); // find an array element
void _Tidy(); // free allocated storage
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
size_t _Stdstr; // if > 0 index of standard stream to suppress destruction
static int _Index; // source of unique indexes for long/pointer array
static bool _Sync; // C/C++ synchronization flag (ignored)
};
_BITMASK_OPS(ios_base::_Fmtflags)
_BITMASK_OPS(ios_base::_Iostate)
_BITMASK_OPS(ios_base::_Openmode)
_BITMASK_OPS(ios_base::_Seekdir)
_STD_END
#pragma warning(pop)
#pragma pack(pop)
#endif /* _XIOSBASE_ */
/*
* Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
V3.10:0009 */