mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-28 08:27:22 +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) {
|
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.
|
// 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)) {
|
for (auto& t : std::filesystem::directory_iterator(folder)) {
|
||||||
auto filename = t.path().filename().string();
|
auto filename = t.path().filename().string();
|
||||||
auto index = std::stoi(GeneralUtils::SplitString(filename, '_').at(0));
|
auto index = std::stoi(GeneralUtils::SplitString(filename, '_').at(0));
|
||||||
filenames.insert(std::make_pair(index, filename));
|
filenames.insert(std::make_pair(index, filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now sort the map by the oldest migration.
|
// Now sort the map by the oldest migration.
|
||||||
std::vector<std::string> sortedFiles{};
|
std::vector<std::string> sortedFiles{};
|
||||||
auto fileIterator = filenames.begin();
|
auto fileIterator = filenames.begin();
|
||||||
std::map<uint32_t, std::string>::iterator oldest = filenames.begin();
|
std::map<uint32_t, std::string>::iterator oldest = filenames.begin();
|
||||||
while (!filenames.empty()) {
|
while (!filenames.empty()) {
|
||||||
if (fileIterator == filenames.end()) {
|
if (fileIterator == filenames.end()) {
|
||||||
sortedFiles.push_back(oldest->second);
|
sortedFiles.push_back(oldest->second);
|
||||||
filenames.erase(oldest);
|
filenames.erase(oldest);
|
||||||
fileIterator = filenames.begin();
|
fileIterator = filenames.begin();
|
||||||
oldest = filenames.begin();
|
oldest = filenames.begin();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (oldest->first > fileIterator->first) oldest = fileIterator;
|
if (oldest->first > fileIterator->first) oldest = fileIterator;
|
||||||
fileIterator++;
|
fileIterator++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sortedFiles;
|
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
|
#ifdef DARKFLAME_PLATFORM_MACOS
|
||||||
|
|
||||||
// Anonymous namespace containing MacOS floating-point parse function specializations
|
// MacOS floating-point parse helper function specializations
|
||||||
namespace {
|
namespace details {
|
||||||
template <std::floating_point T>
|
template <std::floating_point T>
|
||||||
[[nodiscard]] T Parse(const std::string_view str, size_t* parseNum);
|
[[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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,9 +181,10 @@ namespace GeneralUtils {
|
|||||||
* @returns An std::optional containing the desired value if it is equivalent to the string
|
* @returns An std::optional containing the desired value if it is equivalent to the string
|
||||||
*/
|
*/
|
||||||
template <std::floating_point T>
|
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;
|
size_t parseNum;
|
||||||
const T result = Parse<T>(str, &parseNum);
|
const T result = details::_parse<T>(str, parseNum);
|
||||||
const bool isParsed = str.length() == parseNum;
|
const bool isParsed = str.length() == parseNum;
|
||||||
|
|
||||||
return isParsed ? result : std::optional<T>{};
|
return isParsed ? result : std::optional<T>{};
|
||||||
|
Loading…
Reference in New Issue
Block a user