Subversion Repositories spk

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#ifndef EXT_STREAM_INCLUDED
2
#define EXT_STREAM_INCLUDED
3
 
4
namespace ext {
5
 
6
class stream_base
7
{
8
	public:
9
		enum state
10
		{
11
			goodbit=0,
12
			failbit=1,
13
			eofbit=2,
14
			badbit=4
15
		};
16
 
17
	private:
18
		int m_state;
19
		int m_flags;
20
 
21
	public:
22
		stream_base() { m_flags=0; clear(goodbit); }
23
		virtual ~stream_base() { }
24
 
25
		void clear(state s) { m_state=s; }
26
 
27
		int setstate(state s)
28
		{
29
			int old=m_state;
30
			m_state|=s;
31
			return old;
32
		}
33
 
34
		int rdstate() const { return m_state; }
35
 
36
		bool good() const { return rdstate() == goodbit; }
37
		bool bad() const { return (rdstate() & badbit) > 0; }
38
		bool fail() const { return ((rdstate() & (failbit | badbit))!=0); }
39
		bool eof() const { return (rdstate() & eofbit) > 0; }
40
 
41
		int flags() const	{	return m_flags;	}
42
 
43
		int flags(int newflags)
44
		{
45
			int old=m_flags;
46
			m_flags = newflags;
47
			return old;
48
		}
49
 
50
		int setf(int newflags)
51
		{
52
			int old=m_flags;
53
			m_flags|=newflags;
54
			return old;
55
		}
56
 
57
		void unsetf(int mask)	{	m_flags&=~mask;	}
58
};
59
 
60
}
61
 
62
#endif // !defined(EXT_STREAM_INCLUDED)