1 | /*
|
---|
2 | * Copyright (c) 2017 Jaroslav Jindrak
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef LIBCPP_IOS
|
---|
30 | #define LIBCPP_IOS
|
---|
31 |
|
---|
32 | #include <cstdlib>
|
---|
33 | #include <locale>
|
---|
34 | #include <system_error>
|
---|
35 |
|
---|
36 | namespace std
|
---|
37 | {
|
---|
38 | using streamoff = long long;
|
---|
39 | using streamsize = ssize_t;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * 27.5.3, ios_base:
|
---|
43 | */
|
---|
44 |
|
---|
45 | class ios_base
|
---|
46 | {
|
---|
47 | public:
|
---|
48 | virtual ~ios_base();
|
---|
49 |
|
---|
50 | ios_base(const ios_base&) = delete;
|
---|
51 | ios_base& operator=(const ios_base&) = delete;
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * 27.5.3.1.1, failure:
|
---|
55 | */
|
---|
56 |
|
---|
57 | class failure: public system_error
|
---|
58 | {
|
---|
59 | // TODO: implement
|
---|
60 | };
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * 27.5.3.1.2, fmtflags:
|
---|
64 | */
|
---|
65 |
|
---|
66 | using fmtflags = uint32_t;
|
---|
67 | static constexpr fmtflags boolalpha = 0b00'0000'0000'0000'0001;
|
---|
68 | static constexpr fmtflags dec = 0b00'0000'0000'0000'0010;
|
---|
69 | static constexpr fmtflags fixed = 0b00'0000'0000'0000'0100;
|
---|
70 | static constexpr fmtflags hex = 0b00'0000'0000'0000'1000;
|
---|
71 | static constexpr fmtflags internal = 0b00'0000'0000'0001'0000;
|
---|
72 | static constexpr fmtflags left = 0b00'0000'0000'0010'0000;
|
---|
73 | static constexpr fmtflags oct = 0b00'0000'0000'0100'0000;
|
---|
74 | static constexpr fmtflags right = 0b00'0000'0000'1000'0000;
|
---|
75 | static constexpr fmtflags scientific = 0b00'0000'0001'0000'0000;
|
---|
76 | static constexpr fmtflags showbase = 0b00'0000'0010'0000'0000;
|
---|
77 | static constexpr fmtflags showpoint = 0b00'0000'0100'0000'0000;
|
---|
78 | static constexpr fmtflags showpos = 0b00'0000'1000'0000'0000;
|
---|
79 | static constexpr fmtflags skipws = 0b00'0001'0000'0000'0000;
|
---|
80 | static constexpr fmtflags unitbuf = 0b00'0010'0000'0000'0000;
|
---|
81 | static constexpr fmtflags uppercase = 0b00'0100'0000'0000'0000;
|
---|
82 | static constexpr fmtflags adjustfield = 0b00'1000'0000'0000'0000;
|
---|
83 | static constexpr fmtflags basefield = 0b01'0000'0000'0000'0000;
|
---|
84 | static constexpr fmtflags floatfield = 0b10'0000'0000'0000'0000;
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * 27.5.3.1.3, iostate:
|
---|
88 | */
|
---|
89 |
|
---|
90 | using iostate = uint8_t;
|
---|
91 | static constexpr iostate badbit = 0b0001;
|
---|
92 | static constexpr iostate eofbit = 0b0010;
|
---|
93 | static constexpr iostate failbit = 0b0100;
|
---|
94 | static constexpr iostate goodbit = 0b1000;
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * 27.5.3.1.4, openmode:
|
---|
98 | */
|
---|
99 |
|
---|
100 | using openmode = uint8_t;
|
---|
101 | static constexpr openmode app = 0b00'0001;
|
---|
102 | static constexpr openmode ate = 0b00'0010;
|
---|
103 | static constexpr openmode binary = 0b00'0100;
|
---|
104 | static constexpr openmode in = 0b00'1000;
|
---|
105 | static constexpr openmode out = 0b01'0000;
|
---|
106 | static constexpr openmode trunc = 0b10'0000;
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * 27.5.3.1.5, seekdir:
|
---|
110 | */
|
---|
111 |
|
---|
112 | using seekdir = uint8_t;
|
---|
113 | static constexpr seekdir beg = 0b001;
|
---|
114 | static constexpr seekdir cur = 0b010;
|
---|
115 | static constexpr seekdir end = 0b100;
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * 27.5.3.1.6, class Init:
|
---|
119 | */
|
---|
120 |
|
---|
121 | class Init
|
---|
122 | {
|
---|
123 | // TODO: implement
|
---|
124 | };
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * 27.5.3.2, fmtflags state:
|
---|
128 | */
|
---|
129 |
|
---|
130 | fmtflags flags() const;
|
---|
131 | fmtflags flags(fmtflags fmtfl);
|
---|
132 | fmtflags setf(fmtflags fmtfl);
|
---|
133 | fmtflags setf(fmtflags fmtfl, fmtflags mask);
|
---|
134 | void unsetf(fmtflags mask);
|
---|
135 |
|
---|
136 | streamsize precision() const;
|
---|
137 | streamsize precision(streamsize prec);
|
---|
138 | streamsize width() const;
|
---|
139 | streamsize width(streamsize wide);
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * 27.5.3.3, locales:
|
---|
143 | */
|
---|
144 |
|
---|
145 | locale imbue(const locale& loc);
|
---|
146 | locale getloc() const;
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * 27.5.3.5, storage:
|
---|
150 | */
|
---|
151 |
|
---|
152 | static int xalloc();
|
---|
153 | long& iword(int index);
|
---|
154 | void*& pword(int index);
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * 27.5.3.6, callbacks:
|
---|
158 | */
|
---|
159 |
|
---|
160 | enum event
|
---|
161 | {
|
---|
162 | erase_event,
|
---|
163 | imbue_event,
|
---|
164 | copyfmt_event
|
---|
165 | };
|
---|
166 |
|
---|
167 | using event_callback = void (*)(event, ios_base&, int);
|
---|
168 | void register_callback(event_callback fn, int index);
|
---|
169 |
|
---|
170 | static bool sync_with_stdio(bool sync = true);
|
---|
171 |
|
---|
172 | protected:
|
---|
173 | ios_base();
|
---|
174 |
|
---|
175 | private:
|
---|
176 | static int index_{};
|
---|
177 |
|
---|
178 | long* iarray_;
|
---|
179 | void** parray_;
|
---|
180 | };
|
---|
181 | }
|
---|
182 |
|
---|
183 | #endif
|
---|