4#ifndef INCLUDED_SDSL_RAM_FSTREAMBUF
5#define INCLUDED_SDSL_RAM_FSTREAMBUF
24 void pbump64(std::ptrdiff_t x)
26 while (x > std::numeric_limits<int>::max())
28 pbump(std::numeric_limits<int>::max());
29 x -= std::numeric_limits<int>::max();
41 char * begin = m_ram_file->data();
42 char * end = begin + m_ram_file->size();
43 setg(begin, begin, end);
46 std::streambuf *
open(
const std::string name, std::ios_base::openmode mode)
49 if ((mode & std::ios_base::in) and !(mode & std::ios_base::trunc))
69 if ((mode & std::ios_base::out) and !(mode & std::ios_base::app))
75 if (m_ram_file and (mode & std::ios_base::trunc))
81 if (mode & std::ios_base::ate)
87 setg(m_ram_file->data(), m_ram_file->data(), m_ram_file->data() + m_ram_file->size());
88 setp(m_ram_file->data(), m_ram_file->data() + m_ram_file->size());
91 return m_ram_file ? this :
nullptr;
96 return m_ram_file !=
nullptr;
103 m_ram_file =
nullptr;
104 setg(
nullptr,
nullptr,
nullptr);
105 setp(
nullptr,
nullptr);
109 pos_type
seekpos(pos_type sp, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
override
111 if (sp >= (pos_type)0 and sp <= (pos_type)m_ram_file->size())
113 setg(m_ram_file->data(), m_ram_file->data() + sp, m_ram_file->data() + m_ram_file->size());
114 setp(m_ram_file->data(), m_ram_file->data() + m_ram_file->size());
119 if (mode & std::ios_base::out)
122 m_ram_file->reserve(sp);
123 m_ram_file->resize(sp, 0);
124 setg(m_ram_file->data(), m_ram_file->data() + sp, m_ram_file->data() + m_ram_file->size());
125 setp(m_ram_file->data(), m_ram_file->data() + m_ram_file->size());
130 return pos_type(off_type(-1));
137 std::ios_base::seekdir way,
138 std::ios_base::openmode which = std::ios_base::in | std::ios_base::out)
140 if (std::ios_base::beg == way)
142 if (
seekpos(off, which) == pos_type(-1))
147 else if (std::ios_base::cur == way)
149 if (
seekpos(gptr() - eback() + off, which) == pos_type(-1))
154 else if (std::ios_base::end == way)
156 if (
seekpos(egptr() - eback() + off, which) == pos_type(-1))
161 return gptr() - eback();
164 pos_type
pubseekpos(pos_type sp, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out)
166 if (
seekpos(sp, which) == pos_type(-1))
172 return gptr() - eback();
176 std::streamsize
xsputn(char_type
const * s, std::streamsize n)
override
185 if (n < epptr() - pptr())
187 std::copy(s, s + n, pptr());
193 if (epptr() - pbase() == (std::ptrdiff_t)m_ram_file->size() and epptr() == pptr())
195 m_ram_file->insert(m_ram_file->end(), s, s + n);
196 setp(m_ram_file->data(), m_ram_file->data() + m_ram_file->size());
197 std::ptrdiff_t add = epptr() - pbase();
199 setg(m_ram_file->data(), gptr(), m_ram_file->data() + m_ram_file->size());
204 for (std::streamsize i = 0; i < n; ++i)
206 if (traits_type::eq_int_type(sputc(s[i]), traits_type::eof()))
221 int_type
overflow(int_type c = traits_type::eof())
override
225 m_ram_file->push_back(c);
226 setp(m_ram_file->data(), m_ram_file->data() + m_ram_file->size());
227 std::ptrdiff_t add = epptr() - pbase();
229 setg(m_ram_file->data(), gptr(), m_ram_file->data() + m_ram_file->size());
231 return traits_type::to_int_type(c);
std::streambuf * open(const std::string name, std::ios_base::openmode mode)
int_type overflow(int_type c=traits_type::eof()) override
ram_filebuf(ram_fs::content_type &ram_file)
pos_type seekpos(pos_type sp, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out) override
std::streamsize xsputn(char_type const *s, std::streamsize n) override
pos_type pubseekpos(pos_type sp, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out)
pos_type pubseekoff(off_type off, std::ios_base::seekdir way, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out)
memory_tracking.hpp contains two function for allocating and deallocating memory
void store(std::string const &name, content_type data)
content_type & content(std::string const &name)
Get the content.
bool exists(std::string const &name)
Check if the file exists.
std::vector< char, track_allocator< char > > content_type
Namespace for the succinct data structure library.