From a736fe8531b27c4ebb0a71064beaecd35be69250 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 12 Feb 2026 15:36:02 +0200 Subject: [PATCH] libcamera: Replace iterators with range-based for loops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use range-based for loops instead of iterators when iterating over a container. This improves readability. Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze --- include/libcamera/base/utils.h | 8 ++--- src/gstreamer/gstlibcamera-utils.cpp | 50 +++++++++++----------------- src/ipa/rpi/controller/rpi/agc.cpp | 4 +-- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index 4373bc20..37f0d065 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -110,13 +110,13 @@ std::string join(const Container &items, const std::string &sep, UnaryOp op) std::ostringstream ss; bool first = true; - for (auto it = std::begin(items); it != std::end(items); ++it) { + for (const auto &item : items) { if (!first) ss << sep; else first = false; - ss << op(*it); + ss << op(item); } return ss.str(); @@ -128,13 +128,13 @@ std::string join(const Container &items, const std::string &sep) std::ostringstream ss; bool first = true; - for (auto it = std::begin(items); it != std::end(items); ++it) { + for (const auto &item : items) { if (!first) ss << sep; else first = false; - ss << *it; + ss << item; } return ss.str(); diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index bfb094c9..6541d478 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -749,10 +749,9 @@ int gst_libcamera_set_structure_field(GstStructure *structure, const ControlId * switch (value.type()) { case ControlTypeBool: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) { + for (const auto &item : value.get>()) { g_value_init(&x, type); - g_value_set_boolean(&x, *it); + g_value_set_boolean(&x, item); gst_value_array_append_and_take_value(&v, &x); } } else { @@ -762,10 +761,9 @@ int gst_libcamera_set_structure_field(GstStructure *structure, const ControlId * break; case ControlTypeByte: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) { + for (const auto &item : value.get>()) { g_value_init(&x, type); - g_value_set_uint(&x, *it); + g_value_set_uint(&x, item); gst_value_array_append_and_take_value(&v, &x); } } else { @@ -775,10 +773,9 @@ int gst_libcamera_set_structure_field(GstStructure *structure, const ControlId * break; case ControlTypeUnsigned16: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) { + for (const auto &item : value.get>()) { g_value_init(&x, type); - g_value_set_uint(&x, *it); + g_value_set_uint(&x, item); gst_value_array_append_and_take_value(&v, &x); } } else { @@ -788,10 +785,9 @@ int gst_libcamera_set_structure_field(GstStructure *structure, const ControlId * break; case ControlTypeUnsigned32: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) { + for (const auto &item : value.get>()) { g_value_init(&x, type); - g_value_set_uint(&x, *it); + g_value_set_uint(&x, item); gst_value_array_append_and_take_value(&v, &x); } } else { @@ -801,10 +797,9 @@ int gst_libcamera_set_structure_field(GstStructure *structure, const ControlId * break; case ControlTypeInteger32: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) { + for (const auto &item : value.get>()) { g_value_init(&x, type); - g_value_set_int(&x, *it); + g_value_set_int(&x, item); gst_value_array_append_and_take_value(&v, &x); } } else { @@ -827,10 +822,9 @@ int gst_libcamera_set_structure_field(GstStructure *structure, const ControlId * break; case ControlTypeInteger64: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) { + for (const auto &item : value.get>()) { g_value_init(&x, type); - g_value_set_int64(&x, *it); + g_value_set_int64(&x, item); gst_value_array_append_and_take_value(&v, &x); } } else { @@ -840,10 +834,9 @@ int gst_libcamera_set_structure_field(GstStructure *structure, const ControlId * break; case ControlTypeFloat: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) { + for (const auto &item : value.get>()) { g_value_init(&x, type); - g_value_set_float(&x, *it); + g_value_set_float(&x, item); gst_value_array_append_and_take_value(&v, &x); } } else { @@ -862,27 +855,24 @@ int gst_libcamera_set_structure_field(GstStructure *structure, const ControlId * break; case ControlTypeSize: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) - gst_libcamera_gvalue_set_size(&v, *it); + for (const auto &item : value.get>()) + gst_libcamera_gvalue_set_size(&v, item); } else { gst_libcamera_gvalue_set_size(&v, value.get()); } break; case ControlTypePoint: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) - gst_libcamera_gvalue_set_point(&v, *it); + for (const auto &item : value.get>()) + gst_libcamera_gvalue_set_point(&v, item); } else { gst_libcamera_gvalue_set_point(&v, value.get()); } break; case ControlTypeRectangle: if (is_array) { - Span data = value.get>(); - for (auto it = data.begin(); it != data.end(); ++it) - gst_libcamera_gvalue_set_rectangle(&v, *it); + for (const auto &item : value.get>()) + gst_libcamera_gvalue_set_rectangle(&v, item); } else { gst_libcamera_gvalue_set_rectangle(&v, value.get()); } diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp index afda2e36..a8d91f43 100644 --- a/src/ipa/rpi/controller/rpi/agc.cpp +++ b/src/ipa/rpi/controller/rpi/agc.cpp @@ -45,10 +45,10 @@ int Agc::read(const libcamera::YamlObject ¶ms) } const auto &channels = params["channels"].asList(); - for (auto ch = channels.begin(); ch != channels.end(); ch++) { + for (const auto &ch : channels) { LOG(RPiAgc, Debug) << "Read AGC channel"; channelData_.emplace_back(); - int ret = channelData_.back().channel.read(*ch, getHardwareConfig()); + int ret = channelData_.back().channel.read(ch, getHardwareConfig()); if (ret) return ret; }