From patchwork Tue May 24 22:58:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16027 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 8A0B8BD161 for ; Tue, 24 May 2022 22:58:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1756C65670; Wed, 25 May 2022 00:58:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433109; bh=c+sScQK4fT7hxRiMXqN58bPZT5GyrKJgbTvVGkrF0lI=; 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=TOw6v4PTnvFZDpvDMyZ4pPa+zMoBb/vQfnj7W0/nVYuzBrwz+X5+hXmbpZkxH44k/ 9uOEdiOLirz7mfYSwTV20d3qwLl9zcn0yNlZYKuYs0i5vXfuryJnYe+KGYnM4GBn1Q eIbWE3w7p5jrkyQoCiR42wynosZyqC9sHG5DfRTnd37FETyu2Ya1gWJDiJgZHh5Yes JVTbzQQbfB2I/v66DtshQoYW6f7LMGjqJFyOWh4+rYvMUgpNce8a/eLDji3njl0AOf KDjLdjCNnVgAU590ngvCQA3LzqMpGOXiTvitWp/vSH+rqdg2F7TF4OUcRFjfpuGuDK QusKWQ4aTwgEw== 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 ED3C360416 for ; Wed, 25 May 2022 00:58:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Q+/WmQua"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6CEEAA58; Wed, 25 May 2022 00:58:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433104; bh=c+sScQK4fT7hxRiMXqN58bPZT5GyrKJgbTvVGkrF0lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q+/WmQuafk/xWtnEjVIIKrqgq7RGQqR3uWfSruTsigpU3q25HLysEyV7fGuSbtCty 0VfHg0JBPnITMLjkhl5DJq3uopY4aMorGnuZ3HEj3Tsd2Ntwuo2A29amecqBvVHLlS y8K2DA8thXbBTPwUsIdQHRdzc5d/okibD+IyibMk= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:05 +0300 Message-Id: <20220524225816.6830-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 01/12] libcamera: yaml_object: Turn Type into an enum class 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" Turn the Type enum into an enum class to force qualifying 'List' and 'Dictionary' in the YamlObject namespace scope. This will help avoiding ambiguities when adding iterator support. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 8 +++--- src/libcamera/yaml_parser.cpp | 32 ++++++++++++------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 3a4f3052fb65..e002fcf59278 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -28,15 +28,15 @@ public: bool isValue() const { - return type_ == Value; + return type_ == Type::Value; } bool isList() const { - return type_ == List; + return type_ == Type::List; } bool isDictionary() const { - return type_ == Dictionary; + return type_ == Type::Dictionary; } #ifndef __DOXYGEN__ @@ -65,7 +65,7 @@ private: friend class YamlParserContext; - enum Type { + enum class Type { Dictionary, List, Value, diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 92fedaebebfd..4b5ea427bf45 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -47,7 +47,7 @@ void setOk(bool *ok, bool result) */ YamlObject::YamlObject() - : type_(Value) + : type_(Type::Value) { } @@ -99,7 +99,7 @@ bool YamlObject::get(const bool &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; if (value_ == "true") { @@ -118,7 +118,7 @@ int32_t YamlObject::get(const int32_t &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; if (value_ == "") @@ -141,7 +141,7 @@ uint32_t YamlObject::get(const uint32_t &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; if (value_ == "") @@ -175,7 +175,7 @@ double YamlObject::get(const double &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; if (value_ == "") @@ -198,7 +198,7 @@ std::string YamlObject::get(const std::string &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; setOk(ok, true); @@ -210,7 +210,7 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != List) + if (type_ != Type::List) return defaultValue; if (list_.size() != 2) @@ -248,7 +248,7 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const */ std::size_t YamlObject::size() const { - if (type_ != List) + if (type_ != Type::List) return 0; return list_.size(); @@ -266,7 +266,7 @@ std::size_t YamlObject::size() const */ const YamlObject &YamlObject::operator[](std::size_t index) const { - if (type_ != List || index >= size()) + if (type_ != Type::List || index >= size()) return empty; return *list_[index]; @@ -326,7 +326,7 @@ std::vector YamlObject::memberNames() const */ const YamlObject &YamlObject::operator[](const std::string &key) const { - if (type_ != Dictionary || !contains(key)) + if (type_ != Type::Dictionary || !contains(key)) return empty; auto iter = dictionary_.find(key); @@ -510,7 +510,7 @@ int YamlParserContext::parseDictionaryOrList(YamlObject::Type type, const std::function &parseItem) { yaml_event_type_t endEventType = YAML_SEQUENCE_END_EVENT; - if (type == YamlObject::Dictionary) + if (type == YamlObject::Type::Dictionary) endEventType = YAML_MAPPING_END_EVENT; /* @@ -554,22 +554,22 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even switch (event->type) { case YAML_SCALAR_EVENT: - yamlObject.type_ = YamlObject::Value; + yamlObject.type_ = YamlObject::Type::Value; readValue(yamlObject.value_, std::move(event)); return 0; case YAML_SEQUENCE_START_EVENT: { - yamlObject.type_ = YamlObject::List; + yamlObject.type_ = YamlObject::Type::List; auto &list = yamlObject.list_; auto handler = [this, &list](EventPtr evt) { list.emplace_back(new YamlObject()); return parseNextYamlObject(*list.back(), std::move(evt)); }; - return parseDictionaryOrList(YamlObject::List, handler); + return parseDictionaryOrList(YamlObject::Type::List, handler); } case YAML_MAPPING_START_EVENT: { - yamlObject.type_ = YamlObject::Dictionary; + yamlObject.type_ = YamlObject::Type::Dictionary; auto &dictionary = yamlObject.dictionary_; auto handler = [this, &dictionary](EventPtr evtKey) { /* Parse key */ @@ -592,7 +592,7 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even auto elem = dictionary.emplace(key, std::make_unique()); return parseNextYamlObject(*elem.first->second.get(), std::move(evtValue)); }; - return parseDictionaryOrList(YamlObject::Dictionary, handler); + return parseDictionaryOrList(YamlObject::Type::Dictionary, handler); } default: