Helper to handle stdin and fstream uniformly
| 357 | |
| 358 | /// Helper to handle stdin and fstream uniformly |
| 359 | class InputStream { |
| 360 | std::string filepath; |
| 361 | std::istream* activeStream = nullptr; |
| 362 | std::ifstream file; // Unused for stdin/stdout |
| 363 | std::stringstream stdinBuffer; |
| 364 | |
| 365 | public: |
| 366 | InputStream(const std::string& filepath, Reporter& report); |
| 367 | |
| 368 | const std::string& str() { |
| 369 | return filepath; |
| 370 | } |
| 371 | |
| 372 | /*explicit(false)*/ operator std::istream&() { |
| 373 | return *activeStream; |
| 374 | } |
| 375 | |
| 376 | std::istream* operator->() { |
| 377 | return activeStream; |
| 378 | } |
| 379 | std::istream& operator*() { |
| 380 | return *activeStream; |
| 381 | } |
| 382 | }; |
| 383 | |
| 384 | /// Helper to handle stdout and fstream uniformly |
| 385 | class OutputStream { |