]> git.mxchange.org Git - simgear.git/blob - simgear/misc/sgstream.hxx
Updates to build system to better support automake-1.5
[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 #include <simgear/compiler.h>
36
37 #if defined( SG_HAVE_STD_INCLUDES )
38 #  include <istream>
39 #elif defined ( SG_HAVE_NATIVE_SGI_COMPILERS )
40 #  include <CC/stream.h>
41 #elif defined ( __BORLANDC__ )
42 #  include <iostream>
43 #else
44 #  include <istream.h>
45 #endif
46
47 #include STL_STRING
48
49 #include <simgear/misc/zfstream.hxx>
50
51 SG_USING_STD(string);
52
53 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
54 SG_USING_STD(istream);
55 #endif
56
57
58 /**
59  * An envelope class for gzifstream.
60  */
61 class sg_gzifstream : private gzifstream_base, public istream
62 {
63 public:
64     /** Default constructor */
65     sg_gzifstream();
66
67     /**
68      * Constructor that attempt to open a file with and without
69      * ".gz" extension.
70      * @param name name of file
71      * @param io_mode file open mode(s) "or'd" together
72      */
73     sg_gzifstream( const string& name,
74                    ios_openmode io_mode = ios_in | ios_binary );
75
76     /**
77      * Constructor that attaches itself to an existing file descriptor.
78      * @param fd file descriptor
79      * @param io_mode file open mode(s) "or'd" together
80      */
81     sg_gzifstream( int fd, ios_openmode io_mode = ios_in|ios_binary );
82
83     /**
84      * Attempt to open a file with and without ".gz" extension.
85      * @param name name of file
86      * @param io_mode file open mode(s) "or'd" together
87      */
88     void open( const string& name,
89                ios_openmode io_mode = ios_in|ios_binary );
90
91     /**
92      * Attach to an existing file descriptor.
93      * @param fd file descriptor
94      * @param io_mode file open mode(s) "or'd" together
95      */
96     void attach( int fd, ios_openmode io_mode = ios_in|ios_binary );
97
98     /**
99      * Close the stream.
100      */
101     void close() { gzbuf.close(); }
102
103     /** @return true if the file is successfully opened, false otherwise. */
104     bool is_open() { return gzbuf.is_open(); }
105
106 private:
107     // Not defined!
108     sg_gzifstream( const sg_gzifstream& );    
109     void operator= ( const sg_gzifstream& );    
110 };
111
112 /**
113  * \relates sg_gzifstream
114  * An istream manipulator that skips to end of line.
115  * @param in input stream
116  */
117 istream& skipeol( istream& in );
118
119 /**
120  * \relates sg_gzifstream
121  * An istream manipulator that skips over white space.
122  * @param in input stream
123  */
124 istream& skipws( istream& in );
125
126 /**
127  * \relates sg_gzifstream
128  * An istream manipulator that skips comments and white space.
129  * Ignores comments that start with '#'.
130  * @param in input stream
131  */
132 istream& skipcomment( istream& in );
133
134
135 #endif /* _SGSTREAM_HXX */
136