diff --git a/ChangeLog b/ChangeLog index b9940022..27a6f7f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2022-06-05 Jay Berkenbilt + + * Add integer types to pipeline's operator<<: short, int, long, + long long, unsigned short, unsigned int, unsigned long, unsigned + long long. + 2022-05-30 Jay Berkenbilt * qpdf JSON is now at version 2. New command-line arguments: diff --git a/include/qpdf/Pipeline.hh b/include/qpdf/Pipeline.hh index c3eb787e..0e0fb844 100644 --- a/include/qpdf/Pipeline.hh +++ b/include/qpdf/Pipeline.hh @@ -86,6 +86,24 @@ class QPDF_DLL_CLASS Pipeline Pipeline& operator<<(char const* cstr); QPDF_DLL Pipeline& operator<<(std::string const&); + // Calls QUtil::int_to_string + QPDF_DLL + Pipeline& operator<<(short); + QPDF_DLL + Pipeline& operator<<(int); + QPDF_DLL + Pipeline& operator<<(long); + QPDF_DLL + Pipeline& operator<<(long long); + // Calls QUtil::uint_to_string + QPDF_DLL + Pipeline& operator<<(unsigned short); + QPDF_DLL + Pipeline& operator<<(unsigned int); + QPDF_DLL + Pipeline& operator<<(unsigned long); + QPDF_DLL + Pipeline& operator<<(unsigned long long); // Overloaded write to reduce casting QPDF_DLL diff --git a/libqpdf/Pipeline.cc b/libqpdf/Pipeline.cc index 12a98d04..5bd4557d 100644 --- a/libqpdf/Pipeline.cc +++ b/libqpdf/Pipeline.cc @@ -1,5 +1,7 @@ #include +#include + #include #include @@ -52,6 +54,62 @@ Pipeline::operator<<(std::string const& str) return *this; } +Pipeline& +Pipeline::operator<<(short i) +{ + this->writeString(QUtil::int_to_string(i)); + return *this; +} + +Pipeline& +Pipeline::operator<<(int i) +{ + this->writeString(QUtil::int_to_string(i)); + return *this; +} + +Pipeline& +Pipeline::operator<<(long i) +{ + this->writeString(QUtil::int_to_string(i)); + return *this; +} + +Pipeline& +Pipeline::operator<<(long long i) +{ + this->writeString(QUtil::int_to_string(i)); + return *this; +} + +Pipeline& +Pipeline::operator<<(unsigned short i) +{ + this->writeString(QUtil::uint_to_string(i)); + return *this; +} + +Pipeline& +Pipeline::operator<<(unsigned int i) +{ + this->writeString(QUtil::uint_to_string(i)); + return *this; +} + +Pipeline& +Pipeline::operator<<(unsigned long i) +{ + this->writeString(QUtil::uint_to_string(i)); + return *this; +} + +Pipeline& +Pipeline::operator<<(unsigned long long i) +{ + this->writeString(QUtil::uint_to_string(i)); + return *this; +} + void Pipeline::write(char const* data, size_t len) { diff --git a/manual/release-notes.rst b/manual/release-notes.rst index b964df43..897e04b6 100644 --- a/manual/release-notes.rst +++ b/manual/release-notes.rst @@ -145,7 +145,8 @@ For a detailed list of changes, please see the file - ``writeString``: writes a std::string - - ``operator <<``: for null-terminated C strings and std::strings + - ``operator <<``: for null-terminated C strings, std::strings, + and integer types - Add new ``Pipeline`` type ``Pl_OStream`` to write to a ``std::ostream``.