#include "sgstream.hxx"
-using std::string;
using std::istream;
+using std::ostream;
sg_gzifstream::sg_gzifstream()
: istream(&gzbuf)
//
// Open a possibly gzipped file for reading.
//
-sg_gzifstream::sg_gzifstream( const string& name, ios_openmode io_mode )
+sg_gzifstream::sg_gzifstream( const std::string& name, ios_openmode io_mode )
: istream(&gzbuf)
{
this->open( name, io_mode );
// then append ".gz" and try again.
//
void
-sg_gzifstream::open( const string& name, ios_openmode io_mode )
+sg_gzifstream::open( const std::string& name, ios_openmode io_mode )
{
gzbuf.open( name.c_str(), io_mode );
if ( ! gzbuf.is_open() )
{
- string s = name;
+ std::string s = name;
if ( s.substr( s.length() - 3, 3 ) == ".gz" )
{
// remove ".gz" suffix
skipeol( istream& in )
{
char c = '\0';
- // skip to end of line.
+ // make sure we detect LF, CR and CR/LF
while ( in.get(c) ) {
- if ( (c == '\n') || (c == '\r') ) {
- break;
- }
+ if (c == '\n')
+ break;
+ else if (c == '\r') {
+ if (in.peek() == '\n')
+ in.get(c);
+ break;
+ }
}
-
return in;
}
return in;
}
+
+sg_gzofstream::sg_gzofstream()
+ : ostream(&gzbuf)
+{
+}
+
+//-----------------------------------------------------------------------------
+//
+// Open a file for gzipped writing.
+//
+sg_gzofstream::sg_gzofstream( const std::string& name, ios_openmode io_mode )
+ : ostream(&gzbuf)
+{
+ this->open( name, io_mode );
+}
+
+//-----------------------------------------------------------------------------
+//
+// Attach a stream to an already opened file descriptor.
+//
+sg_gzofstream::sg_gzofstream( int fd, ios_openmode io_mode )
+ : ostream(&gzbuf)
+{
+ gzbuf.attach( fd, io_mode );
+}
+
+//-----------------------------------------------------------------------------
+//
+// Open a file for gzipped writing.
+//
+void
+sg_gzofstream::open( const std::string& name, ios_openmode io_mode )
+{
+ gzbuf.open( name.c_str(), io_mode );
+}
+
+void
+sg_gzofstream::attach( int fd, ios_openmode io_mode )
+{
+ gzbuf.attach( fd, io_mode );
+}