[f7aaffe0] | 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_ISTREAM
|
---|
| 30 | #define LIBCPP_ISTREAM
|
---|
| 31 |
|
---|
| 32 | #include <iosfwd>
|
---|
[a9caea1] | 33 | #include <utility>
|
---|
[f7aaffe0] | 34 |
|
---|
| 35 | namespace std
|
---|
| 36 | {
|
---|
[b0d6e2a] | 37 |
|
---|
| 38 | /**
|
---|
| 39 | * 27.7.2.1, class template basic_stream:
|
---|
| 40 | */
|
---|
| 41 |
|
---|
[f7aaffe0] | 42 | template<class Char, class Traits = char_traits<Char>>
|
---|
[b0d6e2a] | 43 | class basic_istream: virtual public basic_ios<Char, Traits>
|
---|
| 44 | {
|
---|
| 45 | public:
|
---|
| 46 | using traits_type = Traits;
|
---|
| 47 | using char_type = Char;
|
---|
| 48 | using int_type = typename traits_type::int_type;
|
---|
| 49 | using pos_type = typename traits_type::pos_type;
|
---|
| 50 | using off_type = typename traits_type::off_type;
|
---|
| 51 |
|
---|
| 52 | /**
|
---|
| 53 | * 27.7.2.1.1, constructor/destructor:
|
---|
| 54 | */
|
---|
| 55 |
|
---|
| 56 | explicit basic_istream(basic_streambuf<Char, Traits>* sb)
|
---|
[a9caea1] | 57 | : gcount_{0}
|
---|
[b0d6e2a] | 58 | {
|
---|
[a9caea1] | 59 | basic_ios::init(sb);
|
---|
[b0d6e2a] | 60 | }
|
---|
| 61 |
|
---|
| 62 | virtual ~basic_stream()
|
---|
[a9caea1] | 63 | { /* DUMMY BODY */ }
|
---|
[b0d6e2a] | 64 |
|
---|
| 65 | /**
|
---|
| 66 | * 27.7.2.1.3, prefix/suffix:
|
---|
| 67 | */
|
---|
| 68 |
|
---|
[a9caea1] | 69 | class sentry
|
---|
| 70 | {
|
---|
| 71 | public:
|
---|
| 72 | explicit sentry(basic_istream<Char, Traits>& is, bool noskipws = false)
|
---|
| 73 | : ok_{false}
|
---|
| 74 | {
|
---|
| 75 | if (!is.good())
|
---|
| 76 | is.setstate(ios_base::failbit);
|
---|
| 77 | else
|
---|
| 78 | {
|
---|
| 79 | if (is.tie())
|
---|
| 80 | is.tie()->flush();
|
---|
| 81 |
|
---|
| 82 | if (!noskipws && ((is.flags() & ios_base::skipws) != 0))
|
---|
| 83 | {
|
---|
| 84 | // TODO: implement when we have istream_iterator and locale,
|
---|
| 85 | // skip whitespace using is.locale()
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | ~sentry() = default;
|
---|
| 91 |
|
---|
| 92 | explicit operator bool() const
|
---|
| 93 | {
|
---|
| 94 | return ok_;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | sentry(const sentry&) = delete;
|
---|
| 98 | sentry& operator=(const sentry&) = delete;
|
---|
| 99 |
|
---|
| 100 | private:
|
---|
| 101 | using traits_type = Traits;
|
---|
| 102 | bool ok_;
|
---|
| 103 | }
|
---|
[b0d6e2a] | 104 |
|
---|
| 105 | /**
|
---|
| 106 | * 27.7.2.2, formatted input:
|
---|
| 107 | */
|
---|
| 108 |
|
---|
| 109 | basic_istream<Char, Traits> operator>>(
|
---|
| 110 | basic_istream<Char, Traits>& (*pf)(basic_istream<Char, Traits>&)
|
---|
| 111 | )
|
---|
| 112 | {
|
---|
| 113 | // TODO: implement
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | basic_istream<Char, Traits> operator>>(
|
---|
| 117 | basic_ios<Char, Traits>& (*pf)(basic_ios<Char, Traits>&)
|
---|
| 118 | )
|
---|
| 119 | {
|
---|
| 120 | // TODO: implement
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | basic_istream<Char, Traits> operator>>(
|
---|
| 124 | ios_base& (*pf)(ios_base&)
|
---|
| 125 | )
|
---|
| 126 | {
|
---|
| 127 | // TODO: implement
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | basic_istream<Char, Traits> operator>>(bool& x)
|
---|
| 131 | {
|
---|
| 132 | // TODO: implement
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | basic_istream<Char, Traits> operator>>(short& x)
|
---|
| 136 | {
|
---|
| 137 | // TODO: implement
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | basic_istream<Char, Traits> operator>>(unsigned short& x)
|
---|
| 141 | {
|
---|
| 142 | // TODO: implement
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | basic_istream<Char, Traits> operator>>(int& x)
|
---|
| 146 | {
|
---|
| 147 | // TODO: implement
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | basic_istream<Char, Traits> operator>>(unsigned int& x)
|
---|
| 151 | {
|
---|
| 152 | // TODO: implement
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | basic_istream<Char, Traits> operator>>(long& x)
|
---|
| 156 | {
|
---|
| 157 | // TODO: implement
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | basic_istream<Char, Traits> operator>>(unsigned long& x)
|
---|
| 161 | {
|
---|
| 162 | // TODO: implement
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | basic_istream<Char, Traits> operator>>(long long& x)
|
---|
| 166 | {
|
---|
| 167 | // TODO: implement
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | basic_istream<Char, Traits> operator>>(unsigned long long& x)
|
---|
| 171 | {
|
---|
| 172 | // TODO: implement
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | basic_istream<Char, Traits> operator>>(float& x)
|
---|
| 176 | {
|
---|
| 177 | // TODO: implement
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | basic_istream<Char, Traits> operator>>(double& x)
|
---|
| 181 | {
|
---|
| 182 | // TODO: implement
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | basic_istream<Char, Traits> operator>>(long double& x)
|
---|
| 186 | {
|
---|
| 187 | // TODO: implement
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | basic_istream<Char, Traits> operator>>(void*& p)
|
---|
| 191 | {
|
---|
| 192 | // TODO: implement
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | basic_istream<Char, Traits> operator>>(basic_streambuf<Char, Traits>* sb)
|
---|
| 196 | {
|
---|
| 197 | // TODO: implement
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | /**
|
---|
| 201 | * 27.7.2.3, unformatted input:
|
---|
| 202 | */
|
---|
| 203 |
|
---|
| 204 | streamsize gcount() const
|
---|
| 205 | {
|
---|
[a9caea1] | 206 | return gcount_;
|
---|
[b0d6e2a] | 207 | }
|
---|
| 208 |
|
---|
| 209 | int_type get()
|
---|
| 210 | {
|
---|
| 211 | // TODO: implement
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | basic_istream<Char, Traits>& get(char_type& c)
|
---|
| 215 | {
|
---|
| 216 | // TODO: implement
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | basic_istream<Char, Traits>& get(char_type* s, streamsize n)
|
---|
| 220 | {
|
---|
| 221 | // TODO: implement
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | basic_istream<Char, Traits>& get(char_type* s, streamsize n, char_type delim)
|
---|
| 225 | {
|
---|
| 226 | // TODO: implement
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | basic_istream<Char, Traits>& get(basic_streambuf<Char, Traits>& sb)
|
---|
| 230 | {
|
---|
| 231 | // TODO: implement
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | basic_istream<Char, Traits>& get(basic_streambuf<Char, Traits>& sb, char_type delim)
|
---|
| 235 | {
|
---|
| 236 | // TODO: implement
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | basic_istream<Char, Traits>& getline(char_type* s, streamsize n)
|
---|
| 240 | {
|
---|
| 241 | // TODO: implement
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | basic_istream<Char, Traits>& getline(char_type* s, streamsize n, char_type delim)
|
---|
| 245 | {
|
---|
| 246 | // TODO: implement
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | basic_istream<Char, Traits>& ignore(streamsize n = 1, int_type delim = traits_type::eof())
|
---|
| 250 | {
|
---|
| 251 | // TODO: implement
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | int_type peek()
|
---|
| 255 | {
|
---|
| 256 | // TODO: implement
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | basic_istream<Char, Traits>& read(char_type* s, streamsize n)
|
---|
| 260 | {
|
---|
| 261 | // TODO: implement
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | streamsize readsome(char_type* s, streamsize n)
|
---|
| 265 | {
|
---|
| 266 | // TODO: implement
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | basic_istream<Char, Traits>& putback(char_type c)
|
---|
| 270 | {
|
---|
| 271 | // TODO: implement
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | basic_istream<Char, Traits>& unget()
|
---|
| 275 | {
|
---|
| 276 | // TODO: implement
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | int sync()
|
---|
| 280 | {
|
---|
| 281 | // TODO: implement
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | pos_type tellg()
|
---|
| 285 | {
|
---|
| 286 | // TODO: implement
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | basic_istream<Char, Traits>& seekg(pos_type pos)
|
---|
| 290 | {
|
---|
| 291 | // TODO: implement
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | basic_istream<Char, Traits>& seekg(off_type off, ios_base::seekdir way)
|
---|
| 295 | {
|
---|
| 296 | // TODO: implement
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | protected:
|
---|
[a9caea1] | 300 | streamsize gcount_;
|
---|
| 301 |
|
---|
[b0d6e2a] | 302 | basic_istream(const basic_istream&) = delete;
|
---|
| 303 |
|
---|
| 304 | basic_istream(basic_istream&& rhs)
|
---|
| 305 | {
|
---|
[a9caea1] | 306 | gcount_ = rhs.gcout_;
|
---|
| 307 |
|
---|
| 308 | basic_ios::move(rhs);
|
---|
| 309 |
|
---|
| 310 | rhs.gcount_ = 0;
|
---|
[b0d6e2a] | 311 | }
|
---|
| 312 |
|
---|
| 313 | /**
|
---|
| 314 | * 27.7.2.1.2, assign/swap:
|
---|
| 315 | */
|
---|
| 316 |
|
---|
| 317 | basic_istream& operator=(const basic_istream& rhs) = delete;
|
---|
| 318 |
|
---|
| 319 | basic_istream& operator=(basic_istream&& rhs)
|
---|
| 320 | {
|
---|
[a9caea1] | 321 | swap(rhs);
|
---|
| 322 |
|
---|
| 323 | return *this;
|
---|
[b0d6e2a] | 324 | }
|
---|
| 325 |
|
---|
| 326 | void swap(basic_stream& rhs)
|
---|
| 327 | {
|
---|
[a9caea1] | 328 | basic_ios::swap(rhs);
|
---|
| 329 | swap(gcoung_, rhs.gcount_);
|
---|
[b0d6e2a] | 330 | }
|
---|
| 331 | };
|
---|
| 332 |
|
---|
| 333 | /**
|
---|
| 334 | * 27.7.2.2.3, character extraction templates:
|
---|
| 335 | */
|
---|
| 336 |
|
---|
| 337 | template<class Char, class Traits>
|
---|
| 338 | basic_istream<Char, Traits>& operator>>(basic_istream<Char, Traits>& is,
|
---|
| 339 | Char& c)
|
---|
| 340 | {
|
---|
| 341 | // TODO: implement
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | template<class Char, class Traits>
|
---|
| 345 | basic_istream<Char, Traits>& operator>>(basic_istream<Char, Traits>& is,
|
---|
| 346 | unsigned char& c)
|
---|
| 347 | {
|
---|
| 348 | // TODO: implement
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | template<class Char, class Traits>
|
---|
| 352 | basic_istream<Char, Traits>& operator>>(basic_istream<Char, Traits>& is,
|
---|
| 353 | signed char& c)
|
---|
| 354 | {
|
---|
| 355 | // TODO: implement
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | template<class Char, class Traits>
|
---|
| 359 | basic_istream<Char, Traits>& operator>>(basic_istream<Char, Traits>& is,
|
---|
| 360 | Char* c)
|
---|
| 361 | {
|
---|
| 362 | // TODO: implement
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | template<class Char, class Traits>
|
---|
| 366 | basic_istream<Char, Traits>& operator>>(basic_istream<Char, Traits>& is,
|
---|
| 367 | unsigned char* c)
|
---|
| 368 | {
|
---|
| 369 | // TODO: implement
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | template<class Char, class Traits>
|
---|
| 373 | basic_istream<Char, Traits>& operator>>(basic_istream<Char, Traits>& is,
|
---|
| 374 | signed char* c)
|
---|
| 375 | {
|
---|
| 376 | // TODO: implement
|
---|
| 377 | }
|
---|
[f7aaffe0] | 378 |
|
---|
| 379 | using istream = basic_istream<char>;
|
---|
| 380 | using wistream = basic_istream<wchar_t>;
|
---|
| 381 |
|
---|
| 382 | template<class Char, class Traits = char_traits<Char>>
|
---|
| 383 | class basic_iostream;
|
---|
| 384 |
|
---|
| 385 | using iostream = basic_iostream<char>;
|
---|
| 386 | using wiostream = basic_iostream<wchar_t>;
|
---|
| 387 |
|
---|
| 388 | template<class Char, class Traits = char_traits<Char>>
|
---|
| 389 | basic_istream<Char, Traits>& ws(basic_istream<Char, Traits>& is);
|
---|
| 390 |
|
---|
| 391 | template<class Char, class Tratis = char_traits<Char>>
|
---|
| 392 | basic_istream<Char, Traits>& operator>>(basic_istream<Char, Traits>& is, T& x);
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | #endif
|
---|