16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 03:29:19 +02:00

reformat: use auto on certain types

This commit is contained in:
jerrrrycho
2026-07-04 05:22:52 +02:00
parent f61068ff89
commit 20e7a99516
118 changed files with 2118 additions and 2063 deletions

View File

@@ -987,7 +987,7 @@ bool global_settings::ConfigParseHardware(cParser& Parser, const std::string& to
if (token == "uartfeature")
{
Parser.getTokens(1);
std::string firstToken = Parser.peek();
const std::string firstToken = Parser.peek();
if (firstToken.find('|') != std::string::npos || firstToken == "none" || uartfeatures_map.contains(firstToken))
{

View File

@@ -60,7 +60,7 @@ std::string filename_date() {
std::string filename_scenery() {
auto extension = Global.SceneryFile.rfind( '.' );
const auto extension = Global.SceneryFile.rfind( '.' );
if( extension != std::string::npos ) {
return Global.SceneryFile.substr( 0, extension );
}
@@ -99,7 +99,7 @@ void LogService()
{
logMutex.lock();
std::string msg = InfoStack.front().first;
bool isError = InfoStack.front().second;
const bool isError = InfoStack.front().second;
InfoStack.pop_front();
logMutex.unlock();

View File

@@ -44,7 +44,7 @@ public:
}
void purge (std::string const &Name)
{
auto lookup = m_itemmap.find( Name );
const auto lookup = m_itemmap.find( Name );
if (lookup == m_itemmap.end())
return;
delete m_items[lookup->second];
@@ -53,7 +53,7 @@ public:
}
void detach (std::string const &Name)
{
auto lookup = m_itemmap.find( Name );
const auto lookup = m_itemmap.find( Name );
if (lookup == m_itemmap.end())
return;
@@ -63,7 +63,7 @@ public:
m_itemmap.erase(lookup);
}
uint32_t find_id( std::string const &Name) const {
auto lookup = m_itemmap.find( Name );
const auto lookup = m_itemmap.find( Name );
return lookup != m_itemmap.end() ? lookup->second : -1;
}
void purge (Type_ *Item)
@@ -79,7 +79,7 @@ public:
// locates item with specified name. returns pointer to the item, or nullptr
Type_ *
find( std::string const &Name ) const {
auto lookup = m_itemmap.find( Name );
const auto lookup = m_itemmap.find( Name );
return lookup != m_itemmap.end() ? m_items[lookup->second] : nullptr; }
protected:

View File

@@ -94,7 +94,7 @@ void UpdateTimers(bool pause)
#if __unix__
double fTime = (double)(count / 1000000000);
#elif _WIN32_WINNT >= _WIN32_WINNT_VISTA
double fTime = ::GetTickCount64() * 0.001f; // Get current time in seconds
const double fTime = ::GetTickCount64() * 0.001f; // Get current time in seconds
#elif _WIN32
double fTime = ::GetTickCount() * 0.001f; // Get current time in seconds
#endif

View File

@@ -27,7 +27,7 @@ namespace
inline std::array<bool, 256> makeBreakTable(const char *brk)
{
std::array<bool, 256> arr{};
for (unsigned char c : std::string_view(brk ? brk : ""))
for (const unsigned char c : std::string_view(brk ? brk : ""))
{
arr[c] = true;
}
@@ -535,7 +535,7 @@ int cParser::getProgress() const
int cParser::getFullProgress() const
{
int progress = getProgress();
const int progress = getProgress();
if (mIncludeParser)
return progress + (100 - progress) * mIncludeParser->getProgress() / 100;
else

View File

@@ -36,12 +36,12 @@ void locale::init()
const std::string& locale::lookup_s(const std::string &msg, bool constant)
{
if (constant) {
auto it = pointer_cache.find(&msg);
const auto it = pointer_cache.find(&msg);
if (it != pointer_cache.end())
return *(const std::string *)it->second;
}
auto it = lang_mapping.find(msg);
const auto it = lang_mapping.find(msg);
if (it != lang_mapping.end()) {
if (constant)
pointer_cache.emplace(&msg, &it->second);
@@ -56,12 +56,12 @@ const std::string& locale::lookup_s(const std::string &msg, bool constant)
const char* locale::lookup_c(const char *msg, bool constant)
{
if (constant) {
auto it = pointer_cache.find(msg);
const auto it = pointer_cache.find(msg);
if (it != pointer_cache.end())
return (const char*)it->second;
}
auto it = lang_mapping.find(std::string(msg));
const auto it = lang_mapping.find(std::string(msg));
if (it != lang_mapping.end()) {
if (constant)
pointer_cache.emplace(msg, it->second.c_str());
@@ -370,7 +370,7 @@ const std::string& locale::coupling_name(int c)
static std::string unknown(STRN("unknown"));
auto it = coupling_names.find(static_cast<coupling>(c));
const auto it = coupling_names.find(static_cast<coupling>(c));
if (it != coupling_names.end())
return lookup_s(it->second);
else

View File

@@ -28,7 +28,7 @@ const char* uart_baudrates_list[] = {
"2000000"
};
const size_t uart_baudrates_list_num = sizeof(uart_baudrates_list) / sizeof(uart_baudrates_list[0]);
const size_t uart_baudrates_list_num = std::size(uart_baudrates_list);
void uart_status::reset_stats() {
packets_sent = 0;

View File

@@ -49,7 +49,7 @@ std::string Now()
std::strftime(buf, sizeof(buf), "%c", &tm);
return std::string(buf);
#else
auto now = std::chrono::system_clock::now();
const auto now = std::chrono::system_clock::now();
auto local = std::chrono::current_zone()->to_local(now);
return std::format("{:%c}", local);
#endif
@@ -242,7 +242,7 @@ std::string to_minutes_str(float const Minutes, bool const Leadingzero, int cons
float minutesintegral;
auto const minutesfractional{std::modf(Minutes, &minutesintegral)};
auto const width{Width - 1};
auto minutes = std::string(width - 1, ' ') + (Leadingzero ? std::to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0));
const auto minutes = std::string(width - 1, ' ') + (Leadingzero ? std::to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0));
return minutes.substr(minutes.size() - width, width) + fractionlabels[static_cast<int>(std::floor(minutesfractional * 10 + 0.1))];
}
@@ -338,7 +338,7 @@ std::string Bezogonkow(std::string Input, bool const Underscorestospaces)
template <> bool extract_value(bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default)
{
auto value = extract_value(Key, Input);
const auto value = extract_value(Key, Input);
if (false == value.empty())
{
// set the specified variable to retrieved value
@@ -381,7 +381,7 @@ std::pair<std::string, std::string> FileExists(std::vector<std::string> const &N
// returns time of last modification for specified file
std::time_t last_modified(std::string const &Filename)
{
std::string fn = Filename;
const std::string fn = Filename;
struct stat filestat;
if (::stat(fn.c_str(), &filestat) == 0)
return filestat.st_mtime;
@@ -411,7 +411,7 @@ bool erase_extension(std::string &Filename)
void erase_leading_slashes(std::string &Filename)
{
auto pos = Filename.find_first_not_of('/');
const auto pos = Filename.find_first_not_of('/');
Filename.erase(0, pos);
}
@@ -425,7 +425,7 @@ void replace_slashes(std::string &Filename)
std::string substr_path(std::string const &Filename)
{
// String::substr returns new string so substr_path has to return std::string
if (auto pos = Filename.rfind('/'); pos != std::string::npos)
if (const auto pos = Filename.rfind('/'); pos != std::string::npos)
return Filename.substr(0, pos + 1);
return {};
}

View File

@@ -87,7 +87,7 @@ inline double LocalRandom(double b)
inline double BorlandTime()
{
auto timesinceepoch = std::time(nullptr);
const auto timesinceepoch = std::time(nullptr);
return timesinceepoch / (24.0 * 60 * 60);
/*
// std alternative
@@ -177,7 +177,7 @@ inline std::string extract_value(std::string const &Key, std::string const &Inpu
template <typename Type_> bool extract_value(Type_ &Variable, std::string const &Key, std::string const &Input, std::string const &Default)
{
auto value = extract_value(Key, Input);
const auto value = extract_value(Key, Input);
if (false == value.empty())
{
// set the specified variable to retrieved value

View File

@@ -15,8 +15,8 @@ public:
static UID random() {
static thread_local std::mt19937_64 gen(std::random_device{}());
UID u;
uint64_t a = gen();
uint64_t b = gen();
const uint64_t a = gen();
const uint64_t b = gen();
for (int i = 0; i < 8; ++i) u.bytes[i] = uint8_t(a >> (i * 8) & 0xFF);
for (int i = 0; i < 8; ++i) u.bytes[8 + i] = uint8_t(b >> (i * 8) & 0xFF);