1 |
786 |
skrzyp |
// This file is part of the uSTL library, an STL implementation.
|
2 |
|
|
//
|
3 |
|
|
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
|
4 |
|
|
// This file is free software, distributed under the MIT License.
|
5 |
|
|
|
6 |
|
|
#ifndef UIOS_H_630C16E316F7650E3A02E1C6611B789A
|
7 |
|
|
#define UIOS_H_630C16E316F7650E3A02E1C6611B789A
|
8 |
|
|
|
9 |
|
|
#include "utypes.h"
|
10 |
|
|
|
11 |
|
|
namespace ustl {
|
12 |
|
|
|
13 |
|
|
class file_exception;
|
14 |
|
|
|
15 |
|
|
const char endl = '\n'; ///< End of line character.
|
16 |
|
|
const char ends = '\0'; ///< End of string character.
|
17 |
|
|
|
18 |
|
|
/// Defines types and constants used by all stream classes.
|
19 |
|
|
class ios_base {
|
20 |
|
|
public:
|
21 |
|
|
/// Used to set parameters for stringstreams
|
22 |
|
|
enum fmtflags {
|
23 |
|
|
boolalpha = (1 << 0), ///< Boolean values printed as text.
|
24 |
|
|
dec = (1 << 1), ///< Decimal number output.
|
25 |
|
|
fixed = (1 << 2), ///< Fixed-point float output.
|
26 |
|
|
hex = (1 << 3), ///< Hexadecimal number output.
|
27 |
|
|
internal = (1 << 4),
|
28 |
|
|
left = (1 << 5), ///< Left alignment.
|
29 |
|
|
oct = (1 << 6), ///< Octal number output.
|
30 |
|
|
right = (1 << 7), ///< Right alignment.
|
31 |
|
|
scientific = (1 << 8), ///< Scientific float format.
|
32 |
|
|
showbase = (1 << 9), ///< Add 0x or 0 prefixes on hex and octal numbers.
|
33 |
|
|
showpoint = (1 << 10), ///< Print decimal point.
|
34 |
|
|
showpos = (1 << 11),
|
35 |
|
|
skipws = (1 << 12), ///< Skip whitespace when reading.
|
36 |
|
|
unitbuf = (1 << 13),
|
37 |
|
|
uppercase = (1 << 14),
|
38 |
|
|
adjustfield = (1 << 15),
|
39 |
|
|
basefield = (1 << 16),
|
40 |
|
|
floatfield = (1 << 17)
|
41 |
|
|
};
|
42 |
|
|
/// For file-based streams, specifies fd mode.
|
43 |
|
|
enum openmode_bits {
|
44 |
|
|
in = (1 << 0),
|
45 |
|
|
out = (1 << 1),
|
46 |
|
|
app = (1 << 2),
|
47 |
|
|
ate = (1 << 3),
|
48 |
|
|
binary = (1 << 4),
|
49 |
|
|
trunc = (1 << 5),
|
50 |
|
|
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
51 |
|
|
nonblock= (1 << 6),
|
52 |
|
|
nocreate= (1 << 7),
|
53 |
|
|
noctty = (1 << 8),
|
54 |
|
|
nombits = 9
|
55 |
|
|
#endif
|
56 |
|
|
};
|
57 |
|
|
/// Seek directions, equivalent to SEEK_SET, SEEK_CUR, and SEEK_END.
|
58 |
|
|
enum seekdir {
|
59 |
|
|
beg,
|
60 |
|
|
cur,
|
61 |
|
|
end
|
62 |
|
|
};
|
63 |
|
|
/// I/O state bitmasks.
|
64 |
|
|
enum iostate_bits {
|
65 |
|
|
goodbit = 0,
|
66 |
|
|
badbit = (1 << 0),
|
67 |
|
|
eofbit = (1 << 1),
|
68 |
|
|
failbit = (1 << 2),
|
69 |
|
|
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
70 |
|
|
nbadbits = 3,
|
71 |
|
|
allbadbits = 0x7
|
72 |
|
|
#endif
|
73 |
|
|
};
|
74 |
|
|
|
75 |
|
|
typedef uint32_t openmode; ///< Holds openmode_bits.
|
76 |
|
|
typedef uint32_t iostate; ///< Holds iostate_bits for a file stream.
|
77 |
|
|
typedef file_exception failure; ///< Thrown by fstream on errors.
|
78 |
|
|
|
79 |
|
|
static const char c_DefaultDelimiters [16]; ///< Default word delimiters for stringstreams.
|
80 |
|
|
public:
|
81 |
|
|
inline ios_base (void) : m_State (goodbit), m_Exceptions (allbadbits) {}
|
82 |
|
|
inline iostate rdstate (void) const { return (m_State); }
|
83 |
|
|
inline bool bad (void) const { return (rdstate() & badbit); }
|
84 |
|
|
inline bool good (void) const { return (rdstate() == goodbit); }
|
85 |
|
|
inline bool fail (void) const { return (rdstate() & (badbit | failbit)); }
|
86 |
|
|
inline bool eof (void) const { return (rdstate() & eofbit); }
|
87 |
|
|
inline bool operator! (void) const { return (fail()); }
|
88 |
|
|
inline operator void* (void) const { return (reinterpret_cast<void*>(!fail())); }
|
89 |
|
|
inline void clear (iostate v = goodbit) { m_State = v; }
|
90 |
|
|
inline void setstate (iostate v) { m_State |= v; }
|
91 |
|
|
inline iostate exceptions (void) const { return (m_Exceptions); }
|
92 |
|
|
inline iostate exceptions (iostate v) { return (m_Exceptions = v); }
|
93 |
|
|
protected:
|
94 |
|
|
inline bool set_and_throw (iostate v) { setstate(v); return (exceptions() & v); }
|
95 |
|
|
void overrun (const char* op, const char* type, uint32_t n, uint32_t p, uint32_t rem);
|
96 |
|
|
private:
|
97 |
|
|
uint16_t m_State; ///< Open state, using ios::iostate_bits.
|
98 |
|
|
uint16_t m_Exceptions; ///< Exception flags, using ios::iostate_bits.
|
99 |
|
|
};
|
100 |
|
|
|
101 |
|
|
} // namespace ustl
|
102 |
|
|
|
103 |
|
|
#endif
|