From 27fb47f70b55000fbd793c40377c20d915216f70 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 24 May 2022 12:23:38 +0300 Subject: libcamera: yaml_parser: Extend YamlObject::size() to dictionaries Dictionaries have a size too, extend the size() function to support them. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- include/libcamera/internal/yaml_parser.h | 3 ++- src/libcamera/yaml_parser.cpp | 42 +++++++++++++++++--------------- test/yaml-parser.cpp | 5 ++++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index e002fcf5..b4f852b1 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -39,6 +39,8 @@ public: return type_ == Type::Dictionary; } + std::size_t size() const; + #ifndef __DOXYGEN__ template YamlObject::get( * const T &defaultValue, bool *ok) const @@ -235,25 +258,6 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const #endif /* __DOXYGEN__ */ -/** - * \fn YamlObject::size() - * \brief Retrieve the number of elements in a list YamlObject - * - * This function retrieves the size of the YamlObject, defined as the number of - * child elements it contains. Only YamlObject instances of List type have a - * size, calling this function on other types of instances is invalid and - * results in undefined behaviour. - * - * \return The size of the YamlObject - */ -std::size_t YamlObject::size() const -{ - if (type_ != Type::List) - return 0; - - return list_.size(); -} - /** * \fn YamlObject::operator[](std::size_t index) const * \brief Retrieve the element from list YamlObject by index diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 5315d99f..c5b4ddbb 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -421,6 +421,11 @@ protected: return TestFail; } + if (dictObj.size() != 3) { + cerr << "Dictionary object parse with wrong size" << std::endl; + return TestFail; + } + auto memeberNames = dictObj.memberNames(); sort(memeberNames.begin(), memeberNames.end()); -- cgit v1.2.1