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>
This commit is contained in:
parent
27483e971f
commit
27fb47f70b
3 changed files with 30 additions and 20 deletions
|
@ -39,6 +39,8 @@ public:
|
||||||
return type_ == Type::Dictionary;
|
return type_ == Type::Dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t size() const;
|
||||||
|
|
||||||
#ifndef __DOXYGEN__
|
#ifndef __DOXYGEN__
|
||||||
template<typename T,
|
template<typename T,
|
||||||
typename std::enable_if_t<
|
typename std::enable_if_t<
|
||||||
|
@ -53,7 +55,6 @@ public:
|
||||||
#endif
|
#endif
|
||||||
T get(const T &defaultValue, bool *ok = nullptr) const;
|
T get(const T &defaultValue, bool *ok = nullptr) const;
|
||||||
|
|
||||||
std::size_t size() const;
|
|
||||||
const YamlObject &operator[](std::size_t index) const;
|
const YamlObject &operator[](std::size_t index) const;
|
||||||
|
|
||||||
bool contains(const std::string &key) const;
|
bool contains(const std::string &key) const;
|
||||||
|
|
|
@ -74,6 +74,29 @@ YamlObject::~YamlObject() = default;
|
||||||
* \return True if the YamlObject is a dictionary, false otherwise
|
* \return True if the YamlObject is a dictionary, false otherwise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \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>(
|
* \fn template<typename T> YamlObject::get<T>(
|
||||||
* const T &defaultValue, bool *ok) const
|
* const T &defaultValue, bool *ok) const
|
||||||
|
@ -235,25 +258,6 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const
|
||||||
|
|
||||||
#endif /* __DOXYGEN__ */
|
#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
|
* \fn YamlObject::operator[](std::size_t index) const
|
||||||
* \brief Retrieve the element from list YamlObject by index
|
* \brief Retrieve the element from list YamlObject by index
|
||||||
|
|
|
@ -421,6 +421,11 @@ protected:
|
||||||
return TestFail;
|
return TestFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dictObj.size() != 3) {
|
||||||
|
cerr << "Dictionary object parse with wrong size" << std::endl;
|
||||||
|
return TestFail;
|
||||||
|
}
|
||||||
|
|
||||||
auto memeberNames = dictObj.memberNames();
|
auto memeberNames = dictObj.memberNames();
|
||||||
sort(memeberNames.begin(), memeberNames.end());
|
sort(memeberNames.begin(), memeberNames.end());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue