Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
istream.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <istream>
27#include <concepts>
28#include <memory>
29
30namespace ext {
31
32class istream {
33 std::unique_ptr < std::istream > m_os;
34
35public:
36 istream ( std::basic_streambuf < char > * sb );
37
38 virtual ~istream ( ) noexcept;
39
40protected:
41 istream ( istream && rhs ) noexcept;
42
43 istream & operator = ( istream && rhs ) noexcept;
44
45public:
46 template < class T >
47 requires requires { std::declval < std::istream > ( ) << std::declval < T > ( ); }
48 friend istream & operator >> ( istream & os, const T & val ) {
49 static_cast < std::istream & > ( os ) >> val;
50 return os;
51 }
52
53 friend istream & operator >> ( istream & os, std::istream & ( * fn ) ( std::istream & ) );
54
55 friend istream & operator >> ( istream & os, std::ios_base & ( * fn ) ( std::ios_base & ) );
56
57protected:
58 operator std::istream & ( ) &;
59
60 operator const std::istream & ( ) const &;
61
62public:
63 int peek ( );
64
65 int get ( );
66
67 istream & get ( char & ch );
68
69 istream & unget ( );
70
71 istream & putback ( char ch );
72
73 istream & read ( char * s, std::streamsize count );
74
75 std::streampos tellg ( );
76
77 istream & seekg ( std::streampos pos );
78
79 istream & seekg ( std::streamoff off, std::ios_base::seekdir dir );
80
81 istream & sync ( );
82
83 std::streambuf * rdbuf ( ) const;
84
85 std::streambuf * rdbuf ( std::streambuf * buf );
86
87 void setstate ( std::ios_base::iostate state );
88
89 void clear ( std::ios_base::iostate state = std::ios_base::goodbit );
90
91 bool good ( ) const;
92
93 bool fail ( ) const;
94
95 bool eof ( ) const;
96
97 operator bool ( ) const;
98};
99
109ext::istream & operator >> ( ext::istream & in, const std::string & str );
110
111} /* namespace ext */
112
Definition: istream.h:32
bool eof() const
Definition: istream.cpp:112
void setstate(std::ios_base::iostate state)
Definition: istream.cpp:96
istream(std::basic_streambuf< char > *sb)
Definition: istream.cpp:10
virtual ~istream() noexcept
int peek()
Definition: istream.cpp:41
int get()
Definition: istream.cpp:45
bool good() const
Definition: istream.cpp:104
bool fail() const
Definition: istream.cpp:108
std::streambuf * rdbuf() const
Definition: istream.cpp:88
void clear(std::ios_base::iostate state=std::ios_base::goodbit)
Definition: istream.cpp:100
istream & seekg(std::streampos pos)
Definition: istream.cpp:73
istream & unget()
Definition: istream.cpp:54
std::streampos tellg()
Definition: istream.cpp:69
istream & sync()
Definition: istream.cpp:83
friend istream & operator>>(istream &os, const T &val)
Definition: istream.h:48
istream & putback(char ch)
Definition: istream.cpp:59
istream & read(char *s, std::streamsize count)
Definition: istream.cpp:64
Definition: sigHandler.cpp:20
std::istream & operator>>(ext::reference_wrapper< std::istream > &is, std::istream &(*const func)(std::istream &))
Overloaded function allowing same operations on wrapped input stream as on the actual input stream,...
Definition: GlobalData.cpp:53