Merge branch 'master' into jgrpp

# Conflicts:
#	src/core/strong_typedef_type.hpp
#	src/gfx.cpp
#	src/group_cmd.cpp
#	src/industry_cmd.cpp
#	src/map_func.h
#	src/newgrf_debug_gui.cpp
#	src/order_cmd.cpp
#	src/pathfinder/follow_track.hpp
#	src/rail_cmd.cpp
#	src/road_cmd.cpp
#	src/road_gui.cpp
#	src/saveload/saveload.cpp
#	src/screenshot.cpp
#	src/smallmap_gui.cpp
#	src/station_cmd.cpp
#	src/strings.cpp
#	src/tile_type.h
#	src/timetable_gui.cpp
#	src/town_cmd.cpp
#	src/train_cmd.cpp
#	src/viewport.cpp
This commit is contained in:
Jonathan G Rennison
2023-02-10 17:18:39 +00:00
55 changed files with 345 additions and 294 deletions

View File

@@ -144,4 +144,46 @@ private:
const int line;
};
/**
* Class to backup a specific variable and restore it upon destruction of this object to prevent
* stack values going out of scope before resetting the global to its original value. Contrary to
* #Backup this restores the variable automatically and there is no manual option to restore.
*/
template <typename T>
struct AutoRestoreBackup {
/*
* There is explicitly no only original constructor version, as that would make it possible
* for the new value to go out of scope before this object goes out of scope, thus defeating
* the whole goal and reason for existing of this object.
*/
/**
* Backup variable and switch to new value.
* @param original Variable to backup.
* @param new_value New value for variable.
*/
AutoRestoreBackup(T &original, T new_value) : original(original), original_value(original)
{
original = new_value;
}
/**
* Restore the variable upon object destruction.
*/
~AutoRestoreBackup()
{
this->original = this->original_value;
}
private:
T &original;
T original_value;
/* Prevent copy, assignment and allocation on stack. */
AutoRestoreBackup(const AutoRestoreBackup&) = delete;
AutoRestoreBackup& operator=(AutoRestoreBackup&) = delete;
static void *operator new(std::size_t) = delete;
static void *operator new[](std::size_t) = delete;
};
#endif /* BACKUP_TYPE_HPP */

View File

@@ -31,7 +31,7 @@
* @return The selected bits, aligned to a LSB.
*/
template <typename T>
static inline uint GB(const T x, const uint8 s, const uint8 n)
debug_inline static uint GB(const T x, const uint8 s, const uint8 n)
{
return (x >> s) & (((T)1U << n) - 1);
}
@@ -103,7 +103,7 @@ static inline T AB(T &x, const uint8 s, const uint8 n, const U i)
* @return True if the bit is set, false else.
*/
template <typename T>
static inline bool HasBit(const T x, const uint8 y)
debug_inline static bool HasBit(const T x, const uint8 y)
{
return (x & ((T)1U << y)) != 0;
}