mirror of
https://github.com/Xahau/xahaud.git
synced 2026-07-25 16:10:15 +00:00
Prefer std::optional over boost:optional:
Some of the boost::optionals must remain for now. Both boost::beast and SOCI have interfaces that require boost::optional.
This commit is contained in:
committed by
Nik Bougalis
parent
85307b29d0
commit
3b33318dc8
@@ -184,7 +184,7 @@ non_object_in_array(std::string const& item, Json::UInt index)
|
||||
|
||||
// This function is used by parseObject to parse any JSON type that doesn't
|
||||
// recurse. Everything represented here is a leaf-type.
|
||||
static boost::optional<detail::STVar>
|
||||
static std::optional<detail::STVar>
|
||||
parseLeaf(
|
||||
std::string const& json_name,
|
||||
std::string const& fieldName,
|
||||
@@ -192,7 +192,7 @@ parseLeaf(
|
||||
Json::Value const& value,
|
||||
Json::Value& error)
|
||||
{
|
||||
boost::optional<detail::STVar> ret;
|
||||
std::optional<detail::STVar> ret;
|
||||
|
||||
auto const& field = SField::getField(fieldName);
|
||||
|
||||
@@ -756,7 +756,7 @@ parseLeaf(
|
||||
static const int maxDepth = 64;
|
||||
|
||||
// Forward declaration since parseObject() and parseArray() call each other.
|
||||
static boost::optional<detail::STVar>
|
||||
static std::optional<detail::STVar>
|
||||
parseArray(
|
||||
std::string const& json_name,
|
||||
Json::Value const& json,
|
||||
@@ -764,7 +764,7 @@ parseArray(
|
||||
int depth,
|
||||
Json::Value& error);
|
||||
|
||||
static boost::optional<STObject>
|
||||
static std::optional<STObject>
|
||||
parseObject(
|
||||
std::string const& json_name,
|
||||
Json::Value const& json,
|
||||
@@ -775,13 +775,13 @@ parseObject(
|
||||
if (!json.isObjectOrNull())
|
||||
{
|
||||
error = not_an_object(json_name);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (depth > maxDepth)
|
||||
{
|
||||
error = too_deep(json_name);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -797,7 +797,7 @@ parseObject(
|
||||
if (field == sfInvalid)
|
||||
{
|
||||
error = unknown_field(json_name, fieldName);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
switch (field.fieldType)
|
||||
@@ -810,7 +810,7 @@ parseObject(
|
||||
if (!value.isObject())
|
||||
{
|
||||
error = not_an_object(json_name, fieldName);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -822,13 +822,13 @@ parseObject(
|
||||
depth + 1,
|
||||
error);
|
||||
if (!ret)
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
data.emplace_back(std::move(*ret));
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
error = invalid_data(json_name, fieldName);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -843,14 +843,14 @@ parseObject(
|
||||
field,
|
||||
depth + 1,
|
||||
error);
|
||||
if (array == boost::none)
|
||||
return boost::none;
|
||||
if (!array.has_value())
|
||||
return std::nullopt;
|
||||
data.emplace_back(std::move(*array));
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
error = invalid_data(json_name, fieldName);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -861,7 +861,7 @@ parseObject(
|
||||
parseLeaf(json_name, fieldName, &inName, value, error);
|
||||
|
||||
if (!leaf)
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
|
||||
data.emplace_back(std::move(*leaf));
|
||||
}
|
||||
@@ -883,10 +883,10 @@ parseObject(
|
||||
{
|
||||
error = invalid_data(json_name);
|
||||
}
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static boost::optional<detail::STVar>
|
||||
static std::optional<detail::STVar>
|
||||
parseArray(
|
||||
std::string const& json_name,
|
||||
Json::Value const& json,
|
||||
@@ -897,13 +897,13 @@ parseArray(
|
||||
if (!json.isArrayOrNull())
|
||||
{
|
||||
error = not_an_array(json_name);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (depth > maxDepth)
|
||||
{
|
||||
error = too_deep(json_name);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -919,7 +919,7 @@ parseArray(
|
||||
{
|
||||
// null values are !singleKey
|
||||
error = singleton_expected(json_name, i);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// TODO: There doesn't seem to be a nice way to get just the
|
||||
@@ -932,7 +932,7 @@ parseArray(
|
||||
if (nameField == sfInvalid)
|
||||
{
|
||||
error = unknown_field(json_name, objectName);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Json::Value const objectFields(json[i][objectName]);
|
||||
@@ -948,13 +948,13 @@ parseArray(
|
||||
std::string errMsg = error["error_message"].asString();
|
||||
error["error_message"] =
|
||||
"Error at '" + ss.str() + "'. " + errMsg;
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (ret->getFName().fieldType != STI_OBJECT)
|
||||
{
|
||||
error = non_object_in_array(ss.str(), i);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
tail.push_back(std::move(*ret));
|
||||
@@ -965,7 +965,7 @@ parseArray(
|
||||
catch (std::exception const&)
|
||||
{
|
||||
error = invalid_data(json_name);
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -990,12 +990,12 @@ STParsedJSONArray::STParsedJSONArray(
|
||||
using namespace STParsedJSONDetail;
|
||||
auto arr = parseArray(name, json, sfGeneric, 0, error);
|
||||
if (!arr)
|
||||
array = boost::none;
|
||||
array.reset();
|
||||
else
|
||||
{
|
||||
auto p = dynamic_cast<STArray*>(&arr->get());
|
||||
if (p == nullptr)
|
||||
array = boost::none;
|
||||
array.reset();
|
||||
else
|
||||
array = std::move(*p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user