summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pstream.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2019-03-26 11:13:37 +1100
committer Vas Crabb <vas@vastheman.com>2019-03-26 11:13:37 +1100
commit97b67170277437131adf6ed4d60139c172529e4f (patch)
tree7a5cbf608f191075f1612b1af15832c206a3fe2d /src/lib/netlist/plib/pstream.cpp
parentb380514764cf857469bae61c11143a19f79a74c5 (diff)
(nw) Clean up the mess on master
This effectively reverts b380514764cf857469bae61c11143a19f79a74c5 and c24473ddff715ecec2e258a6eb38960cf8c8e98e, restoring the state at 598cd5227223c3b04ca31f0dbc1981256d9ea3ff. Before pushing, please check that what you're about to push is sane. Check your local commit log and ensure there isn't anything out-of-place before pushing to mainline. When things like this happen, it wastes everyone's time. I really don't need this in a week when real work™ is busting my balls and I'm behind where I want to be with preparing for MAME release.
Diffstat (limited to 'src/lib/netlist/plib/pstream.cpp')
-rw-r--r--src/lib/netlist/plib/pstream.cpp131
1 files changed, 26 insertions, 105 deletions
diff --git a/src/lib/netlist/plib/pstream.cpp b/src/lib/netlist/plib/pstream.cpp
index 420f63c9e5e..a7acdaafb52 100644
--- a/src/lib/netlist/plib/pstream.cpp
+++ b/src/lib/netlist/plib/pstream.cpp
@@ -8,9 +8,9 @@
#include "pstream.h"
#include "palloc.h"
+#include <algorithm>
#include <cstdio>
#include <cstdlib>
-#include <algorithm>
// VS2015 prefers _dup
#ifdef _WIN32
@@ -21,34 +21,14 @@
namespace plib {
-pstream::~pstream()
-{
-}
-
// -----------------------------------------------------------------------------
// pistream: input stream
// -----------------------------------------------------------------------------
-pistream::~pistream()
-{
-}
-
// -----------------------------------------------------------------------------
// postream: output stream
// -----------------------------------------------------------------------------
-postream::~postream()
-{
-}
-
-void postream::write(pistream &strm)
-{
- char buf[1024];
- pos_type r;
- while ((r=strm.read(buf, 1024)) > 0)
- write(buf, r);
-}
-
// -----------------------------------------------------------------------------
// Input file stream
// -----------------------------------------------------------------------------
@@ -91,7 +71,7 @@ pifilestream::~pifilestream()
}
}
-pifilestream::pos_type pifilestream::vread(void *buf, const pos_type n)
+pifilestream::pos_type pifilestream::vread(value_type *buf, const pos_type n)
{
pos_type r = fread(buf, 1, n, static_cast<FILE *>(m_file));
if (r < n)
@@ -119,7 +99,7 @@ void pifilestream::vseek(const pos_type n)
throw file_e("Generic file operation failed: {}", m_filename);
}
-pifilestream::pos_type pifilestream::vtell()
+pifilestream::pos_type pifilestream::vtell() const
{
long ret = ftell(static_cast<FILE *>(m_file));
if (ret < 0)
@@ -140,10 +120,6 @@ pstdin::pstdin()
/* nothing to do */
}
-pstdin::~pstdin()
-{
-}
-
// -----------------------------------------------------------------------------
// Output file stream
// -----------------------------------------------------------------------------
@@ -180,12 +156,11 @@ pofilestream::~pofilestream()
}
}
-void pofilestream::vwrite(const void *buf, const pos_type n)
+void pofilestream::vwrite(const value_type *buf, const pos_type n)
{
std::size_t r = fwrite(buf, 1, n, static_cast<FILE *>(m_file));
if (r < n)
{
- //printf("%ld %ld %s\n", r, n, strerror(errno));
if (ferror(static_cast<FILE *>(m_file)))
throw file_write_e(m_filename);
}
@@ -204,7 +179,7 @@ void pofilestream::vseek(const pos_type n)
}
}
-pstream::pos_type pofilestream::vtell()
+pstream::pos_type pofilestream::vtell() const
{
std::ptrdiff_t ret = ftell(static_cast<FILE *>(m_file));
if (ret < 0)
@@ -215,11 +190,6 @@ pstream::pos_type pofilestream::vtell()
return static_cast<pos_type>(ret);
}
-postringstream::~postringstream()
-{
-}
-
-
// -----------------------------------------------------------------------------
// pstderr: write to stderr
// -----------------------------------------------------------------------------
@@ -233,10 +203,6 @@ pstderr::pstderr()
{
}
-pstderr::~pstderr()
-{
-}
-
// -----------------------------------------------------------------------------
// pstdout: write to stdout
// -----------------------------------------------------------------------------
@@ -250,35 +216,32 @@ pstdout::pstdout()
{
}
-pstdout::~pstdout()
-{
-}
-
// -----------------------------------------------------------------------------
// Memory stream
// -----------------------------------------------------------------------------
pimemstream::pimemstream(const void *mem, const pos_type len)
- : pistream(FLAG_SEEKABLE), m_pos(0), m_len(len), m_mem(static_cast<const pstring::mem_t *>(mem))
+ : pistream(FLAG_SEEKABLE), m_pos(0), m_len(len), m_mem(static_cast<const char *>(mem))
{
}
-pimemstream::pimemstream(const pomemstream &ostrm)
-: pistream(FLAG_SEEKABLE), m_pos(0), m_len(ostrm.size()), m_mem(reinterpret_cast<pstring::mem_t *>(ostrm.memory()))
+pimemstream::pimemstream()
+ : pistream(FLAG_SEEKABLE), m_pos(0), m_len(0), m_mem(static_cast<const char *>(nullptr))
{
}
-pimemstream::~pimemstream()
+pimemstream::pimemstream(const pomemstream &ostrm)
+: pistream(FLAG_SEEKABLE), m_pos(0), m_len(ostrm.size()), m_mem(reinterpret_cast<const char *>(ostrm.memory()))
{
}
-pimemstream::pos_type pimemstream::vread(void *buf, const pos_type n)
+pimemstream::pos_type pimemstream::vread(value_type *buf, const pos_type n)
{
pos_type ret = (m_pos + n <= m_len) ? n : m_len - m_pos;
if (ret > 0)
{
- std::copy(m_mem + m_pos, m_mem + m_pos + ret, static_cast<char *>(buf));
+ std::copy(m_mem + m_pos, m_mem + m_pos + ret, reinterpret_cast<char *>(buf));
m_pos += ret;
}
@@ -295,78 +258,45 @@ void pimemstream::vseek(const pos_type n)
}
-pimemstream::pos_type pimemstream::vtell()
+pimemstream::pos_type pimemstream::vtell() const
{
return m_pos;
}
-pistringstream::~pistringstream()
-{
-}
-
// -----------------------------------------------------------------------------
// Output memory stream
// -----------------------------------------------------------------------------
pomemstream::pomemstream()
-: postream(FLAG_SEEKABLE), m_pos(0), m_capacity(1024), m_size(0)
-{
- m_mem = palloc_array<char>(m_capacity);
-}
-
-pomemstream::~pomemstream()
+: postream(FLAG_SEEKABLE), m_pos(0), m_mem(1024)
{
- pfree_array(m_mem);
+ m_mem.clear();
}
-void pomemstream::vwrite(const void *buf, const pos_type n)
+void pomemstream::vwrite(const value_type *buf, const pos_type n)
{
- if (m_pos + n >= m_capacity)
- {
- while (m_pos + n >= m_capacity)
- m_capacity *= 2;
- char *o = m_mem;
- m_mem = palloc_array<char>(m_capacity);
- if (m_mem == nullptr)
- {
- throw out_of_mem_e("pomemstream::vwrite");
- }
- std::copy(o, o + m_pos, m_mem);
- pfree_array(o);
- }
+ if (m_pos + n >= m_mem.size())
+ m_mem.resize(m_pos + n);
- std::copy(static_cast<const char *>(buf), static_cast<const char *>(buf) + n, m_mem + m_pos);
+ std::copy(buf, buf + n, &m_mem[0] + m_pos);
m_pos += n;
- m_size = std::max(m_pos, m_size);
}
void pomemstream::vseek(const pos_type n)
{
m_pos = n;
- m_size = std::max(m_pos, m_size);
- if (m_size >= m_capacity)
- {
- while (m_size >= m_capacity)
- m_capacity *= 2;
- char *o = m_mem;
- m_mem = palloc_array<char>(m_capacity);
- if (m_mem == nullptr)
- {
- throw out_of_mem_e("pomemstream::vseek");
- }
- std::copy(o, o + m_pos, m_mem);
- pfree_array(o);
- }
+ if (m_pos>=m_mem.size())
+ m_mem.resize(m_pos);
}
-pstream::pos_type pomemstream::vtell()
+pstream::pos_type pomemstream::vtell() const
{
return m_pos;
}
bool putf8_reader::readline(pstring &line)
{
- pstring::code_t c = 0;
+ putf8string::code_t c = 0;
m_linebuf = "";
if (!this->readcode(c))
{
@@ -378,23 +308,14 @@ bool putf8_reader::readline(pstring &line)
if (c == 10)
break;
else if (c != 13) /* ignore CR */
- m_linebuf += pstring(c);
+ m_linebuf += putf8string(c);
if (!this->readcode(c))
break;
}
- line = m_linebuf;
+ line = m_linebuf.c_str();
return true;
}
-putf8_fmt_writer::putf8_fmt_writer(postream &strm)
-: pfmt_writer_t()
-, putf8_writer(strm)
-{
-}
-
-putf8_fmt_writer::~putf8_fmt_writer()
-{
-}
void putf8_fmt_writer::vdowrite(const pstring &ls) const
{
@@ -403,4 +324,4 @@ void putf8_fmt_writer::vdowrite(const pstring &ls) const
-}
+} // namespace plib