11template<
typename Vector,
typename TraitsT = std::
char_traits<
typename Vector::value_type>>
12class vecostreambuf:
public std::basic_streambuf<typename Vector::value_type, TraitsT> {
19 m_vector.push_back(ch);
26 std::streamsize
xsputn(
const typename Vector::value_type *s, std::streamsize num)
28 size_t oldsize = m_vector.size();
29 if (oldsize + num > m_vector.capacity()) {
30 m_vector.reserve(std::max(2 * (oldsize + num), m_vector.capacity() * 2));
32 m_vector.resize(oldsize + num);
33 memcpy(m_vector.data() + oldsize, s, num);
37 std::size_t
write(
const void *ptr, std::size_t size)
39 return xsputn(
static_cast<const typename Vector::value_type *
>(ptr), size);
51template<
typename Vector,
typename TraitsT = std::
char_traits<
typename Vector::value_type>>
52class vecistreambuf:
public std::basic_streambuf<typename Vector::value_type, TraitsT> {
56 auto &v =
const_cast<Vector &
>(vec);
57 this->setg(v.data(), v.data(), v.data() + v.size());
60 std::size_t
read(
void *ptr, std::size_t size)
62 if (cur + size > vec.size())
63 size = vec.size() - cur;
64 memcpy(ptr, vec.data() + cur, size);
69 bool empty()
const {
return cur == 0; }
70 typename Vector::value_type
peekch()
const {
return vec[cur]; }
71 typename Vector::value_type
getch() {
return vec[cur++]; }
Definition: vecstreambuf.h:52
Vector::value_type getch()
Definition: vecstreambuf.h:71
std::size_t read(void *ptr, std::size_t size)
Definition: vecstreambuf.h:60
vecistreambuf(const Vector &ve)
Definition: vecstreambuf.h:54
void ungetch(char)
Definition: vecstreambuf.h:72
Vector::value_type peekch() const
Definition: vecstreambuf.h:70
bool empty() const
Definition: vecstreambuf.h:69
Definition: vecstreambuf.h:12
const Vector & get_vector() const
Definition: vecstreambuf.h:42
vecostreambuf()
Definition: vecstreambuf.h:14
Vector & get_vector()
Definition: vecstreambuf.h:44
std::size_t write(const void *ptr, std::size_t size)
Definition: vecstreambuf.h:37
int overflow(int ch)
Definition: vecstreambuf.h:16
std::streamsize xsputn(const typename Vector::value_type *s, std::streamsize num)
Definition: vecstreambuf.h:26
Definition: allobjects.cpp:30
Vector3 Vector
Definition: vector.h:36