From 61b531522a9cdfe08754a684b4a354c41699af03 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 3 Mar 2016 13:03:42 +1100 Subject: Implement swappable concept properly --- src/lib/util/vecstream.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/lib/util/vecstream.h') diff --git a/src/lib/util/vecstream.h b/src/lib/util/vecstream.h index fb472df95cd..498e35eac5e 100644 --- a/src/lib/util/vecstream.h +++ b/src/lib/util/vecstream.h @@ -19,6 +19,10 @@ #include #include +#include +#include +#include +#include #include #include #include @@ -103,10 +107,11 @@ public: void swap(basic_vectorbuf &that) { + using std::swap; std::basic_streambuf::swap(that); - std::swap(m_mode, that.m_mode); - m_storage.swap(that.m_storage); - std::swap(m_threshold, that.m_threshold); + swap(m_mode, that.m_mode); + swap(m_storage, that.m_storage); + swap(m_threshold, that.m_threshold); } void reserve(typename vector_type::size_type size) @@ -382,6 +387,16 @@ typedef basic_ovectorstream wovectorstream; typedef basic_vectorstream vectorstream; typedef basic_vectorstream wvectorstream; +template +void swap(basic_vectorbuf &a, basic_vectorbuf &b) { a.swap(b); } + +template +void swap(basic_ivectorstream &a, basic_ivectorstream &b) { a.swap(b); } +template +void swap(basic_ovectorstream &a, basic_ovectorstream &b) { a.swap(b); } +template +void swap(basic_vectorstream &a, basic_vectorstream &b) { a.swap(b); } + } // namespace util #endif // __MAME_UTIL_VECSTREAM_H__ -- cgit v1.2.3-70-g09d2 From 8dad674507a9e8d5ae6e3cb23df717ea0c41443b Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 10 Mar 2016 04:41:08 +1100 Subject: Allow seek to position 0 in a vectorstream with empty storage, always reserve 1k for core_file printf buffer --- src/lib/util/corefile.cpp | 1 + src/lib/util/vecstream.h | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/lib/util/vecstream.h') diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index fd98c8be59f..64169a606fc 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -613,6 +613,7 @@ int core_text_file::puts(char const *s) int core_text_file::vprintf(util::format_argument_pack const &args) { + m_printf_buffer.reserve(1024); m_printf_buffer.seekp(0, ovectorstream::beg); util::stream_format(m_printf_buffer, args); m_printf_buffer.put('\0'); diff --git a/src/lib/util/vecstream.h b/src/lib/util/vecstream.h index 498e35eac5e..bf144501253 100644 --- a/src/lib/util/vecstream.h +++ b/src/lib/util/vecstream.h @@ -116,7 +116,7 @@ public: void reserve(typename vector_type::size_type size) { - if ((m_mode & std::ios_base::out) && (m_storage.size() < size)) + if ((m_mode & std::ios_base::out) && (m_storage.capacity() < size)) { m_storage.reserve(size); adjust(); @@ -150,8 +150,8 @@ protected: bool const out(which & std::ios_base::out); if ((!in && !out) || (in && out && (std::ios_base::cur == dir)) || - (in && (!(m_mode & std::ios_base::in) || !this->gptr())) || - (out && (!(m_mode & std::ios_base::out) || !this->pptr()))) + (in && !(m_mode & std::ios_base::in)) || + (out && !(m_mode & std::ios_base::out))) { return pos_type(off_type(-1)); } -- cgit v1.2.3-70-g09d2