0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

jsonhelper: provide rvalue reference overloads for all methods that return a reference to a passed object

Signed-off-by: James Yonan <james@openvpn.net>
This commit is contained in:
James Yonan 2023-04-28 12:41:27 -06:00
parent 993875b6f8
commit f3a861d54c

View File

@ -117,6 +117,28 @@ inline const Json::Value &cast(const Json::ValueType target_type,
{
return cast(target_type, value, name, optional, nullptr);
}
template <typename NAME, typename TITLE>
inline Json::Value cast(const Json::ValueType target_type,
Json::Value &&value,
const NAME &name,
const bool optional,
const TITLE &title)
{
Json::Value ret = std::move(value);
cast(target_type, ret, name, optional, title);
return ret;
}
template <typename NAME>
inline Json::Value cast(const Json::ValueType target_type,
Json::Value &&value,
const NAME &name,
const bool optional)
{
return cast(target_type, std::move(value), name, optional, nullptr);
}
#endif
template <typename T, typename NAME>
@ -215,6 +237,15 @@ inline const std::string &get_string_ref(const Json::Value &root, const NAME &na
return get_string_ref(root, name, nullptr);
}
// for safety, define an rvalue ref overload that falls back to get_string()
template <typename NAME, typename TITLE>
inline std::string get_string_ref(Json::Value &&root,
const NAME &name,
const TITLE &title)
{
return get_string(root, name, title);
}
template <typename NAME, typename TITLE>
inline const std::string *get_string_ptr(const Json::Value &root,
const NAME &name,
@ -621,6 +652,24 @@ inline const Json::Value &get_dict(const Json::Value &root,
return get_dict(root, name, optional, nullptr);
}
template <typename NAME, typename TITLE>
inline Json::Value get_dict(Json::Value &&root,
const NAME &name,
const bool optional,
const TITLE &title)
{
Json::Value r = std::move(root);
return get_dict(r, name, optional, title);
}
template <typename NAME>
inline Json::Value get_dict(Json::Value &&root,
const NAME &name,
const bool optional)
{
return get_dict(std::move(root), name, optional, nullptr);
}
template <typename TITLE>
inline const Json::Value &cast_dict(const Json::Value &value,
const bool optional,
@ -643,6 +692,22 @@ inline const Json::Value &cast_dict(const Json::Value &value,
return cast_dict(value, optional, nullptr);
}
template <typename TITLE>
inline Json::Value cast_dict(Json::Value &&value,
const bool optional,
const TITLE &title)
{
Json::Value ret = std::move(value);
cast_dict(ret, optional, title);
return ret;
}
inline Json::Value cast_dict(Json::Value &&value,
const bool optional)
{
return cast_dict(std::move(value), optional, nullptr);
}
template <typename NAME, typename TITLE>
inline const Json::Value &get_array(const Json::Value &root,
const NAME &name,
@ -669,6 +734,24 @@ inline const Json::Value &get_array(const Json::Value &root,
return get_array(root, name, optional, nullptr);
}
template <typename NAME, typename TITLE>
inline Json::Value get_array(Json::Value &&root,
const NAME &name,
const bool optional,
const TITLE &title)
{
Json::Value r = std::move(root);
return get_array(r, name, optional, title);
}
template <typename NAME>
inline Json::Value get_array(Json::Value &&root,
const NAME &name,
const bool optional)
{
return get_array(std::move(root), name, optional, nullptr);
}
template <typename TITLE>
inline const Json::Value &cast_array(const Json::Value &value,
const bool optional,
@ -691,6 +774,22 @@ inline const Json::Value &cast_array(const Json::Value &value,
return cast_array(value, optional, nullptr);
}
template <typename TITLE>
inline Json::Value cast_array(Json::Value &&value,
const bool optional,
const TITLE &title)
{
Json::Value ret = std::move(value);
cast_array(ret, optional, title);
return ret;
}
inline Json::Value cast_array(Json::Value &&value,
const bool optional)
{
return cast_array(std::move(value), optional, nullptr);
}
template <typename NAME, typename TITLE>
inline void to_string(const Json::Value &root,
std::string &dest,