Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ocstream.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/ocstream.hh
11 /// @brief Output channel stream wrapper class
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
13 
14 
15 #ifndef INCLUDED_utility_io_ocstream_hh
16 #define INCLUDED_utility_io_ocstream_hh
17 
18 
19 // Unit headers
21 
22 // Package headers
23 #include <utility/io/orstream.hh>
24 
25 // C++ headers
26 #include <ostream>
27 
28 
29 namespace utility {
30 namespace io {
31 
32 
33 /// @brief ocstream: Output channel stream wrapper class
34 class ocstream :
35  public orstream
36 {
37 
38 
39 public: // Creation
40 
41 
42  /// @brief Constructor
43  inline
44  ocstream( std::ostream & o_stream_a ) :
45  o_stream_( o_stream_a )
46  {}
47 
48 
49  /// @brief Destructor
50  inline
51  virtual
53  {}
54 
55 
56 public: // Methods: conversion
57 
58 
59  /// @brief bool conversion
60  inline
61  operator bool() const
62  {
63  return !!o_stream_;
64  }
65 
66 
67  /// @brief Stream conversion
68  inline
69  operator std::ostream const &() const
70  {
71  return o_stream_;
72  }
73 
74 
75  /// @brief Stream conversion
76  inline
77  operator std::ostream &()
78  {
79  return o_stream_;
80  }
81 
82 
83 public: // Methods: formatting
84 
85 
86  /// @brief Stream output: override to preserve type of return value
87  template< typename T >
88  inline
89  ocstream &
90  operator <<( T const & t )
91  {
92  o_stream_ << t;
93  return *this;
94  }
95 
96 
97  /// @brief Stream manipulator output
98  inline
99  ocstream &
101  {
102  o_stream_ << m;
103  return *this;
104  }
105 
106 
107 public: // Methods: i/o
108 
109 
110  /// @brief Write a char
111  inline
112  ocstream &
113  put( char const c )
114  {
115  o_stream_.put( c );
116  return *this;
117  }
118 
119 
120  /// @brief Write a string
121  inline
122  ocstream &
123  write( char const * str, std::streamsize const count )
124  {
125  o_stream_.write( str, count );
126  return *this;
127  }
128 
129 
130  /// @brief Write a string
131  inline
132  ocstream &
133  write( std::string const & str, std::streamsize const count )
134  {
135  o_stream_.write( str.c_str(), count );
136  return *this;
137  }
138 
139 
140  /// @brief Flush the stream
141  inline
142  ocstream &
144  {
145  o_stream_.flush();
146  return *this;
147  }
148 
149 
150  /// @brief Clear the stream
151  inline
152  void
154  {
155  o_stream_.clear();
156  }
157 
158 
159 public: // Properties
160 
161 
162  /// @brief Stream access
163  inline
164  std::ostream const &
165  operator ()() const
166  {
167  return o_stream_;
168  }
169 
170 
171  /// @brief Stream access
172  inline
173  std::ostream &
175  {
176  return o_stream_;
177  }
178 
179 
180  /// @brief Stream access
181  inline
182  std::ostream const &
183  stream() const
184  {
185  return o_stream_;
186  }
187 
188 
189  /// @brief Stream access
190  inline
191  std::ostream &
193  {
194  return o_stream_;
195  }
196 
197 
198  /// @brief Pointer to the stream buffer
199  inline
200  std::streambuf *
201  rdbuf() const
202  {
203  return o_stream_.rdbuf();
204  }
205 
206 
207 public: // Properties: predicate
208 
209 
210  /// @brief Good?
211  inline
212  bool
213  good() const
214  {
215  return o_stream_.good();
216  }
217 
218 
219  /// @brief End of file?
220  inline
221  bool
222  eof() const
223  {
224  return o_stream_.eof();
225  }
226 
227 
228  /// @brief Fail?
229  inline
230  bool
231  fail() const
232  {
233  return o_stream_.fail();
234  }
235 
236 
237  /// @brief Bad?
238  inline
239  bool
240  bad() const
241  {
242  return o_stream_.bad();
243  }
244 
245 
246  /// @brief Compressed?
247  inline
248  bool
249  compressed() const
250  {
251  return false;
252  }
253 
254 
255  /// @brief Uncompressed?
256  inline
257  bool
258  uncompressed() const
259  {
260  return true;
261  }
262 
263 
264  /// @brief gzipped?
265  inline
266  bool
267  gzipped() const
268  {
269  return false;
270  }
271 
272 
273 private: // Fields
274 
275 
276  /// @brief Output stream reference
277  std::ostream & o_stream_;
278 
279 
280 }; // ocstream
281 
282 
283 namespace oc { // Predefined ocstreams
284 
285 
286 /// @brief Wrapper around std::cout
287 extern ocstream cout;
288 
289 /// @brief Wrapper around std::cerr
290 extern ocstream cerr;
291 
292 /// @brief Wrapper around std::clog
293 extern ocstream clog;
294 
295 
296 } // namespace oc
297 
298 
299 } // namespace io
300 } // namespace utility
301 
302 
303 #endif // INCLUDED_utility_io_ocstream_HH
Output stream wrapper abstract base class.
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
bool uncompressed() const
Uncompressed?
Definition: ocstream.hh:258
bool compressed() const
Compressed?
Definition: ocstream.hh:249
std::ostream const & operator()() const
Stream access.
Definition: ocstream.hh:165
bool gzipped() const
gzipped?
Definition: ocstream.hh:267
bool good() const
Good?
Definition: ocstream.hh:213
bool bad() const
Bad?
Definition: ocstream.hh:240
std::ostream & o_stream_
Output stream reference.
Definition: ocstream.hh:277
virtual ~ocstream()
Destructor.
Definition: ocstream.hh:52
ocstream clog(std::clog)
Wrapper around std::clog.
Definition: ocstream.hh:293
std::ostream & stream()
Stream access.
Definition: ocstream.hh:192
bool eof() const
End of file?
Definition: ocstream.hh:222
std::ostream &(* manipulator)(std::ostream &)
Definition: orstream.hh:40
void clear()
Clear the stream.
Definition: ocstream.hh:153
orstream: Output stream wrapper base class
Definition: orstream.hh:33
std::streambuf * rdbuf() const
Pointer to the stream buffer.
Definition: ocstream.hh:201
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
ocstream & operator<<(T const &t)
Stream output: override to preserve type of return value.
Definition: ocstream.hh:90
ocstream & put(char const c)
Write a char.
Definition: ocstream.hh:113
ocstream & write(char const *str, std::streamsize const count)
Write a string.
Definition: ocstream.hh:123
bool fail() const
Fail?
Definition: ocstream.hh:231
ocstream: Output channel stream wrapper class
Definition: ocstream.hh:34
ocstream & flush()
Flush the stream.
Definition: ocstream.hh:143
ocstream & write(std::string const &str, std::streamsize const count)
Write a string.
Definition: ocstream.hh:133
std::ostream const & stream() const
Stream access.
Definition: ocstream.hh:183
utility::io::ocstream forward declarations
ocstream(std::ostream &o_stream_a)
Constructor.
Definition: ocstream.hh:44