8#ifndef INCLUDED_SDSL_SFSTREAM
9#define INCLUDED_SDSL_SFSTREAM
27 std::string m_file =
"";
34 this->init(m_streambuf);
38 osfstream(std::string
const & file, std::ios_base::openmode mode = std::ios_base::out) : std::ostream(nullptr)
40 this->init(m_streambuf);
45 buf_ptr_type open(std::string
const & file, std::ios_base::openmode mode = std::ios_base::out)
48 m_streambuf =
nullptr;
50 std::streambuf * success =
nullptr;
54 success = ((
ram_filebuf *)m_streambuf)->open(m_file, mode | std::ios_base::out);
58 m_streambuf =
new std::filebuf();
59 success = ((std::filebuf *)m_streambuf)->open(m_file, mode | std::ios_base::out);
67 this->setstate(std::ios_base::failbit);
69 m_streambuf =
nullptr;
71 this->rdbuf(m_streambuf);
78 if (
nullptr == m_streambuf)
86 return ((std::filebuf *)m_streambuf)->is_open();
94 if (
nullptr == m_streambuf)
106 fail = !((std::filebuf *)m_streambuf)->close();
110 this->setstate(std::ios::failbit);
127 ios_base::iostate err = std::ios_base::iostate(std::ios_base::goodbit);
135 p = ((
ram_filebuf *)m_streambuf)->pubseekpos(pos, std::ios_base::out);
139 p = ((std::filebuf *)m_streambuf)->pubseekpos(pos, std::ios_base::out);
141 if (p == pos_type(off_type(-1)))
143 err |= ios_base::failbit;
160 ios_base::iostate err = std::ios_base::iostate(ios_base::goodbit);
168 p = ((
ram_filebuf *)m_streambuf)->pubseekoff(off, way, std::ios_base::out);
172 p = ((std::filebuf *)m_streambuf)->pubseekoff(off, way, std::ios_base::out);
174 if (p == pos_type(off_type(-1)))
176 err |= ios_base::failbit;
196 typedef std::streambuf * buf_ptr_type;
199 buf_ptr_type m_streambuf =
nullptr;
200 std::string m_file =
"";
207 this->init(m_streambuf);
211 isfstream(std::string
const & file, std::ios_base::openmode mode = std::ios_base::in) : std::istream(nullptr)
213 this->init(m_streambuf);
218 buf_ptr_type
open(std::string
const & file, std::ios_base::openmode mode = std::ios_base::in)
221 m_streambuf =
nullptr;
223 std::streambuf * success =
nullptr;
227 success = ((
ram_filebuf *)m_streambuf)->open(m_file, mode | std::ios_base::in);
231 m_streambuf =
new std::filebuf();
232 success = ((std::filebuf *)m_streambuf)->open(m_file, mode | std::ios_base::in);
240 this->setstate(std::ios_base::failbit);
242 m_streambuf =
nullptr;
244 this->rdbuf(m_streambuf);
251 if (
nullptr == m_streambuf)
259 return ((std::filebuf *)m_streambuf)->is_open();
267 if (
nullptr == m_streambuf)
279 fail = !((std::filebuf *)m_streambuf)->close();
283 this->setstate(std::ios::failbit);
300 ios_base::iostate err = std::ios_base::iostate(std::ios_base::goodbit);
308 p = ((
ram_filebuf *)m_streambuf)->pubseekpos(pos, std::ios_base::in);
312 p = ((std::filebuf *)m_streambuf)->pubseekpos(pos, std::ios_base::in);
314 if (p == pos_type(off_type(-1)))
316 err |= ios_base::failbit;
332 ios_base::iostate err = std::ios_base::iostate(ios_base::goodbit);
340 p = ((
ram_filebuf *)m_streambuf)->pubseekoff(off, way, std::ios_base::in);
344 p = ((std::filebuf *)m_streambuf)->pubseekoff(off, way, std::ios_base::in);
346 if (p == pos_type(off_type(-1)))
348 err |= ios_base::failbit;
364 ios_base::iostate err = std::ios_base::iostate(ios_base::goodbit);
365 pos_type p = pos_type(off_type(-1));
372 p = ((
ram_filebuf *)m_streambuf)->pubseekoff(0, std::ios_base::cur);
376 p = ((std::filebuf *)m_streambuf)->pubseekoff(0, std::ios_base::cur);
378 if (p == pos_type(off_type(-1)))
380 err |= ios_base::failbit;
isfstream(std::string const &file, std::ios_base::openmode mode=std::ios_base::in)
Constructor taking a file name and open mode.
~isfstream()
Standard destructor.
isfstream & seekg(pos_type pos)
bool is_open()
Is the stream close?
buf_ptr_type open(std::string const &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.
osfstream & seekp(pos_type pos)
void close()
Close the stream.
bool is_open()
Is the stream close?
~osfstream()
Standard destructor.
osfstream()
Standard constructor.
osfstream & seekp(off_type off, ios_base::seekdir way)
buf_ptr_type open(std::string const &file, std::ios_base::openmode mode=std::ios_base::out)
Open the stream.
std::streambuf * buf_ptr_type
osfstream(std::string const &file, std::ios_base::openmode mode=std::ios_base::out)
Constructor taking a file name and open mode.
Namespace for the succinct data structure library.
bool is_ram_file(std::string const &file)
Determines if the given file is a RAM-file.