8#ifndef INCLUDED_SDSL_SFSTREAM
9#define INCLUDED_SDSL_SFSTREAM
28 std::string m_file =
"";
34 : std::ostream(nullptr)
36 this->init(m_streambuf);
40 osfstream(
const std::string & file, std::ios_base::openmode mode = std::ios_base::out)
41 : std::ostream(nullptr)
43 this->init(m_streambuf);
48 buf_ptr_type open(
const std::string & file, std::ios_base::openmode mode = std::ios_base::out)
51 m_streambuf =
nullptr;
53 std::streambuf * success =
nullptr;
57 success = ((
ram_filebuf *)m_streambuf)->open(m_file, mode | std::ios_base::out);
61 m_streambuf =
new std::filebuf();
62 success = ((std::filebuf *)m_streambuf)->open(m_file, mode | std::ios_base::out);
64 if (success) { this->clear(); }
67 this->setstate(std::ios_base::failbit);
69 m_streambuf =
nullptr;
71 this->rdbuf(m_streambuf);
78 if (
nullptr == m_streambuf)
return false;
82 return ((std::filebuf *)m_streambuf)->is_open();
90 if (
nullptr == m_streambuf) { fail =
true; }
96 fail = !((std::filebuf *)m_streambuf)->close();
99 if (fail) this->setstate(std::ios::failbit);
109 operator voidptr()
const {
return m_streambuf; }
113 ios_base::iostate err = std::ios_base::iostate(std::ios_base::goodbit);
122 p = ((std::filebuf *)m_streambuf)->pubseekpos(pos, std::ios_base::out);
124 if (p == pos_type(off_type(-1)))
126 err |= ios_base::failbit;
133 if (err) { this->setstate(err); }
140 ios_base::iostate err = std::ios_base::iostate(ios_base::goodbit);
149 p = ((std::filebuf *)m_streambuf)->pubseekoff(off, way, std::ios_base::out);
151 if (p == pos_type(off_type(-1)))
153 err |= ios_base::failbit;
160 if (err) { this->setstate(err); }
170 typedef std::streambuf * buf_ptr_type;
173 buf_ptr_type m_streambuf =
nullptr;
174 std::string m_file =
"";
180 : std::istream(nullptr)
182 this->init(m_streambuf);
186 isfstream(
const std::string & file, std::ios_base::openmode mode = std::ios_base::in)
187 : std::istream(nullptr)
189 this->init(m_streambuf);
194 buf_ptr_type
open(
const std::string & file, std::ios_base::openmode mode = std::ios_base::in)
197 m_streambuf =
nullptr;
199 std::streambuf * success =
nullptr;
203 success = ((
ram_filebuf *)m_streambuf)->open(m_file, mode | std::ios_base::in);
207 m_streambuf =
new std::filebuf();
208 success = ((std::filebuf *)m_streambuf)->open(m_file, mode | std::ios_base::in);
210 if (success) { this->clear(); }
213 this->setstate(std::ios_base::failbit);
215 m_streambuf =
nullptr;
217 this->rdbuf(m_streambuf);
224 if (
nullptr == m_streambuf)
return false;
228 return ((std::filebuf *)m_streambuf)->is_open();
236 if (
nullptr == m_streambuf) { fail =
true; }
242 fail = !((std::filebuf *)m_streambuf)->close();
245 if (fail) this->setstate(std::ios::failbit);
259 ios_base::iostate err = std::ios_base::iostate(std::ios_base::goodbit);
268 p = ((std::filebuf *)m_streambuf)->pubseekpos(pos, std::ios_base::in);
270 if (p == pos_type(off_type(-1))) { err |= ios_base::failbit; }
275 if (err) { this->setstate(err); }
282 ios_base::iostate err = std::ios_base::iostate(ios_base::goodbit);
291 p = ((std::filebuf *)m_streambuf)->pubseekoff(off, way, std::ios_base::in);
293 if (p == pos_type(off_type(-1))) { err |= ios_base::failbit; }
298 if (err) { this->setstate(err); }
305 ios_base::iostate err = std::ios_base::iostate(ios_base::goodbit);
306 pos_type p = pos_type(off_type(-1));
314 p = ((std::filebuf *)m_streambuf)->pubseekoff(0, std::ios_base::cur);
316 if (p == pos_type(off_type(-1))) { err |= ios_base::failbit; }
321 if (err) { this->setstate(err); }
~isfstream()
Standard destructor.
isfstream & seekg(pos_type pos)
bool is_open()
Is the stream close?
buf_ptr_type open(const std::string &file, std::ios_base::openmode mode=std::ios_base::in)
Open the stream.
isfstream & seekg(off_type off, ios_base::seekdir way)
isfstream()
Standard constructor.
void close()
Close the stream.
isfstream(const std::string &file, std::ios_base::openmode mode=std::ios_base::in)
Constructor taking a file name and open mode.
std::streambuf * buf_ptr_type
osfstream & seekp(pos_type pos)
void close()
Close the stream.
bool is_open()
Is the stream close?
buf_ptr_type open(const std::string &file, std::ios_base::openmode mode=std::ios_base::out)
Open the stream.
osfstream(const std::string &file, std::ios_base::openmode mode=std::ios_base::out)
Constructor taking a file name and open mode.
~osfstream()
Standard destructor.
osfstream()
Standard constructor.
osfstream & seekp(off_type off, ios_base::seekdir way)
Namespace for the succinct data structure library.
bool is_ram_file(const std::string &file)
Determines if the given file is a RAM-file.