diff options
Diffstat (limited to 'src/lib/netlist/plib/pstream.h')
-rw-r--r-- | src/lib/netlist/plib/pstream.h | 123 |
1 files changed, 69 insertions, 54 deletions
diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index 6d02c4d1551..83c514da2e1 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -7,9 +7,6 @@ #ifndef PSTREAM_H_ #define PSTREAM_H_ -#include <cstdarg> -#include <cstddef> - #include "pconfig.h" #include "pstring.h" #include "pfmtlog.h" @@ -20,9 +17,8 @@ namespace plib { // pstream: things common to all streams // ----------------------------------------------------------------------------- -class pstream +class pstream : nocopyassignmove { - P_PREVENT_COPYING(pstream) public: using pos_type = std::size_t; @@ -73,7 +69,6 @@ private: class pistream : public pstream { - P_PREVENT_COPYING(pistream) public: explicit pistream(const unsigned flags) : pstream(flags) {} @@ -81,15 +76,6 @@ public: bool eof() const { return ((flags() & FLAG_EOF) != 0); } - /* this digests linux & dos/windows text files */ - - bool readline(pstring &line); - - bool readbyte(char &b) - { - return (read(&b, 1) == 1); - } - pos_type read(void *buf, const unsigned n) { return vread(buf, n); @@ -99,8 +85,6 @@ protected: /* read up to n bytes from stream */ virtual pos_type vread(void *buf, const pos_type n) = 0; -private: - pstringbuffer m_linebuf; }; // ----------------------------------------------------------------------------- @@ -109,30 +93,11 @@ private: class postream : public pstream { - P_PREVENT_COPYING(postream) public: explicit postream(unsigned flags) : pstream(flags) {} virtual ~postream(); - /* this digests linux & dos/windows text files */ - - void writeline(const pstring &line) - { - write(line); - write(10); - } - - void write(const pstring &text) - { - write(text.c_str(), text.blen()); - } - - void write(const char c) - { - write(&c, 1); - } - void write(const void *buf, const pos_type n) { vwrite(buf, n); @@ -153,7 +118,6 @@ private: class pomemstream : public postream { - P_PREVENT_COPYING(pomemstream) public: pomemstream(); @@ -177,8 +141,6 @@ private: class postringstream : public postream { - P_PREVENT_COPYING(postringstream ) - public: postringstream() : postream(0) { } @@ -205,7 +167,6 @@ private: class pofilestream : public postream { - P_PREVENT_COPYING(pofilestream) public: explicit pofilestream(const pstring &fname); @@ -233,7 +194,6 @@ private: class pstderr : public pofilestream { - P_PREVENT_COPYING(pstderr) public: pstderr(); virtual ~pstderr(); @@ -245,7 +205,6 @@ public: class pstdout : public pofilestream { - P_PREVENT_COPYING(pstdout) public: pstdout(); virtual ~pstdout(); @@ -257,7 +216,6 @@ public: class pifilestream : public pistream { - P_PREVENT_COPYING(pifilestream) public: explicit pifilestream(const pstring &fname); @@ -286,7 +244,6 @@ private: class pstdin : public pifilestream { - P_PREVENT_COPYING(pstdin) public: pstdin(); @@ -299,13 +256,13 @@ public: class pimemstream : public pistream { - P_PREVENT_COPYING(pimemstream) public: pimemstream(const void *mem, const pos_type len); explicit pimemstream(const pomemstream &ostrm); virtual ~pimemstream(); + pos_type size() const { return m_len; } protected: /* read up to n bytes from stream */ virtual pos_type vread(void *buf, const pos_type n) override; @@ -324,7 +281,6 @@ private: class pistringstream : public pimemstream { - P_PREVENT_COPYING(pistringstream) public: pistringstream(const pstring &str) : pimemstream(str.c_str(), str.len()), m_str(str) { } virtual ~pistringstream(); @@ -335,27 +291,86 @@ private: }; // ----------------------------------------------------------------------------- -// pstream_fmt_writer_t: writer on top of ostream +// putf8reader_t: reader on top of istream // ----------------------------------------------------------------------------- -class pstream_fmt_writer_t : public plib::pfmt_writer_t<> +/* this digests linux & dos/windows text files */ + +class putf8_reader : plib::nocopyassignmove { - P_PREVENT_COPYING(pstream_fmt_writer_t) public: + explicit putf8_reader(pistream &strm) : m_strm(strm) {} + virtual ~putf8_reader() {} - explicit pstream_fmt_writer_t(postream &strm) : m_strm(strm) {} - virtual ~pstream_fmt_writer_t(); + bool eof() const { return m_strm.eof(); } + bool readline(pstring &line); -protected: - virtual void vdowrite(const pstring &ls) const override + bool readbyte1(char &b) + { + return (m_strm.read(&b, 1) == 1); + } + + bool readcode(pstring::code_t &c) + { + char b[4]; + if (m_strm.read(&b[0], 1) != 1) + return false; + const unsigned l = pstring::traits::codelen(b); + for (unsigned i = 1; i < l; i++) + if (m_strm.read(&b[i], 1) != 1) + return false; + c = pstring::traits::code(b); + return true; + } + +private: + pistream &m_strm; + pstringbuffer m_linebuf; +}; + +// ----------------------------------------------------------------------------- +// putf8writer_t: writer on top of ostream +// ----------------------------------------------------------------------------- + +class putf8_writer : plib::nocopyassignmove +{ +public: + explicit putf8_writer(postream &strm) : m_strm(strm) {} + virtual ~putf8_writer() {} + + void writeline(const pstring &line) const { - m_strm.write(ls); + write(line); + write(10); + } + + void write(const pstring &text) const + { + m_strm.write(text.c_str(), text.blen()); + } + + void write(const pstring::code_t c) const + { + write(pstring(c)); } private: postream &m_strm; }; +class putf8_fmt_writer : public pfmt_writer_t<>, public putf8_writer +{ +public: + + explicit putf8_fmt_writer(postream &strm); + virtual ~putf8_fmt_writer(); + +protected: + virtual void vdowrite(const pstring &ls) const override; + +private: +}; + } #endif /* PSTREAM_H_ */ |