Repalce raw for-loops by corresponding algorithms

C++20
elsid 3 years ago
parent 082810f924
commit fbd95516f4
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -6,6 +6,7 @@
#include <array> #include <array>
#include <map> #include <map>
#include <sstream> #include <sstream>
#include <algorithm>
namespace Nif namespace Nif
{ {
@ -181,18 +182,11 @@ void NIFFile::parse(Files::IStreamPtr stream)
"NetImmerse File Format", "NetImmerse File Format",
"Gamebryo File Format" "Gamebryo File Format"
}; };
bool supported = false; const bool supportedHeader = std::any_of(verStrings.begin(), verStrings.end(),
for (const std::string& verString : verStrings) [&] (const std::string& verString) { return head.compare(0, verString.size(), verString) == 0; });
{ if (!supportedHeader)
supported = (head.compare(0, verString.size(), verString) == 0);
if (supported)
break;
}
if (!supported)
fail("Invalid NIF header: " + head); fail("Invalid NIF header: " + head);
supported = false;
// Get BCD version // Get BCD version
ver = nif.getUInt(); ver = nif.getUInt();
// 4.0.0.0 is an older, practically identical version of the format. // 4.0.0.0 is an older, practically identical version of the format.
@ -202,13 +196,8 @@ void NIFFile::parse(Files::IStreamPtr stream)
NIFStream::generateVersion(4,0,0,0), NIFStream::generateVersion(4,0,0,0),
VER_MW VER_MW
}; };
for (uint32_t supportedVer : supportedVers) const bool supportedVersion = std::find(supportedVers.begin(), supportedVers.end(), ver) != supportedVers.end();
{ if (!supportedVersion)
supported = (ver == supportedVer);
if (supported)
break;
}
if (!supported)
{ {
if (sLoadUnsupportedFiles) if (sLoadUnsupportedFiles)
warn("Unsupported NIF version: " + printVersion(ver) + ". Proceed with caution!"); warn("Unsupported NIF version: " + printVersion(ver) + ". Proceed with caution!");
@ -311,7 +300,7 @@ void NIFFile::parse(Files::IStreamPtr stream)
r = entry->second(); r = entry->second();
if (!supported) if (!supportedVersion)
Log(Debug::Verbose) << "NIF Debug: Reading record of type " << rec << ", index " << i << " (" << filename << ")"; Log(Debug::Verbose) << "NIF Debug: Reading record of type " << rec << ", index " << i << " (" << filename << ")";
assert(r != nullptr); assert(r != nullptr);

Loading…
Cancel
Save