From d5d6dbe85cf270aee7c956429a5a692feca3900f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 29 Apr 2022 04:31:48 +0300 Subject: libcamera: Add operator<<() for V4L2 format classes Implement the stream output operator<<() for the V4L2DeviceFormat and V4L2SubdeviceFormat classes to simplify printing them. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- src/libcamera/v4l2_subdevice.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/libcamera/v4l2_subdevice.cpp') diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index d5ae4605..b3d0ddad 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -190,17 +190,10 @@ const std::map formatInfoMap = { */ const std::string V4L2SubdeviceFormat::toString() const { - std::stringstream mbus; - mbus << size << "-"; + std::stringstream ss; + ss << *this; - const auto it = formatInfoMap.find(mbus_code); - - if (it == formatInfoMap.end()) - mbus << utils::hex(mbus_code, 4); - else - mbus << it->second.name; - - return mbus.str(); + return ss.str(); } /** @@ -220,6 +213,27 @@ uint8_t V4L2SubdeviceFormat::bitsPerPixel() const return it->second.bitsPerPixel; } +/** + * \brief Insert a text representation of a V4L2SubdeviceFormat into an output + * stream + * \param[in] out The output stream + * \param[in] f The V4L2SubdeviceFormat + * \return The output stream \a out + */ +std::ostream &operator<<(std::ostream &out, const V4L2SubdeviceFormat &f) +{ + out << f.size << "-"; + + const auto it = formatInfoMap.find(f.mbus_code); + + if (it == formatInfoMap.end()) + out << utils::hex(f.mbus_code, 4); + else + out << it->second.name; + + return out; +} + /** * \class V4L2Subdevice * \brief A V4L2 subdevice as exposed by the Linux kernel -- cgit v1.2.1