]> git.donarmstrong.com Git - flightcrew.git/blob - src/zipios/src/outputstringstream.h
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / zipios / src / outputstringstream.h
1 #ifndef OUTPUTSTRINGSTREAM_H
2 #define OUTPUTSTRINGSTREAM_H
3
4 #include "zipios++/zipios-config.h"
5
6 #include "zipios++/meta-iostreams.h"
7 #include <string>
8
9 namespace zipios {
10
11 #if defined (HAVE_STD_IOSTREAM) && defined (USE_STD_IOSTREAM)
12
13 typedef std::ostringstream OutputStringStream ;
14
15 #else
16
17 /** OutputStringStream is typedefed to ostringstream if sstream is
18     part of the standard library (unless Zipios++ has been explicitly
19     configured not to use it). If sstream is not present
20     OutputStringStream is a subclass of ostrstream from
21     strstream.h. In this case OutputStringStream specializes the str()
22     method, such that the caller does not have to concern himself with
23     null-terminating the string and unfreezing the ostrstream. */
24 class OutputStringStream : public ostrstream {
25 public:
26
27   /** Specialization of ostrstream::str() that takes care of
28       null-terminating the string and unfreezing the ostrstream.  */
29   inline string str() {
30     *this << ends ; // null terminate ostrstream
31     string o_str( ostrstream::str() ) ;
32     freeze( 0 ) ;
33     return o_str ;
34   }
35 private:
36   // To avoid invoking such a member function in the base
37   // class if there is one!
38   string str() const ; 
39 };
40
41 #endif
42
43 } // namespace 
44
45
46 #endif
47
48 /** \file
49     Header file that defines OutputStringStream.
50 */
51
52 /*
53   Zipios++ - a small C++ library that provides easy access to .zip files.
54   Copyright (C) 2000  Thomas Søndergaard
55   
56   This library is free software; you can redistribute it and/or
57   modify it under the terms of the GNU Lesser General Public
58   License as published by the Free Software Foundation; either
59   version 2 of the License, or (at your option) any later version.
60   
61   This library is distributed in the hope that it will be useful,
62   but WITHOUT ANY WARRANTY; without even the implied warranty of
63   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
64   Lesser General Public License for more details.
65   
66   You should have received a copy of the GNU Lesser General Public
67   License along with this library; if not, write to the Free Software
68   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
69 */