Add integer types to Pipeline::operator<<

This commit is contained in:
Jay Berkenbilt 2022-06-05 12:33:36 -04:00
parent 3fe6a1f5e9
commit f588d74140
4 changed files with 84 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2022-06-05 Jay Berkenbilt <ejb@ql.org>
* 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 <ejb@ql.org>
* qpdf JSON is now at version 2. New command-line arguments:

View File

@ -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

View File

@ -1,5 +1,7 @@
#include <qpdf/Pipeline.hh>
#include <qpdf/QUtil.hh>
#include <cstring>
#include <stdexcept>
@ -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)
{

View File

@ -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``.