Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
irstream.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/io/irstream.hh
11 /// @brief Input stream wrapper abstract base class
12 /// @author Mike Tyka (M.Tyka@bristol.ac.uk) (based on orstream.hh)
13 
14 
15 #ifndef INCLUDED_utility_io_irstream_hh
16 #define INCLUDED_utility_io_irstream_hh
17 
18 
19 // Unit headers
21 
22 // C++ headers
23 #include <iosfwd>
24 #include <string>
25 #include <iostream>
26 
27 
28 namespace utility {
29 namespace io {
30 
31 
32 /// @brief orstream: Input stream wrapper abstract base class
33 class irstream
34 {
35 
36 
37 protected: // Types
38 
39 
40  typedef std::istream & (*std_manipulator)( std::istream & );
41 
42 
43 public: // Creation
44 
45 
46  /// @brief Destructor
47  inline
48  virtual
50  {}
51 
52 
53 protected: // Creation
54 
55 
56  /// @brief Default constructor
57  inline
59  {}
60 
61 
62 private: // Creation
63 
64 
65  /// @brief Copy constructor: Undefined
66  irstream( irstream const & );
67 
68 
69 private: // Methods: assignment
70 
71 
72  /// @brief Copy assignment: Undefined
73  irstream &
74  operator =( irstream const & );
75 
76 
77 public: // Methods: conversion
78 
79 
80  /// @brief bool conversion
81  virtual
82  operator bool() const = 0;
83 
84 
85  /// @brief Stream conversion
86  virtual
87  operator std::istream const &() const = 0;
88 
89 
90  /// @brief Stream conversion
91  virtual
92  operator std::istream &() = 0;
93 
94 
95 public: // Methods: formatting
96 
97 
98  /// @brief Stream input
99  template< typename T >
100  inline
101  irstream &
102  operator >>( T & t )
103  {
104  stream() >> t;
105  return *this;
106  }
107 
108 
109  /// @brief Stream manipulator input
110  virtual
111  std::istream &
112  operator >>( std_manipulator m ) = 0;
113 
114 
115 public: // Methods: i/o
116 
117 
118  /// @brief Clear the stream
119  virtual
120  void
121  clear() = 0;
122 
123 
124  /// @brief Seek to the beginning
125  virtual
126  void
127  seek_beg() = 0;
128 
129 
130  /// @brief Get the next character
131  virtual
132  int
133  get() = 0;
134 
135 
136  /// @brief Get the next character
137  virtual
138  irstream &
139  get( char & c ) = 0;
140 
141 
142  /// @brief Get the next specified number of characters
143  virtual
144  irstream &
145  get( char * str, std::streamsize const count ) = 0;
146 
147 
148  /// @brief Get the next specified number of characters
149  virtual
150  irstream &
151  get( char * str, std::streamsize const count, char const delim ) = 0;
152 
153 
154  /// @brief Get the next specified number of characters
155  virtual
156  irstream &
157  get( std::string & str, std::streamsize const count ) = 0;
158 
159 
160  /// @brief Get the next specified number of characters
161  virtual
162  irstream &
163  get( std::string & str, std::streamsize const count, char const delim ) = 0;
164 
165 
166  /// @brief Get the rest of the line
167  virtual
168  irstream &
169  getline( char * line, std::streamsize const count ) = 0;
170 
171 
172  /// @brief Get the rest of the line
173  virtual
174  irstream &
175  getline( char * line, std::streamsize const count, char const delim ) = 0;
176 
177  /// @brief Get the rest of the line
178  virtual
179  irstream &
180  getline( std::string & line ) = 0;
181 
182 
183  /// @brief Get the rest of the line
184  virtual
185  irstream &
186  getline( std::string & line, char const delim ) = 0;
187 
188 
189  /// @brief Read the next specified number of characters
190  virtual
191  irstream &
192  read( char * str, std::streamsize const count ) = 0;
193 
194 
195  /// @brief Read the next specified number of characters
196  virtual
197  irstream &
198  read( std::string & str, std::streamsize const count ) = 0;
199 
200 
201  /// @brief Read the next available specified number of characters
202  virtual
203  std::streamsize
204  readsome( char * str, std::streamsize const count ) = 0;
205 
206 
207  /// @brief Read the next available specified number of characters
208  virtual
209  std::streamsize
210  readsome( std::string & str, std::streamsize const count ) = 0;
211 
212 
213  /// @brief Skip over the next character
214  virtual
215  irstream &
216  ignore() = 0;
217 
218 
219  /// @brief Skip over the next specified number of characters
220  virtual
221  irstream &
222  ignore( std::streamsize const count ) = 0;
223 
224 
225  /// @brief Skip over the next specified number of characters
226  virtual
227  irstream &
228  ignore( std::streamsize const count, char const delim ) = 0;
229 
230 
231  /// @brief Returns the next character without extracting it
232  virtual
233  int
234  peek() = 0;
235 
236 
237  /// @brief Put the last character read back into the stream
238  virtual
239  irstream &
240  unget() = 0;
241 
242 
243  /// @brief Put the last character read back into the stream and check that passed character is correct
244  virtual
245  irstream &
246  putback( char c ) = 0;
247 
248 
249 public: // Properties
250 
251 
252  /// @brief Stream access
253  virtual
254  std::istream const &
255  operator ()() const = 0;
256 
257 
258  /// @brief Stream access
259  virtual
260  std::istream &
261  operator ()() = 0;
262 
263 
264  /// @brief Stream access
265  virtual
266  std::istream const &
267  stream() const = 0;
268 
269 
270  /// @brief Stream access
271  virtual
272  std::istream &
273  stream() = 0;
274 
275 
276  /// @brief Pointer to the stream buffer
277  virtual
278  std::streambuf *
279  rdbuf() const = 0;
280 
281 
282 public: // Properties: predicate
283 
284 
285  /// @brief Good?
286  virtual
287  bool
288  good() const = 0;
289 
290 
291  /// @brief End of file?
292  virtual
293  bool
294  eof() const = 0;
295 
296 
297  /// @brief Fail?
298  virtual
299  bool
300  fail() const = 0;
301 
302 
303  /// @brief Bad?
304  virtual
305  bool
306  bad() const = 0;
307 
308 
309  /// @brief Compressed?
310  virtual
311  bool
312  compressed() const = 0;
313 
314 
315  /// @brief Uncompressed?
316  virtual
317  bool
318  uncompressed() const = 0;
319 
320 
321  /// @brief gzipped?
322  virtual
323  bool
324  gzipped() const = 0;
325 
326 
327 }; // irstream
328 
329 
330 } // namespace io
331 } // namespace utility
332 
333 
334 #endif // INCLUDED_utility_io_irstream_HH
virtual std::istream const & stream() const =0
Stream access.
virtual bool gzipped() const =0
gzipped?
virtual irstream & unget()=0
Put the last character read back into the stream.
virtual bool compressed() const =0
Compressed?
virtual void seek_beg()=0
Seek to the beginning.
virtual void clear()=0
Clear the stream.
virtual std::streambuf * rdbuf() const =0
Pointer to the stream buffer.
orstream: Input stream wrapper abstract base class
Definition: irstream.hh:33
virtual bool uncompressed() const =0
Uncompressed?
virtual irstream & putback(char c)=0
Put the last character read back into the stream and check that passed character is correct...
virtual ~irstream()
Destructor.
Definition: irstream.hh:49
irstream()
Default constructor.
Definition: irstream.hh:58
std::istream &(* std_manipulator)(std::istream &)
Definition: irstream.hh:40
virtual bool good() const =0
Good?
virtual bool eof() const =0
End of file?
virtual irstream & getline(char *line, std::streamsize const count)=0
Get the rest of the line.
virtual std::streamsize readsome(char *str, std::streamsize const count)=0
Read the next available specified number of characters.
static char * line
Definition: Svm.cc:2683
utility::io::irstream forward declarations
virtual irstream & ignore()=0
Skip over the next character.
irstream & operator=(irstream const &)
Copy assignment: Undefined.
virtual bool bad() const =0
Bad?
virtual int peek()=0
Returns the next character without extracting it.
virtual irstream & read(char *str, std::streamsize const count)=0
Read the next specified number of characters.
virtual bool fail() const =0
Fail?
irstream & operator>>(T &t)
Stream input.
Definition: irstream.hh:102
virtual std::istream const & operator()() const =0
Stream access.