diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2022-05-24 12:23:38 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2022-06-16 02:43:47 +0300 |
commit | 27fb47f70b55000fbd793c40377c20d915216f70 (patch) | |
tree | 902c9f46c8f02cac96707c12d1337d3ffec1d2c2 /src | |
parent | 27483e971fb43c0874b8399e7431dd805efa3994 (diff) |
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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/yaml_parser.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 4b5ea427..5b872dbb 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -75,6 +75,29 @@ YamlObject::~YamlObject() = default; */ /** + * \fn YamlObject::size() + * \brief Retrieve the number of elements in a dictionary or list YamlObject + * + * This function retrieves the size of the YamlObject, defined as the number of + * child elements it contains. Only YamlObject instances of Dictionary or List + * types 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 +{ + switch (type_) { + case Type::Dictionary: + return dictionary_.size(); + case Type::List: + return list_.size(); + default: + return 0; + } +} + +/** * \fn template<typename T> YamlObject::get<T>( * const T &defaultValue, bool *ok) const * \brief Parse the YamlObject as a \a T value @@ -236,25 +259,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 * |