mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-09 01:38:20 +00:00
chore: Remove anonymous namespace from GeneralUtils.h (#1460)
* remove anonymous namespace from GeneralUtils.h * Put helper functions in nested details namespace to hide from hinting * rename implementation functions to use lower case, leading underscore and move definitions to source file
This commit is contained in:
parent
f38537aece
commit
5ae8fd8e0e
@ -294,28 +294,50 @@ std::u16string GeneralUtils::ReadWString(RakNet::BitStream* inStream) {
|
||||
|
||||
std::vector<std::string> GeneralUtils::GetSqlFileNamesFromFolder(const std::string& folder) {
|
||||
// Because we dont know how large the initial number before the first _ is we need to make it a map like so.
|
||||
std::map<uint32_t, std::string> filenames{};
|
||||
std::map<uint32_t, std::string> filenames{};
|
||||
for (auto& t : std::filesystem::directory_iterator(folder)) {
|
||||
auto filename = t.path().filename().string();
|
||||
auto index = std::stoi(GeneralUtils::SplitString(filename, '_').at(0));
|
||||
filenames.insert(std::make_pair(index, filename));
|
||||
auto filename = t.path().filename().string();
|
||||
auto index = std::stoi(GeneralUtils::SplitString(filename, '_').at(0));
|
||||
filenames.insert(std::make_pair(index, filename));
|
||||
}
|
||||
|
||||
// Now sort the map by the oldest migration.
|
||||
std::vector<std::string> sortedFiles{};
|
||||
auto fileIterator = filenames.begin();
|
||||
std::map<uint32_t, std::string>::iterator oldest = filenames.begin();
|
||||
while (!filenames.empty()) {
|
||||
auto fileIterator = filenames.begin();
|
||||
std::map<uint32_t, std::string>::iterator oldest = filenames.begin();
|
||||
while (!filenames.empty()) {
|
||||
if (fileIterator == filenames.end()) {
|
||||
sortedFiles.push_back(oldest->second);
|
||||
filenames.erase(oldest);
|
||||
fileIterator = filenames.begin();
|
||||
oldest = filenames.begin();
|
||||
continue;
|
||||
sortedFiles.push_back(oldest->second);
|
||||
filenames.erase(oldest);
|
||||
fileIterator = filenames.begin();
|
||||
oldest = filenames.begin();
|
||||
continue;
|
||||
}
|
||||
if (oldest->first > fileIterator->first) oldest = fileIterator;
|
||||
fileIterator++;
|
||||
if (oldest->first > fileIterator->first) oldest = fileIterator;
|
||||
fileIterator++;
|
||||
}
|
||||
|
||||
return sortedFiles;
|
||||
}
|
||||
|
||||
#ifdef DARKFLAME_PLATFORM_MACOS
|
||||
|
||||
// MacOS floating-point parse function specializations
|
||||
namespace GeneralUtils::details {
|
||||
template <>
|
||||
[[nodiscard]] float _parse<float>(const std::string_view str, size_t& parseNum) {
|
||||
return std::stof(std::string{ str }, &parseNum);
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] double _parse<double>(const std::string_view str, size_t& parseNum) {
|
||||
return std::stod(std::string{ str }, &parseNum);
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] long double _parse<long double>(const std::string_view str, size_t& parseNum) {
|
||||
return std::stold(std::string{ str }, &parseNum);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -168,25 +168,10 @@ namespace GeneralUtils {
|
||||
|
||||
#ifdef DARKFLAME_PLATFORM_MACOS
|
||||
|
||||
// Anonymous namespace containing MacOS floating-point parse function specializations
|
||||
namespace {
|
||||
// MacOS floating-point parse helper function specializations
|
||||
namespace details {
|
||||
template <std::floating_point T>
|
||||
[[nodiscard]] T Parse(const std::string_view str, size_t* parseNum);
|
||||
|
||||
template <>
|
||||
[[nodiscard]] float Parse<float>(const std::string_view str, size_t* parseNum) {
|
||||
return std::stof(std::string{ str }, parseNum);
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] double Parse<double>(const std::string_view str, size_t* parseNum) {
|
||||
return std::stod(std::string{ str }, parseNum);
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] long double Parse<long double>(const std::string_view str, size_t* parseNum) {
|
||||
return std::stold(std::string{ str }, parseNum);
|
||||
}
|
||||
[[nodiscard]] T _parse(const std::string_view str, size_t& parseNum);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,9 +181,10 @@ namespace GeneralUtils {
|
||||
* @returns An std::optional containing the desired value if it is equivalent to the string
|
||||
*/
|
||||
template <std::floating_point T>
|
||||
[[nodiscard]] std::optional<T> TryParse(const std::string_view str) noexcept try {
|
||||
[[nodiscard]] std::optional<T> TryParse(const std::string_view str) noexcept
|
||||
try {
|
||||
size_t parseNum;
|
||||
const T result = Parse<T>(str, &parseNum);
|
||||
const T result = details::_parse<T>(str, parseNum);
|
||||
const bool isParsed = str.length() == parseNum;
|
||||
|
||||
return isParsed ? result : std::optional<T>{};
|
||||
|
Loading…
Reference in New Issue
Block a user