From patchwork Thu Jun 16 14:23:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16237 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A47A1C3273 for ; Thu, 16 Jun 2022 14:24:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9EE7765642; Thu, 16 Jun 2022 16:24:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655389461; bh=0KeW0Buaom75cIuO+HgipUaC0yUDEfXN25HJl3AYNWw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ZJ9W8H/gmJhBaQKsy5hiG17L2zrD+V8LvF4lyc8ZlBzfs35v3p9UlGBbfYuvXGeD/ /5+df3KsY/jSoJOR2wXufXg3ZZXGngZQ9/oryrAht0jMZnVIqeiybQLHlaVtHV1i9P zZNEsSV0EH706iJRtcEd1z6fYyzcbZvbkucW7u3zpGx2MlET03tGzaFRc0tJdWLfwP 9wureCbGl8KU3hKp1dc2/CKEpVOf3Z60Q3t4mn8OnZ3imfCPGc+3hR2vSCLPTVkPZB wXxVEi8uuYf833YMGveYSAtXVBDutYASGY4ilCLu4l/8nflhbbMlNC3FjGWT+SA1v/ ya9F5tf7D8QmA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 22ECB600F0 for ; Thu, 16 Jun 2022 16:24:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qXv8Bo/T"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 70FF3898; Thu, 16 Jun 2022 16:24:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655389458; bh=0KeW0Buaom75cIuO+HgipUaC0yUDEfXN25HJl3AYNWw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qXv8Bo/TyU0vCmqcHjQFWQZSEmOX+qkAEKnGjq9XrUmwUnX49B11+5JKlx6izwgBB BhT4PWVlgN8T1zO8OD03dB3cIFJJQ7La1dip4GDFGqOHYshebeq6uxryeoYHa2bHHR NH+Cp6cQJq4eH62Q3OxiLa+5aNLcO5yFlMQMqMr4= To: libcamera-devel@lists.libcamera.org Date: Thu, 16 Jun 2022 17:23:57 +0300 Message-Id: <20220616142403.20723-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> References: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/7] libcamera: yaml_parser: Use std::is_same_v<> X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" As the YamlObject class is internal to libcamera, it can use the full C++17 API. Replace std::is_same<>::value with std::is_same_v<>. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Han-Lin Chen --- include/libcamera/internal/yaml_parser.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index be5f0914703f..29b7b218f0d9 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -44,12 +44,12 @@ public: #ifndef __DOXYGEN__ template::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value> * = nullptr> + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v> * = nullptr> #else template #endif From patchwork Thu Jun 16 14:23:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16238 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 406ACC3274 for ; Thu, 16 Jun 2022 14:24:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1DA4865638; Thu, 16 Jun 2022 16:24:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655389462; bh=eBhtyfWSH8NxgAETTgSClfRGZZdpaQDweJah+lUuLr8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=rGrcWipz6eA8gBVZq0VUx4itdRPodySUJK2Rl+cdjX06L2qpvv6i4k6hViAFtfiw3 OG2G2Rqfe4XZVuinQ52Y+ZDmcxgI4RJAXo/S50wmFkWxtRzZivKz4UYYVuKLh/Gu+n 9Gf2F53/A7yC4H4a5kxK9x3Sjsov7jDp8LeJ1GodGXI8JV+UCyTnDAwV0akdVA6xlH XbDullhijzx9WQiB+oaRCMcrwZMyzpxURuca+ajgy5teoutqnaoogTcQBMaflomn/0 3Qa0Byu6w76tQIaZjqKQe6nVpudOUwVm37I5B+mRiuUsCU7mNKR2/YK+VFBAiY/r3R v/Qb3zQ7yt3ww== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E0C0600F0 for ; Thu, 16 Jun 2022 16:24:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WnkBj2h5"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0E0B48AF; Thu, 16 Jun 2022 16:24:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655389459; bh=eBhtyfWSH8NxgAETTgSClfRGZZdpaQDweJah+lUuLr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WnkBj2h5DQzzZ7HxZzicXgdSvyRe+XSCtC1k1QFk+ZXFEqfPhA0xDo3hDxL2e5DDq KVrHVwn3HxJeBxIReYikAnG4xovPH9P0l65lWyTMup9hhSnF4XsXtJyZItJhoJ7I0s K88vofc9CKHtJo5xeVegyOL5ZXH1nUxXaCC6zBcM= To: libcamera-devel@lists.libcamera.org Date: Thu, 16 Jun 2022 17:23:58 +0300 Message-Id: <20220616142403.20723-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> References: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/7] libcamera: yaml_parser: Add iterator API X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Allow using range-based for loops over YamlObject instances by implementing iterators. New YamlObject::DictAdapter and YamlObject::ListAdapter adapter classes are introduced to provide different iterators depending on the object type. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Han-Lin Chen --- include/libcamera/internal/yaml_parser.h | 117 ++++++++++++++++++++++- src/libcamera/yaml_parser.cpp | 39 ++++++++ 2 files changed, 154 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 29b7b218f0d9..8edd32354184 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -22,7 +23,116 @@ class YamlParserContext; class YamlObject { +private: + using DictContainer = std::map>; + using ListContainer = std::vector>; + public: +#ifndef __DOXYGEN__ + template + class Iterator + { + public: + using difference_type = std::ptrdiff_t; + using iterator_category = std::bidirectional_iterator_tag; + + Iterator(typename Container::const_iterator it) + : it_(it) + { + } + + Derived &operator++() + { + ++it_; + return *static_cast(this); + } + + Derived operator++(int) + { + Derived it = *static_cast(this); + it_++; + return it; + } + + friend bool operator==(const Iterator &a, const Iterator &b) + { + return a.it_ == b.it_; + } + + friend bool operator!=(const Iterator &a, const Iterator &b) + { + return a.it_ != b.it_; + } + + protected: + typename Container::const_iterator it_; + }; + + template + class Adapter + { + public: + Adapter(const Container &container) + : container_(container) + { + } + + Iterator begin() const + { + return Iterator{ container_.begin() }; + } + + Iterator end() const + { + return Iterator{ container_.end() }; + } + + protected: + const Container &container_; + }; + + class ListIterator : public Iterator + { + public: + using value_type = const YamlObject &; + using pointer = const YamlObject *; + using reference = value_type; + + value_type operator*() const + { + return *it_->get(); + } + + pointer operator->() const + { + return it_->get(); + } + }; + + class DictIterator : public Iterator + { + public: + using value_type = std::pair; + using pointer = value_type *; + using reference = value_type &; + + value_type operator*() const + { + return { it_->first, *it_->second.get() }; + } + }; + + class DictAdapter : public Adapter + { + public: + using key_type = std::string; + }; + + class ListAdapter : public Adapter + { + }; +#endif /* __DOXYGEN__ */ + YamlObject(); ~YamlObject(); @@ -55,6 +165,9 @@ public: #endif T get(const T &defaultValue, bool *ok = nullptr) const; + DictAdapter asDict() const { return DictAdapter{ dictionary_ }; } + ListAdapter asList() const { return ListAdapter{ list_ }; } + const YamlObject &operator[](std::size_t index) const; bool contains(const std::string &key) const; @@ -75,8 +188,8 @@ private: Type type_; std::string value_; - std::vector> list_; - std::map> dictionary_; + ListContainer list_; + DictContainer dictionary_; }; class YamlParser final diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 85f6694f5fde..4df7e5a33d47 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -259,6 +259,45 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const #endif /* __DOXYGEN__ */ +/** + * \fn YamlObject::asDict() const + * \brief Wrap a dictionary YamlObject in an adapter that exposes iterators + * + * The YamlObject class doesn't directly implement iterators, as the iterator + * type depends on whether the object is a Dictionary or List. This function + * wraps a YamlObject of Dictionary type into an adapter that exposes + * iterators, as well as begin() and end() functions, allowing usage of + * range-based for loops with YamlObject. As YAML mappings are not ordered, the + * iteration order is not specified. + * + * The iterator's value_type is a + * std::pair. + * + * If the YamlObject is not of Dictionary type, the returned adapter operates + * as an empty container. + * + * \return An adapter of unspecified type compatible with range-based for loops + */ + +/** + * \fn YamlObject::asList() const + * \brief Wrap a list YamlObject in an adapter that exposes iterators + * + * The YamlObject class doesn't directly implement iterators, as the iterator + * type depends on whether the object is a Dictionary or List. This function + * wraps a YamlObject of List type into an adapter that exposes iterators, as + * well as begin() and end() functions, allowing usage of range-based for loops + * with YamlObject. As YAML lists are ordered, the iteration order is identical + * to the list order in the YAML data. + * + * The iterator's value_type is a const YamlObject &. + * + * If the YamlObject is not of List type, the returned adapter operates as an + * empty container. + * + * \return An adapter of unspecified type compatible with range-based for loops + */ + /** * \fn YamlObject::operator[](std::size_t index) const * \brief Retrieve the element from list YamlObject by index From patchwork Thu Jun 16 14:23:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16239 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id CDFF3C3275 for ; Thu, 16 Jun 2022 14:24:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C7A146563B; Thu, 16 Jun 2022 16:24:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655389463; bh=l/IgiffefRYZLY6fMuKPGTjR9AJ3eP6LacrA1gQk1Yc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=STPtpu15iIqr/6mauXJv07yc7bc/Qsd+a4ZN11hrjNAS/U73D+8PcN8f8KgopLqOV bpzUUSl5jRTie7Gw7e27n+AJh2UaHbjdc4kQXNS796i8CTcpo7PThixznkqcE8+V3E TH/LE5zVIBO2qc04xMFosv5JNlfwX4BNu96Me/RUz7QTMHYNvMY/OzAnAtG6z1pD0g EzWOX9i+EJeCTV+51OyGX00+20abd/kJk1ZQR1psx1HFOrvK+1H6aHfQFjLN1V3M6g 379evsWpEZdEpaTOAvv6rRw6HqKjALpZF0fb5wU6YwUr0+p9sw0oYsrvRYGJRQQOZq YJDsCDuEG3wnw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4240165635 for ; Thu, 16 Jun 2022 16:24:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HTZBke8b"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A61B3415; Thu, 16 Jun 2022 16:24:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655389460; bh=l/IgiffefRYZLY6fMuKPGTjR9AJ3eP6LacrA1gQk1Yc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HTZBke8bnEAqdckiXUJ6jgl1tR62Gpu3tVAzra9SW4sfcs4HhJZU4tIFvja6Q3yZO IILDG6MVTuG57AenIYNWsGWi1QR2WQwbmEV/aq/99kr9G8ohpnwmR2xCLZpuzMLAMt gTeljWlETZFmsrjh5zC2cHJNTH9KtqxLNGS3gAz0= To: libcamera-devel@lists.libcamera.org Date: Thu, 16 Jun 2022 17:23:59 +0300 Message-Id: <20220616142403.20723-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> References: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/7] test: yaml_parser: Extend tests to cover the iterator API X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Test iteration over lists and dictionaries to test the YamlObject iterator API. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Han-Lin Chen --- test/yaml-parser.cpp | 99 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 19 deletions(-) diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 5ff4c3236dbf..ab6e9a01c0fe 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -5,11 +5,14 @@ * yaml-parser.cpp - YAML parser operations tests */ +#include #include +#include #include #include #include +#include #include "libcamera/internal/yaml_parser.h" @@ -373,15 +376,39 @@ protected: return TestFail; } - if (listObj.size() > 2) { + static constexpr std::array listValues{ + "James", + "Mary", + }; + + if (listObj.size() != listValues.size()) { cerr << "List object parse with wrong size" << std::endl; return TestFail; } - if (listObj[0].get("") != "James" || - listObj[1].get("") != "Mary") { - cerr << "List object parse as wrong value" << std::endl; - return TestFail; + unsigned int i = 0; + for (auto &elem : listObj.asList()) { + if (i >= listValues.size()) { + std::cerr << "Too many elements in list during iteration" + << std::endl; + return TestFail; + } + + std::string value = listValues[i]; + + if (&elem != &listObj[i]) { + std::cerr << "List element " << i << " has wrong address" + << std::endl; + return TestFail; + } + + if (elem.get("") != value) { + std::cerr << "List element " << i << " has wrong value" + << std::endl; + return TestFail; + } + + i++; } /* Test dictionary object */ @@ -422,19 +449,60 @@ protected: return TestFail; } - if (dictObj.size() != 3) { - cerr << "Dictionary object parse with wrong size" << std::endl; + std::map dictValues{ { + { "a", 1 }, + { "b", 2 }, + { "c", 3 }, + } }; + + size_t dictSize = dictValues.size(); + + if (dictObj.size() != dictSize) { + cerr << "Dictionary object has wrong size" << std::endl; return TestFail; } + i = 0; + for (const auto &[key, elem] : dictObj.asDict()) { + if (i >= dictSize) { + std::cerr << "Too many elements in dictionary during iteration" + << std::endl; + return TestFail; + } + + const auto item = dictValues.find(key); + if (item == dictValues.end()) { + std::cerr << "Dictionary key " << i << " has wrong value" + << std::endl; + return TestFail; + } + + if (&elem != &dictObj[key]) { + std::cerr << "Dictionary element " << i << " has wrong address" + << std::endl; + return TestFail; + } + + if (elem.get(0) != item->second) { + std::cerr << "Dictionary element " << i << " has wrong value" + << std::endl; + return TestFail; + } + + /* + * Erase the item to make sure that each iteration + * produces a different value. + */ + dictValues.erase(item); + i++; + } + + /* Make sure utils::map_keys() works on the adapter. */ + (void)utils::map_keys(dictObj.asDict()); + auto memeberNames = dictObj.memberNames(); sort(memeberNames.begin(), memeberNames.end()); - if (memeberNames.size() != 3) { - cerr << "Dictionary object fail to extra member names" << std::endl; - return TestFail; - } - if (memeberNames[0] != "a" || memeberNames[1] != "b" || memeberNames[2] != "c") { @@ -442,13 +510,6 @@ protected: return TestFail; } - if (dictObj["a"].get(0) != 1 || - dictObj["b"].get(0) != 2 || - dictObj["c"].get(0) != 3) { - cerr << "Dictionary object fail to parse member value" << std::endl; - return TestFail; - } - /* Test leveled objects */ auto &level1Obj = (*root)["level1"]; From patchwork Thu Jun 16 14:24:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16240 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 47906BD808 for ; Thu, 16 Jun 2022 14:24:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2D1065641; Thu, 16 Jun 2022 16:24:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655389464; bh=Ic3F3Afbq5cwq4A8ifAQhqKg4w3eXeU4Dm+xJoUklrM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=D9wZzsfYXFKeAspcyFkpcgiBEobEXVG6AaDF8TkXXSeluC+gj1w7gwkYXahs6QQjU C1Q8kWsdkR5rb7HwAMHFQNKeDrSzQd6mBSUJmGQGt4N8UdE9XfhDBZOj3sXGpnc558 MU94zNs/2sENAqgJmFyN94Ixz0HA7cvMcwDSZzOB9BTMDW2H2TBh+uy43jDLHhX3+D fozhEVPhGduiErpYqVVNp/Fw0l1vCwJhg3Cs4bqPjPjq+8WZZhfug/XjZXoh4NCGg0 v6c71aabR56b5iCKzzoEaukhkB3uSrGKiwEJ0YNmNOxJ8CfLPNu4tu99MPlMMTv2sR W8CpS4cn3jgAA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DE99865635 for ; Thu, 16 Jun 2022 16:24:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DVUuGjnV"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 444F1898; Thu, 16 Jun 2022 16:24:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655389460; bh=Ic3F3Afbq5cwq4A8ifAQhqKg4w3eXeU4Dm+xJoUklrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DVUuGjnVffbpor9ACXyCXzhaOKSMWRvIRRaaVs66tUPUX+e4oWLcesfltn9VoRsly qTDJl+8K966EM+IV664CbN+obPK9MhA7nazHVxO3EAEtzOpL+qV3kETPjFXKwmesci 69j1+OoeVu6flVE9zIfvpG2UcOvjz8V8s2FHuXz8= To: libcamera-devel@lists.libcamera.org Date: Thu, 16 Jun 2022 17:24:00 +0300 Message-Id: <20220616142403.20723-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> References: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/7] android: Use the YamlObject iterator API X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace usage of YamlObject::memberNames() with the more efficient iterator API. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Han-Lin Chen --- src/android/camera_hal_config.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/android/camera_hal_config.cpp b/src/android/camera_hal_config.cpp index ac484b8df1bd..bacfe4b9c505 100644 --- a/src/android/camera_hal_config.cpp +++ b/src/android/camera_hal_config.cpp @@ -82,10 +82,8 @@ int CameraHalConfig::Private::parseConfigFile(File &file, if (!yamlObjectCameras.isDictionary()) return -EINVAL; - std::vector cameraIds = yamlObjectCameras.memberNames(); - for (const std::string &cameraId : cameraIds) { - if (parseCameraConfigData(cameraId, - yamlObjectCameras[cameraId])) + for (const auto &[cameraId, configData] : yamlObjectCameras.asDict()) { + if (parseCameraConfigData(cameraId, configData)) return -EINVAL; } From patchwork Thu Jun 16 14:24:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16241 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D653AC3276 for ; Thu, 16 Jun 2022 14:24:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 706F165635; Thu, 16 Jun 2022 16:24:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655389466; bh=ZttNfuLXQgYgSHWyV79OsPjjYDVeCxtqYKq4DxCSCuo=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=L4xGPbGyZnybSTMvNra57qTVPRMIosuEG0GYYgvVV3lEklJxNk+P6v7xIGW1d+wdr 9IHF4KYQ5KTvukaR0T0bI+4UcfSd8h3NZSHUpHy9tvDgZ1pfRvc+NqGZrjc3MBo8c4 XEJkZwamijT7vmFBVyJso79QeoYMf94X9stvifqRqP8KbjrQVHOLKffOV3fiRv8ZkH M0/PoCJXkz18MHYcboIwdjRFZTASQ9t58Qpi2doNxJrzQgOxppPfA66B0vxbI1zNwO rW8hQXBKFDxXF0xslKVmmaL1Le0OJfi8JI63/3Y2uZrEn9UFn0QiVehOwrpo1W+bEk g1LDFVOpFmAng== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D282A65635 for ; Thu, 16 Jun 2022 16:24:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aTyfIj8Z"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D97FD415; Thu, 16 Jun 2022 16:24:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655389461; bh=ZttNfuLXQgYgSHWyV79OsPjjYDVeCxtqYKq4DxCSCuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aTyfIj8ZkwG7e20Dwna2k/lk0AyY88eTVIclh6/b2tfFamxMBCTkSwqkuclhWJ5/X okmk4ymcORzXsPNsIsGkpRNS6v0wAmJ/UTRjyjZlqmR7HBLG5Ex4TBQzRlnqoPkNNg pwKXZQvV1jZBK79DHZlPFcIf0uMUP0fbAZBVNYVU= To: libcamera-devel@lists.libcamera.org Date: Thu, 16 Jun 2022 17:24:01 +0300 Message-Id: <20220616142403.20723-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> References: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/7] libcamera: yaml_parser: Remove memberNames() function X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Now that YamlObject supports iteration, the memberNames() function isn't useful anymore as it can be implemented using utils::map_keys() if really needed. Drop it. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Han-Lin Chen --- include/libcamera/internal/yaml_parser.h | 1 - src/libcamera/yaml_parser.cpp | 22 ---------------------- test/yaml-parser.cpp | 10 ---------- 3 files changed, 33 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 8edd32354184..811be1affcc0 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -172,7 +172,6 @@ public: bool contains(const std::string &key) const; const YamlObject &operator[](const std::string &key) const; - std::vector memberNames() const; private: LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject) diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 4df7e5a33d47..9b6e70cbfcf3 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -335,28 +335,6 @@ bool YamlObject::contains(const std::string &key) const return true; } -/** - * \fn YamlObject::memberNames() - * \brief Retrieve all member names of the dictionary - * - * This function retrieve member names of a YamlObject. Only YamlObject - * instances of Dictionary type associate elements with names, calling this - * function on other types of instances is invalid and results in undefined - * behaviour. - * - * \todo Replace this function with an iterator-based API - * - * \return A vector of string as the member names - */ -std::vector YamlObject::memberNames() const -{ - std::vector memberNames; - for (auto &[key, _] : dictionary_) - memberNames.push_back(key); - - return memberNames; -} - /** * \fn YamlObject::operator[](const std::string &key) const * \brief Retrieve a member by name from the dictionary diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index ab6e9a01c0fe..38f848232fa6 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -500,16 +500,6 @@ protected: /* Make sure utils::map_keys() works on the adapter. */ (void)utils::map_keys(dictObj.asDict()); - auto memeberNames = dictObj.memberNames(); - sort(memeberNames.begin(), memeberNames.end()); - - if (memeberNames[0] != "a" || - memeberNames[1] != "b" || - memeberNames[2] != "c") { - cerr << "Dictionary object fail to parse member names" << std::endl; - return TestFail; - } - /* Test leveled objects */ auto &level1Obj = (*root)["level1"]; From patchwork Thu Jun 16 14:24:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16242 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DAE69C3277 for ; Thu, 16 Jun 2022 14:24:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D05106564E; Thu, 16 Jun 2022 16:24:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655389467; bh=r9lS+1HujmZ7MfQVdOdG+DnAUFPXoJWwZN4J+mpa6RI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QYYm1YIFIVI1JBUy96UebjcV5BjeKG1A7IH9SLikEMe9DfOX80robQJy/82mcPdpi Fnd77PIa5p6MJdEFxiWA77KP0w+CoNCshQT7ElsHv5l155sdsb0xv8TqAQhUtfAz0W N5CtaqhOFiX1QbK9znGSWo92uqIBpu1cqH1fpp7c6TB3YzA8Q5nVJHSPMzOueDAsHt UzTO/LhuDrNhv4m5twbaszIQfafpXepxPlkdzHsMlND4gtAbTlK+ky0Y11rO8AF4an zEDOWJpCwNwm3CqFFgHa3qX5ii+oaaqieqSY+M/CrcC+avJDQWwQle+QgldExd4E6j w4CJICfxH27KQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 225A965646 for ; Thu, 16 Jun 2022 16:24:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MFfnWv8k"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7A810898; Thu, 16 Jun 2022 16:24:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655389461; bh=r9lS+1HujmZ7MfQVdOdG+DnAUFPXoJWwZN4J+mpa6RI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MFfnWv8kwvMsJg2OLsCusS0b2cgaUCjOzNONzKZdU1c2DhQca7tJsRozwby2tfkrs NlBoLS6FKMQNRgEywULYZLmuyTK/LxHz43JT+aG2rAd67fkCSov8Zv209IRQYwvbsH X2XAxdFxK7+lOfgmoUVLyvIFiT7GnXzWIVo4ubu0= To: libcamera-devel@lists.libcamera.org Date: Thu, 16 Jun 2022 17:24:02 +0300 Message-Id: <20220616142403.20723-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> References: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/7] libcamera: yaml_parser: Fix range checks for 32-bit integers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The strtol() and strtoul() functions return long integers, which may be larger than 32-bit integers. Add manual range checks. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Han-Lin Chen --- src/libcamera/yaml_parser.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 9b6e70cbfcf3..bd4b501b1422 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -151,9 +152,11 @@ int32_t YamlObject::get(const int32_t &defaultValue, bool *ok) const char *end; errno = 0; - int32_t value = std::strtol(value_.c_str(), &end, 10); + long value = std::strtol(value_.c_str(), &end, 10); - if ('\0' != *end || errno == ERANGE) + if ('\0' != *end || errno == ERANGE || + value < std::numeric_limits::min() || + value > std::numeric_limits::max()) return defaultValue; setOk(ok, true); @@ -185,9 +188,11 @@ uint32_t YamlObject::get(const uint32_t &defaultValue, bool *ok) const char *end; errno = 0; - uint32_t value = std::strtoul(value_.c_str(), &end, 10); + unsigned long value = std::strtoul(value_.c_str(), &end, 10); - if ('\0' != *end || errno == ERANGE) + if ('\0' != *end || errno == ERANGE || + value < std::numeric_limits::min() || + value > std::numeric_limits::max()) return defaultValue; setOk(ok, true); From patchwork Thu Jun 16 14:24:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16243 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 264ABC3278 for ; Thu, 16 Jun 2022 14:24:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F1B5B6564A; Thu, 16 Jun 2022 16:24:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655389468; bh=m0wL503PX9JwlUdA0hctOJ5EKRrME6YGwFemjoRVaqk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=b/3KaSkm4zwdKn4i0GSUNCRXEd3l2FEqjvEhDUhAoesX/Po/PMJGRy9rrCYs2VG7S TAo+Xatxo5UaEy7Dr5OsZtI1zqRfOPJgi1oe2GiFtvFdJ/ND6JMuM9Zvtq18Su/DBD tPEeAZRxPOac5Z5TtbFwywgp987Zeeaym8/TCZw9I0PecCSU+F5OfdukeWBOAKyTfr WF/ll3MCcugaA0SeNCNBvjtWFVL/6uNJ9QTl3gqKZM4cNWpXGuQassNvC/gM8LajMB 9wAsaA9tkw13MseH7CgZQKnEJb9MtarMrwcnriQ3boMYh5VVYwDd79ZZ3o1v9Tlis5 nOuA9R/BIySWw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BA34165649 for ; Thu, 16 Jun 2022 16:24:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="G2WJMMJE"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1F184415; Thu, 16 Jun 2022 16:24:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655389462; bh=m0wL503PX9JwlUdA0hctOJ5EKRrME6YGwFemjoRVaqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G2WJMMJEgn3Xk3Ko68pxS2rpLILQPlqvEpBsHPkjCbEKaJsdHbnlYM5V3SBZwBdsM aEIGSLSkezI6AAep5WNXZQAuhBQh649ogapeAhUja+b94c/6FvhFfOXaPe40+Qpzr0 BF15zNmFeWyaefglBKE5UYWDeXb1vpOn/xHfevUE= To: libcamera-devel@lists.libcamera.org Date: Thu, 16 Jun 2022 17:24:03 +0300 Message-Id: <20220616142403.20723-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> References: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/7] libcamera: yaml_parser: Add get() specializations for 16-bit integers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Extend the YamlObject::get() function template to support 16-bit integers. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Han-Lin Chen --- include/libcamera/internal/yaml_parser.h | 2 + src/libcamera/yaml_parser.cpp | 61 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 811be1affcc0..90d348eac74c 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -156,6 +156,8 @@ public: typename std::enable_if_t< std::is_same_v || std::is_same_v || + std::is_same_v || + std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v || diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index bd4b501b1422..5c45e44e49c3 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -138,6 +138,67 @@ bool YamlObject::get(const bool &defaultValue, bool *ok) const return defaultValue; } +template<> +int16_t YamlObject::get(const int16_t &defaultValue, bool *ok) const +{ + setOk(ok, false); + + if (type_ != Type::Value) + return defaultValue; + + if (value_ == "") + return defaultValue; + + char *end; + + errno = 0; + int16_t value = std::strtol(value_.c_str(), &end, 10); + + if ('\0' != *end || errno == ERANGE || + value < std::numeric_limits::min() || + value > std::numeric_limits::max()) + return defaultValue; + + setOk(ok, true); + return value; +} + +template<> +uint16_t YamlObject::get(const uint16_t &defaultValue, bool *ok) const +{ + setOk(ok, false); + + if (type_ != Type::Value) + return defaultValue; + + if (value_ == "") + return defaultValue; + + /* + * libyaml parses all scalar values as strings. When a string has + * leading spaces before a minus sign, for example " -10", strtoul + * skips leading spaces, accepts the leading minus sign, and the + * calculated digits are negated as if by unary minus. Rule it out in + * case the user gets a large number when the value is negative. + */ + std::size_t found = value_.find_first_not_of(" \t"); + if (found != std::string::npos && value_[found] == '-') + return defaultValue; + + char *end; + + errno = 0; + uint16_t value = std::strtoul(value_.c_str(), &end, 10); + + if ('\0' != *end || errno == ERANGE || + value < std::numeric_limits::min() || + value > std::numeric_limits::max()) + return defaultValue; + + setOk(ok, true); + return value; +} + template<> int32_t YamlObject::get(const int32_t &defaultValue, bool *ok) const {