sys: Return std::nullopt instead of {} for empty optional values

This commit is contained in:
WerWolv
2022-01-30 12:43:43 +01:00
parent 4bc074fa84
commit dd572ba024
11 changed files with 45 additions and 46 deletions

View File

@@ -305,7 +305,7 @@ namespace hex::plugin::builtin {
openFiles.erase(file);
return {};
return std::nullopt;
});
/* read(file, size) */
@@ -329,7 +329,7 @@ namespace hex::plugin::builtin {
openFiles[file].write(data);
return {};
return std::nullopt;
});
/* seek(file, offset) */
@@ -342,7 +342,7 @@ namespace hex::plugin::builtin {
openFiles[file].seek(offset);
return {};
return std::nullopt;
});
/* size(file) */
@@ -365,7 +365,7 @@ namespace hex::plugin::builtin {
openFiles[file].setSize(size);
return {};
return std::nullopt;
});
/* flush(file) */
@@ -377,7 +377,7 @@ namespace hex::plugin::builtin {
openFiles[file].flush();
return {};
return std::nullopt;
});
/* remove(file) */
@@ -389,7 +389,7 @@ namespace hex::plugin::builtin {
openFiles[file].remove();
return {};
return std::nullopt;
});
}
}

View File

@@ -96,7 +96,7 @@ namespace hex::plugin::builtin::prv {
auto ack = socket.readString(1);
if (ack.empty() || ack[0] != '+')
return {};
return false;
auto receivedPacket = socket.readString(6);

View File

@@ -150,7 +150,7 @@ namespace hex::plugin::builtin {
mathEvaluator.registerStandardVariables();
mathInput.clear();
return {};
return std::nullopt;
},
0,
0);
@@ -161,7 +161,7 @@ namespace hex::plugin::builtin {
auto provider = ImHexApi::Provider::get();
if (!ImHexApi::Provider::isValid() || !provider->isReadable() || args[0] >= provider->getActualSize())
return {};
return std::nullopt;
provider->read(args[0], &value, sizeof(u8));
@@ -174,15 +174,15 @@ namespace hex::plugin::builtin {
"write", [](auto args) -> std::optional<long double> {
auto provider = ImHexApi::Provider::get();
if (!ImHexApi::Provider::isValid() || !provider->isWritable() || args[0] >= provider->getActualSize())
return {};
return std::nullopt;
if (args[1] > 0xFF)
return {};
return std::nullopt;
u8 value = args[1];
provider->write(args[0], &value, sizeof(u8));
return {};
return std::nullopt;
},
2,
2);

View File

@@ -313,7 +313,7 @@ namespace hex {
}
if (evaluationStack.empty())
return {};
return std::nullopt;
else if (evaluationStack.size() > 1)
throw std::invalid_argument("Undigested input left!");
else