diff options
author | Peter Carbonetto | 2017-08-02 13:07:23 -0500 |
---|---|---|
committer | GitHub | 2017-08-02 13:07:23 -0500 |
commit | adaf9557f776ca274b51e921af0542ef1b84eb61 (patch) | |
tree | 8f7581bec20eb815848d02f926cb949ed038008b /src/gzstream.cpp | |
parent | 84360c191f418bf8682b35e0c8235fcc3bd19a06 (diff) | |
parent | 1e49e7a27d0f4b811a87c64db1e875779766f6b0 (diff) | |
download | pangemma-adaf9557f776ca274b51e921af0542ef1b84eb61.tar.gz |
Merge pull request #62 from genenetwork/spacing
Spacing and coding style.
Diffstat (limited to 'src/gzstream.cpp')
-rw-r--r-- | src/gzstream.cpp | 176 |
1 files changed, 87 insertions, 89 deletions
diff --git a/src/gzstream.cpp b/src/gzstream.cpp index 688b625..a7014d6 100644 --- a/src/gzstream.cpp +++ b/src/gzstream.cpp @@ -28,7 +28,7 @@ #include "gzstream.h" #include <iostream> -#include <string.h> // for memcpy +#include <string.h> // for memcpy #ifdef GZSTREAM_NAMESPACE namespace GZSTREAM_NAMESPACE { @@ -42,119 +42,117 @@ namespace GZSTREAM_NAMESPACE { // class gzstreambuf: // -------------------------------------- -gzstreambuf* gzstreambuf::open( const char* name, int open_mode) { - if ( is_open()) - return (gzstreambuf*)0; - mode = open_mode; - // no append nor read/write mode - if ((mode & std::ios::ate) || (mode & std::ios::app) - || ((mode & std::ios::in) && (mode & std::ios::out))) - return (gzstreambuf*)0; - char fmode[10]; - char* fmodeptr = fmode; - if ( mode & std::ios::in) - *fmodeptr++ = 'r'; - else if ( mode & std::ios::out) - *fmodeptr++ = 'w'; - *fmodeptr++ = 'b'; - *fmodeptr = '\0'; - file = gzopen( name, fmode); - if (file == 0) - return (gzstreambuf*)0; - opened = 1; - return this; +gzstreambuf *gzstreambuf::open(const char *name, int open_mode) { + if (is_open()) + return (gzstreambuf *)0; + mode = open_mode; + // no append nor read/write mode + if ((mode & std::ios::ate) || (mode & std::ios::app) || + ((mode & std::ios::in) && (mode & std::ios::out))) + return (gzstreambuf *)0; + char fmode[10]; + char *fmodeptr = fmode; + if (mode & std::ios::in) + *fmodeptr++ = 'r'; + else if (mode & std::ios::out) + *fmodeptr++ = 'w'; + *fmodeptr++ = 'b'; + *fmodeptr = '\0'; + file = gzopen(name, fmode); + if (file == 0) + return (gzstreambuf *)0; + opened = 1; + return this; } -gzstreambuf * gzstreambuf::close() { - if ( is_open()) { - sync(); - opened = 0; - if ( gzclose( file) == Z_OK) - return this; - } - return (gzstreambuf*)0; +gzstreambuf *gzstreambuf::close() { + if (is_open()) { + sync(); + opened = 0; + if (gzclose(file) == Z_OK) + return this; + } + return (gzstreambuf *)0; } int gzstreambuf::underflow() { // used for input buffer only - if ( gptr() && ( gptr() < egptr())) - return * reinterpret_cast<unsigned char *>( gptr()); - - if ( ! (mode & std::ios::in) || ! opened) - return EOF; - // Josuttis' implementation of inbuf - int n_putback = gptr() - eback(); - if ( n_putback > 4) - n_putback = 4; - memcpy( buffer + (4 - n_putback), gptr() - n_putback, n_putback); - - int num = gzread( file, buffer+4, bufferSize-4); - if (num <= 0) // ERROR or EOF - return EOF; - - // reset buffer pointers - setg( buffer + (4 - n_putback), // beginning of putback area - buffer + 4, // read position - buffer + 4 + num); // end of buffer - - // return next character - return * reinterpret_cast<unsigned char *>( gptr()); + if (gptr() && (gptr() < egptr())) + return *reinterpret_cast<unsigned char *>(gptr()); + + if (!(mode & std::ios::in) || !opened) + return EOF; + // Josuttis' implementation of inbuf + int n_putback = gptr() - eback(); + if (n_putback > 4) + n_putback = 4; + memcpy(buffer + (4 - n_putback), gptr() - n_putback, n_putback); + + int num = gzread(file, buffer + 4, bufferSize - 4); + if (num <= 0) // ERROR or EOF + return EOF; + + // reset buffer pointers + setg(buffer + (4 - n_putback), // beginning of putback area + buffer + 4, // read position + buffer + 4 + num); // end of buffer + + // return next character + return *reinterpret_cast<unsigned char *>(gptr()); } int gzstreambuf::flush_buffer() { - // Separate the writing of the buffer from overflow() and - // sync() operation. - int w = pptr() - pbase(); - if ( gzwrite( file, pbase(), w) != w) - return EOF; - pbump( -w); - return w; + // Separate the writing of the buffer from overflow() and + // sync() operation. + int w = pptr() - pbase(); + if (gzwrite(file, pbase(), w) != w) + return EOF; + pbump(-w); + return w; } -int gzstreambuf::overflow( int c) { // used for output buffer only - if ( ! ( mode & std::ios::out) || ! opened) - return EOF; - if (c != EOF) { - *pptr() = c; - pbump(1); - } - if ( flush_buffer() == EOF) - return EOF; - return c; +int gzstreambuf::overflow(int c) { // used for output buffer only + if (!(mode & std::ios::out) || !opened) + return EOF; + if (c != EOF) { + *pptr() = c; + pbump(1); + } + if (flush_buffer() == EOF) + return EOF; + return c; } int gzstreambuf::sync() { - // Changed to use flush_buffer() instead of overflow( EOF) - // which caused improper behavior with std::endl and flush(), - // bug reported by Vincent Ricard. - if ( pptr() && pptr() > pbase()) { - if ( flush_buffer() == EOF) - return -1; - } - return 0; + // Changed to use flush_buffer() instead of overflow( EOF) + // which caused improper behavior with std::endl and flush(), + // bug reported by Vincent Ricard. + if (pptr() && pptr() > pbase()) { + if (flush_buffer() == EOF) + return -1; + } + return 0; } // -------------------------------------- // class gzstreambase: // -------------------------------------- -gzstreambase::gzstreambase( const char* name, int mode) { - init( &buf); - open( name, mode); +gzstreambase::gzstreambase(const char *name, int mode) { + init(&buf); + open(name, mode); } -gzstreambase::~gzstreambase() { - buf.close(); -} +gzstreambase::~gzstreambase() { buf.close(); } -void gzstreambase::open( const char* name, int open_mode) { - if ( ! buf.open( name, open_mode)) - clear( rdstate() | std::ios::badbit); +void gzstreambase::open(const char *name, int open_mode) { + if (!buf.open(name, open_mode)) + clear(rdstate() | std::ios::badbit); } void gzstreambase::close() { - if ( buf.is_open()) - if ( ! buf.close()) - clear( rdstate() | std::ios::badbit); + if (buf.is_open()) + if (!buf.close()) + clear(rdstate() | std::ios::badbit); } #ifdef GZSTREAM_NAMESPACE |