mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
vcmi: use std::optional
This commit is contained in:
@@ -31,12 +31,12 @@ void JsonDeserializer::serializeInternal(const std::string & fieldName, boost::l
|
||||
value = data.Bool();
|
||||
}
|
||||
|
||||
void JsonDeserializer::serializeInternal(const std::string & fieldName, si32 & value, const boost::optional<si32> & defaultValue, const TDecoder & decoder, const TEncoder & encoder)
|
||||
void JsonDeserializer::serializeInternal(const std::string & fieldName, si32 & value, const std::optional<si32> & defaultValue, const TDecoder & decoder, const TEncoder & encoder)
|
||||
{
|
||||
std::string identifier;
|
||||
serializeString(fieldName, identifier);
|
||||
|
||||
value = defaultValue ? defaultValue.get() : 0;
|
||||
value = defaultValue.value_or(0);
|
||||
|
||||
if(!identifier.empty())
|
||||
{
|
||||
@@ -74,31 +74,31 @@ void JsonDeserializer::serializeInternal(const std::string & fieldName, std::vec
|
||||
}
|
||||
}
|
||||
|
||||
void JsonDeserializer::serializeInternal(const std::string & fieldName, double & value, const boost::optional<double> & defaultValue)
|
||||
void JsonDeserializer::serializeInternal(const std::string & fieldName, double & value, const std::optional<double> & defaultValue)
|
||||
{
|
||||
const JsonNode & data = currentObject->operator[](fieldName);
|
||||
|
||||
if(!data.isNumber())
|
||||
value = defaultValue ? defaultValue.get() : 0;//todo: report error on not null?
|
||||
value = defaultValue.value_or(0);//todo: report error on not null?
|
||||
else
|
||||
value = data.Float();
|
||||
}
|
||||
|
||||
void JsonDeserializer::serializeInternal(const std::string & fieldName, si64 & value, const boost::optional<si64> & defaultValue)
|
||||
void JsonDeserializer::serializeInternal(const std::string & fieldName, si64 & value, const std::optional<si64> & defaultValue)
|
||||
{
|
||||
const JsonNode & data = currentObject->operator[](fieldName);
|
||||
|
||||
if(!data.isNumber())
|
||||
value = defaultValue ? defaultValue.get() : 0;//todo: report error on not null?
|
||||
value = defaultValue.value_or(0);//todo: report error on not null?
|
||||
else
|
||||
value = data.Integer();
|
||||
}
|
||||
|
||||
void JsonDeserializer::serializeInternal(const std::string & fieldName, si32 & value, const boost::optional<si32> & defaultValue, const std::vector<std::string> & enumMap)
|
||||
void JsonDeserializer::serializeInternal(const std::string & fieldName, si32 & value, const std::optional<si32> & defaultValue, const std::vector<std::string> & enumMap)
|
||||
{
|
||||
const std::string & valueName = currentObject->operator[](fieldName).String();
|
||||
|
||||
const si32 actualOptional = defaultValue ? defaultValue.get() : 0;
|
||||
const si32 actualOptional = defaultValue.value_or(0);
|
||||
|
||||
si32 rawValue = vstd::find_pos(enumMap, valueName);
|
||||
if(rawValue < 0)
|
||||
@@ -238,13 +238,13 @@ void JsonDeserializer::serializeString(const std::string & fieldName, std::strin
|
||||
value = currentObject->operator[](fieldName).String();
|
||||
}
|
||||
|
||||
void JsonDeserializer::serializeRaw(const std::string & fieldName, JsonNode & value, const boost::optional<const JsonNode &> defaultValue)
|
||||
void JsonDeserializer::serializeRaw(const std::string & fieldName, JsonNode & value, const std::optional<std::reference_wrapper<const JsonNode>> defaultValue)
|
||||
{
|
||||
const JsonNode & data = currentObject->operator[](fieldName);
|
||||
if(data.getType() == JsonNode::JsonType::DATA_NULL)
|
||||
{
|
||||
if(defaultValue)
|
||||
value = defaultValue.get();
|
||||
value = defaultValue.value();
|
||||
else
|
||||
value.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user