29#include "io/gzstream.hpp"
44 gzstreambuf* gzstreambuf::open(
const char* name,
int open_mode) {
45 if (is_open())
return (gzstreambuf*)0;
48 if ((mode & std::ios::ate) || (mode & std::ios::app) ||
49 ((mode & std::ios::in) && (mode & std::ios::out)))
50 return (gzstreambuf*)0;
52 char* fmodeptr = fmode;
53 if (mode & std::ios::in)
55 else if (mode & std::ios::out)
59 file = gzopen(name, fmode);
60 if (file == 0)
return (gzstreambuf*)0;
65 gzstreambuf* gzstreambuf::close() {
69 if (gzclose(file) == Z_OK)
return this;
71 return (gzstreambuf*)0;
74 int gzstreambuf::underflow() {
75 if (gptr() && (gptr() < egptr()))
76 return *
reinterpret_cast<unsigned char*
>(gptr());
78 if (!(mode & std::ios::in) || !opened)
return EOF;
80 int n_putback = gptr() - eback();
81 if (n_putback > 4) n_putback = 4;
82 memcpy(buffer + (4 - n_putback), gptr() - n_putback, n_putback);
84 int num = gzread(file, buffer + 4, bufferSize - 4);
89 setg(buffer + (4 - n_putback),
94 return *
reinterpret_cast<unsigned char*
>(gptr());
97 int gzstreambuf::flush_buffer() {
100 int w = pptr() - pbase();
101 if (gzwrite(file, pbase(), w) != w)
return EOF;
106 int gzstreambuf::overflow(
int c) {
107 if (!(mode & std::ios::out) || !opened)
return EOF;
112 if (flush_buffer() == EOF)
return EOF;
116 int gzstreambuf::sync() {
120 if (pptr() && pptr() > pbase()) {
121 if (flush_buffer() == EOF)
return -1;
130 gzstreambase::gzstreambase(
const char* name,
int mode) {
135 gzstreambase::~gzstreambase() { buf.close(); }
137 void gzstreambase::open(
const char* name,
int open_mode) {
138 if (!buf.open(name, open_mode)) clear(rdstate() | std::ios::badbit);
141 void gzstreambase::close() {
143 if (!buf.close()) clear(rdstate() | std::ios::badbit);
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.