Let wuffs_aux's MemoryInput take a char* ptr

This commit is contained in:
Nigel Tao committed 2020-08-17 10:00:19 +10:00
1 parent 2742a4f4be
commit ca1113620b
4 files changed
+16 -2

No files matched your search

+6
View File
@@ -53,6 +53,12 @@ FileInput::CopyIn(IOBuffer* dst) {
// --------
MemoryInput::MemoryInput(const char* ptr, size_t len)
: m_io(wuffs_base__ptr_u8__reader(
static_cast<uint8_t*>(static_cast<void*>(const_cast<char*>(ptr))),
len,
true)) {}
MemoryInput::MemoryInput(const uint8_t* ptr, size_t len)
: m_io(wuffs_base__ptr_u8__reader(const_cast<uint8_t*>(ptr), len, true)) {}
+1
View File
@@ -63,6 +63,7 @@ class FileInput : public Input {
// It does not take responsibility for freeing the memory when done.
class MemoryInput : public Input {
public:
MemoryInput(const char* ptr, size_t len);
MemoryInput(const uint8_t* ptr, size_t len);
virtual IOBuffer* BringsItsOwnIOBuffer();
+2 -2
View File
@@ -609,7 +609,7 @@ const AuxBaseCc = "" +
"" +
"// --------\n\nFileInput::FileInput(FILE* f) : m_f(f) {}\n\nstd::string //\nFileInput::CopyIn(IOBuffer* dst) {\n if (!m_f) {\n return \"wuffs_aux::sync_io::FileInput: nullptr file\";\n } else if (dst && !dst->meta.closed) {\n size_t n = fread(dst->writer_pointer(), 1, dst->writer_length(), m_f);\n dst->meta.wi += n;\n dst->meta.closed = feof(m_f);\n if (ferror(m_f)) {\n return \"wuffs_aux::sync_io::FileInput: error reading file\";\n }\n }\n return \"\";\n}\n\n" +
"" +
"// --------\n\nMemoryInput::MemoryInput(const uint8_t* ptr, size_t len)\n : m_io(wuffs_base__ptr_u8__reader(const_cast<uint8_t*>(ptr), len, true)) {}\n\nIOBuffer* //\nMemoryInput::BringsItsOwnIOBuffer() {\n return &m_io;\n}\n\nstd::string //\nMemoryInput::CopyIn(IOBuffer* dst) {\n if (dst && !dst->meta.closed && (dst != &m_io)) {\n size_t nd = dst->writer_length();\n size_t ns = m_io.reader_length();\n size_t n = (nd < ns) ? nd : ns;\n memcpy(dst->writer_pointer(), m_io.reader_pointer(), n);\n m_io.meta.ri += n;\n dst->meta.wi += n;\n dst->meta.closed = m_io.reader_length() == 0;\n }\n return \"\";\n}\n\n" +
"// --------\n\nMemoryInput::MemoryInput(const char* ptr, size_t len)\n : m_io(wuffs_base__ptr_u8__reader(\n static_cast<uint8_t*>(static_cast<void*>(const_cast<char*>(ptr))),\n len,\n true)) {}\n\nMemoryInput::MemoryInput(const uint8_t* ptr, size_t len)\n : m_io(wuffs_base__ptr_u8__reader(const_cast<uint8_t*>(ptr), len, true)) {}\n\nIOBuffer* //\nMemoryInput::BringsItsOwnIOBuffer() {\n return &m_io;\n}\n\nstd::string //\nMemoryInput::CopyIn(IOBuffer* dst) {\n if (dst && !dst->meta.closed && (dst != &m_io)) {\n size_t nd = dst->writer_length();\n size_t ns = m_io.reader_length();\n size_t n = (nd < ns) ? nd : ns;\n memcpy(dst->writer_pointer(), m_io.reader_pointer(), n);\n m_io.meta.ri += n;\n dst->meta.wi += n;\n dst->meta.closed = m_io.reader_length() == 0;\n }\n return \"\";\n}\n\n" +
"" +
"// --------\n\n} // namespace sync_io\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__AUX__BASE)\n" +
""
@@ -621,7 +621,7 @@ const AuxBaseHh = "" +
"" +
"// --------\n\n// FileInput is an Input that reads from a file source.\n//\n// It does not take responsibility for closing the file when done.\nclass FileInput : public Input {\n public:\n FileInput(FILE* f);\n\n virtual std::string CopyIn(IOBuffer* dst);\n\n private:\n FILE* m_f;\n\n // Delete the copy and assign constructors.\n FileInput(const FileInput&) = delete;\n FileInput& operator=(const FileInput&) = delete;\n};\n\n" +
"" +
"// --------\n\n// MemoryInput is an Input that reads from an in-memory source.\n//\n// It does not take responsibility for freeing the memory when done.\nclass MemoryInput : public Input {\n public:\n MemoryInput(const uint8_t* ptr, size_t len);\n\n virtual IOBuffer* BringsItsOwnIOBuffer();\n virtual std::string CopyIn(IOBuffer* dst);\n\n private:\n IOBuffer m_io;\n\n // Delete the copy and assign constructors.\n MemoryInput(const MemoryInput&) = delete;\n MemoryInput& operator=(const MemoryInput&) = delete;\n};\n\n" +
"// --------\n\n// MemoryInput is an Input that reads from an in-memory source.\n//\n// It does not take responsibility for freeing the memory when done.\nclass MemoryInput : public Input {\n public:\n MemoryInput(const char* ptr, size_t len);\n MemoryInput(const uint8_t* ptr, size_t len);\n\n virtual IOBuffer* BringsItsOwnIOBuffer();\n virtual std::string CopyIn(IOBuffer* dst);\n\n private:\n IOBuffer m_io;\n\n // Delete the copy and assign constructors.\n MemoryInput(const MemoryInput&) = delete;\n MemoryInput& operator=(const MemoryInput&) = delete;\n};\n\n" +
"" +
"// --------\n\n} // namespace sync_io\n\n} // namespace wuffs_aux\n" +
""
+7
View File
@@ -8455,6 +8455,7 @@ class FileInput : public Input {
// It does not take responsibility for freeing the memory when done.
class MemoryInput : public Input {
public:
MemoryInput(const char* ptr, size_t len);
MemoryInput(const uint8_t* ptr, size_t len);
virtual IOBuffer* BringsItsOwnIOBuffer();
@@ -28999,6 +29000,12 @@ FileInput::CopyIn(IOBuffer* dst) {
// --------
MemoryInput::MemoryInput(const char* ptr, size_t len)
: m_io(wuffs_base__ptr_u8__reader(
static_cast<uint8_t*>(static_cast<void*>(const_cast<char*>(ptr))),
len,
true)) {}
MemoryInput::MemoryInput(const uint8_t* ptr, size_t len)
: m_io(wuffs_base__ptr_u8__reader(const_cast<uint8_t*>(ptr), len, true)) {}