souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes
souffle::gzfstream::internal::gzfstreambuf Class Reference

#include <gzfstream.h>

Inheritance diagram for souffle::gzfstream::internal::gzfstreambuf:
Inheritance graph
Collaboration diagram for souffle::gzfstream::internal::gzfstreambuf:
Collaboration graph

Public Member Functions

gzfstreambufclose ()
 
 gzfstreambuf ()
 
 gzfstreambuf (const gzfstreambuf &)=delete
 
 gzfstreambuf (gzfstreambuf &&old)=default
 
bool is_open () const
 
gzfstreambufopen (const std::string &filename, std::ios_base::openmode mode)
 
 ~gzfstreambuf () override
 

Protected Member Functions

int_type overflow (int c=EOF) override
 
int sync () override
 
int_type underflow () override
 

Private Attributes

char buffer [bufferSize] = {}
 
gzFile fileHandle = {}
 
bool isOpen = false
 
std::ios_base::openmode mode = std::ios_base::in
 

Static Private Attributes

static constexpr unsigned int bufferSize = 65536
 
static constexpr unsigned int reserveSize = 16
 

Detailed Description

Definition at line 45 of file gzfstream.h.

Constructor & Destructor Documentation

◆ gzfstreambuf() [1/3]

souffle::gzfstream::internal::gzfstreambuf::gzfstreambuf ( )
inline

Definition at line 52 of file gzfstream.h.

53  {
54  return nullptr;
55  }

◆ gzfstreambuf() [2/3]

souffle::gzfstream::internal::gzfstreambuf::gzfstreambuf ( const gzfstreambuf )
delete

◆ gzfstreambuf() [3/3]

souffle::gzfstream::internal::gzfstreambuf::gzfstreambuf ( gzfstreambuf &&  old)
default

◆ ~gzfstreambuf()

souffle::gzfstream::internal::gzfstreambuf::~gzfstreambuf ( )
inlineoverride

Definition at line 96 of file gzfstream.h.

103  {

Member Function Documentation

◆ close()

gzfstreambuf* souffle::gzfstream::internal::gzfstreambuf::close ( )
inline

Definition at line 81 of file gzfstream.h.

84  :
85  int_type overflow(int c = EOF) override {
86  if (((mode & std::ios::out) == 0) || !isOpen) {
87  return EOF;
88  }
89 
90  if (c != EOF) {

◆ is_open()

bool souffle::gzfstream::internal::gzfstreambuf::is_open ( ) const
inline

Definition at line 92 of file gzfstream.h.

95  {

Referenced by open().

◆ open()

gzfstreambuf* souffle::gzfstream::internal::gzfstreambuf::open ( const std::string &  filename,
std::ios_base::openmode  mode 
)
inline

Definition at line 61 of file gzfstream.h.

61  {
62  if (is_open()) {
63  sync();
64  isOpen = false;
65  if (gzclose(fileHandle) == Z_OK) {
66  return this;
67  }
68  }
69  return nullptr;
70  }
71 
72  bool is_open() const {
73  return isOpen;
74  }
75 
76  ~gzfstreambuf() override {
77  try {
78  close();
79  } catch (...) {

References fileHandle, is_open(), isOpen, and sync().

Here is the call graph for this function:

◆ overflow()

int_type souffle::gzfstream::internal::gzfstreambuf::overflow ( int  c = EOF)
inlineoverrideprotected

Definition at line 105 of file gzfstream.h.

107  {
108  return traits_type::to_int_type(*gptr());
109  }
110 
111  unsigned charsPutBack = gptr() - eback();
112  if (charsPutBack > reserveSize) {
113  charsPutBack = reserveSize;
114  }
115  memcpy(buffer + reserveSize - charsPutBack, gptr() - charsPutBack, charsPutBack);
116 
117  int charsRead = gzread(fileHandle, buffer + reserveSize, bufferSize - reserveSize);
118  if (charsRead <= 0) {
119  return EOF;
120  }
121 

◆ sync()

int souffle::gzfstream::internal::gzfstreambuf::sync ( )
inlineoverrideprotected

Definition at line 147 of file gzfstream.h.

148  : virtual public std::ios {
149 public:
150  gzfstream() {
151  init(&buf);
152  }
153 
154  gzfstream(const std::string& filename, std::ios_base::openmode mode) {
155  init(&buf);
156  open(filename, mode);

References souffle::gzfstream::internal::gzfstream::buf, souffle::gzfstream::internal::gzfstream::gzfstream(), and souffle::gzfstream::internal::gzfstream::open().

Referenced by open().

Here is the call graph for this function:

◆ underflow()

int_type souffle::gzfstream::internal::gzfstreambuf::underflow ( )
inlineoverrideprotected

Definition at line 123 of file gzfstream.h.

127  {
128  if ((pptr() != nullptr) && pptr() > pbase()) {
129  int toWrite = pptr() - pbase();
130  if (gzwrite(fileHandle, pbase(), toWrite) != toWrite) {
131  return -1;
132  }
133  pbump(-toWrite);
134  }
135  return 0;
136  }
137 
138 private:
139  static constexpr unsigned int bufferSize = 65536;
140  static constexpr unsigned int reserveSize = 16;
141 
142  char buffer[bufferSize] = {};
143  gzFile fileHandle = {};
144  bool isOpen = false;
145  std::ios_base::openmode mode = std::ios_base::in;

Field Documentation

◆ buffer

char souffle::gzfstream::internal::gzfstreambuf::buffer[bufferSize] = {}
private

Definition at line 162 of file gzfstream.h.

◆ bufferSize

constexpr unsigned int souffle::gzfstream::internal::gzfstreambuf::bufferSize = 65536
staticconstexprprivate

Definition at line 159 of file gzfstream.h.

◆ fileHandle

gzFile souffle::gzfstream::internal::gzfstreambuf::fileHandle = {}
private

Definition at line 163 of file gzfstream.h.

Referenced by open().

◆ isOpen

bool souffle::gzfstream::internal::gzfstreambuf::isOpen = false
private

Definition at line 164 of file gzfstream.h.

Referenced by open().

◆ mode

std::ios_base::openmode souffle::gzfstream::internal::gzfstreambuf::mode = std::ios_base::in
private

Definition at line 165 of file gzfstream.h.

◆ reserveSize

constexpr unsigned int souffle::gzfstream::internal::gzfstreambuf::reserveSize = 16
staticconstexprprivate

Definition at line 160 of file gzfstream.h.


The documentation for this class was generated from the following file:
souffle::gzfstream::internal::gzfstreambuf::open
gzfstreambuf * open(const std::string &filename, std::ios_base::openmode mode)
Definition: gzfstream.h:61
souffle::gzfstream::internal::gzfstreambuf::isOpen
bool isOpen
Definition: gzfstream.h:164
souffle::gzfstream::internal::gzfstreambuf::buffer
char buffer[bufferSize]
Definition: gzfstream.h:162
souffle::gzfstream::internal::gzfstreambuf::mode
std::ios_base::openmode mode
Definition: gzfstream.h:165
souffle::gzfstream::internal::gzfstreambuf::bufferSize
static constexpr unsigned int bufferSize
Definition: gzfstream.h:159
souffle::gzfstream::internal::gzfstreambuf::sync
int sync() override
Definition: gzfstream.h:147
souffle::gzfstream::internal::gzfstreambuf::overflow
int_type overflow(int c=EOF) override
Definition: gzfstream.h:105
souffle::gzfstream::internal::gzfstreambuf::is_open
bool is_open() const
Definition: gzfstream.h:92
souffle::gzfstream::internal::gzfstreambuf::reserveSize
static constexpr unsigned int reserveSize
Definition: gzfstream.h:160
souffle::gzfstream::internal::gzfstreambuf::fileHandle
gzFile fileHandle
Definition: gzfstream.h:163
souffle::gzfstream::internal::gzfstreambuf::close
gzfstreambuf * close()
Definition: gzfstream.h:81
souffle::gzfstream::internal::gzfstreambuf::~gzfstreambuf
~gzfstreambuf() override
Definition: gzfstream.h:96