mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-16 17:05:08 +03:00
ipa: libipa: vector: Specialize YamlObject getter
Implement a specialization of the YamlObject::Getter structure to support deserializing ipa::Vector objects from YAML data. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
This commit is contained in:
parent
922686067a
commit
64ed07d4d0
2 changed files with 42 additions and 0 deletions
|
@ -148,6 +148,23 @@ namespace ipa {
|
||||||
* \return True if the two vectors are not equal, false otherwise
|
* \return True if the two vectors are not equal, false otherwise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __DOXYGEN__
|
||||||
|
bool vectorValidateYaml(const YamlObject &obj, unsigned int size)
|
||||||
|
{
|
||||||
|
if (!obj.isList())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (obj.size() != size) {
|
||||||
|
LOG(Vector, Error)
|
||||||
|
<< "Wrong number of values in YAML vector: expected "
|
||||||
|
<< size << ", got " << obj.size();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif /* __DOXYGEN__ */
|
||||||
|
|
||||||
} /* namespace ipa */
|
} /* namespace ipa */
|
||||||
|
|
||||||
} /* namespace libcamera */
|
} /* namespace libcamera */
|
||||||
|
|
|
@ -180,6 +180,10 @@ bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __DOXYGEN__
|
||||||
|
bool vectorValidateYaml(const YamlObject &obj, unsigned int size);
|
||||||
|
#endif /* __DOXYGEN__ */
|
||||||
|
|
||||||
} /* namespace ipa */
|
} /* namespace ipa */
|
||||||
|
|
||||||
#ifndef __DOXYGEN__
|
#ifndef __DOXYGEN__
|
||||||
|
@ -195,6 +199,27 @@ std::ostream &operator<<(std::ostream &out, const ipa::Vector<T, Rows> &v)
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, unsigned int Rows>
|
||||||
|
struct YamlObject::Getter<ipa::Vector<T, Rows>> {
|
||||||
|
std::optional<ipa::Vector<T, Rows>> get(const YamlObject &obj) const
|
||||||
|
{
|
||||||
|
if (!ipa::vectorValidateYaml(obj, Rows))
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
ipa::Vector<T, Rows> vector;
|
||||||
|
|
||||||
|
unsigned int i = 0;
|
||||||
|
for (const YamlObject &entry : obj.asList()) {
|
||||||
|
const auto value = entry.get<T>();
|
||||||
|
if (!value)
|
||||||
|
return std::nullopt;
|
||||||
|
vector[i++] = *value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
};
|
||||||
#endif /* __DOXYGEN__ */
|
#endif /* __DOXYGEN__ */
|
||||||
|
|
||||||
} /* namespace libcamera */
|
} /* namespace libcamera */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue