]> git.mxchange.org Git - simgear.git/blob - simgear/misc/sgstream.hxx
renamed to sgstream.[ch]xx
[simgear.git] / simgear / misc / sgstream.hxx
1 /**
2  * \file sgstream.hxx
3  * zlib input file stream wrapper.
4  */
5
6 // Written by Bernie Bright, 1998
7 //
8 // Copyright (C) 1998  Bernie Bright - bbright@c031.aone.net.au
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library 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 GNU
18 // Library General Public License for more details.
19 //
20 // You should have received a copy of the GNU Library General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA  02111-1307, USA.
24 //
25 // $Id$
26
27
28 #ifndef _SGSTREAM_HXX
29 #define _SGSTREAM_HXX
30
31 #ifndef __cplusplus                                                          
32 # error This library requires C++
33 #endif                                   
34
35 #ifdef HAVE_CONFIG_H
36 #  include <config.h>
37 #endif
38
39 #include <simgear/compiler.h>
40
41 #if defined( SG_HAVE_STD_INCLUDES )
42 #  include <istream>
43 #elif defined ( SG_HAVE_NATIVE_SGI_COMPILERS )
44 #  include <CC/stream.h>
45 #elif defined ( __BORLANDC__ )
46 #  include <iostream>
47 #else
48 #  include <istream.h>
49 #endif
50
51 #include STL_STRING
52
53 #include <simgear/misc/zfstream.hxx>
54
55 SG_USING_STD(string);
56
57 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
58 SG_USING_STD(istream);
59 #endif
60
61
62 /**
63  * An envelope class for gzifstream.
64  */
65 class sg_gzifstream : private gzifstream_base, public istream
66 {
67 public:
68     /** Default constructor */
69     sg_gzifstream();
70
71     /**
72      * Constructor that attempt to open a file with and without
73      * ".gz" extension.
74      * @param name name of file
75      * @param io_mode file open mode(s) "or'd" together
76      */
77     sg_gzifstream( const string& name,
78                    ios_openmode io_mode = ios_in | ios_binary );
79
80     /**
81      * Constructor that attaches itself to an existing file descriptor.
82      * @param fd file descriptor
83      * @param io_mode file open mode(s) "or'd" together
84      */
85     sg_gzifstream( int fd, ios_openmode io_mode = ios_in|ios_binary );
86
87     /**
88      * Attempt to open a file with and without ".gz" extension.
89      * @param name name of file
90      * @param io_mode file open mode(s) "or'd" together
91      */
92     void open( const string& name,
93                ios_openmode io_mode = ios_in|ios_binary );
94
95     /**
96      * Attach to an existing file descriptor.
97      * @param fd file descriptor
98      * @param io_mode file open mode(s) "or'd" together
99      */
100     void attach( int fd, ios_openmode io_mode = ios_in|ios_binary );
101
102     /**
103      * Close the stream.
104      */
105     void close() { gzbuf.close(); }
106
107     /** @return true if the file is successfully opened, false otherwise. */
108     bool is_open() { return gzbuf.is_open(); }
109
110 private:
111     // Not defined!
112     sg_gzifstream( const sg_gzifstream& );    
113     void operator= ( const sg_gzifstream& );    
114 };
115
116 /**
117  * \relates sg_gzifstream
118  * An istream manipulator that skips to end of line.
119  * @param in input stream
120  */
121 istream& skipeol( istream& in );
122
123 /**
124  * \relates sg_gzifstream
125  * An istream manipulator that skips over white space.
126  * @param in input stream
127  */
128 istream& skipws( istream& in );
129
130 /**
131  * \relates sg_gzifstream
132  * An istream manipulator that skips comments and white space.
133  * Ignores comments that start with '#'.
134  * @param in input stream
135  */
136 istream& skipcomment( istream& in );
137
138
139 #endif /* _SGSTREAM_HXX */
140