Convert remaining C-style casts to C++-style ones

This commit is contained in:
Gymnasiast 2020-04-30 15:51:50 +02:00
parent d8ffec0ed7
commit c83ddefe47
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
8 changed files with 24 additions and 19 deletions

View File

@ -1754,8 +1754,8 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi)
ScreenCoordsXY screenCoords(w->windowPos.x, w->windowPos.y);
// Draw coordinates
gfx_draw_string(dpi, (char*)"X:", COLOUR_WHITE, screenCoords + ScreenCoordsXY(5, 24));
gfx_draw_string(dpi, (char*)"Y:", COLOUR_WHITE, screenCoords + ScreenCoordsXY(74, 24));
gfx_draw_string(dpi, "X:", COLOUR_WHITE, screenCoords + ScreenCoordsXY(5, 24));
gfx_draw_string(dpi, "Y:", COLOUR_WHITE, screenCoords + ScreenCoordsXY(74, 24));
if (windowTileInspectorTileSelected)
{
auto tileCoords = TileCoordsXY{ windowTileInspectorToolMap };
@ -1764,8 +1764,8 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi)
}
else
{
gfx_draw_string(dpi, (char*)"-", COLOUR_WHITE, screenCoords + ScreenCoordsXY(43 - 7, 24));
gfx_draw_string(dpi, (char*)"-", COLOUR_WHITE, screenCoords + ScreenCoordsXY(113, 24));
gfx_draw_string(dpi, "-", COLOUR_WHITE, screenCoords + ScreenCoordsXY(43 - 7, 24));
gfx_draw_string(dpi, "-", COLOUR_WHITE, screenCoords + ScreenCoordsXY(113, 24));
}
if (windowTileInspectorSelectedIndex != -1)

View File

@ -75,7 +75,7 @@ namespace Memory
template<typename T> static void Free(T* ptr)
{
free((void*)ptr);
free(const_cast<void*>(reinterpret_cast<const void*>(ptr)));
}
template<typename T> static void FreeArray(T* ptr, size_t count)

View File

@ -1,6 +1,10 @@
// Adapted from freetype.h in order to avoid C-style casts.
#define FT_LOAD_TARGET_ALT(x) (static_cast<FT_Int32>((x)&15) << 16)
#define FT_IMAGE_TAG(value, _x1, _x2, _x3, _x4) \
value \
= ((static_cast<unsigned long>(_x1) << 24) | (static_cast<unsigned long>(_x2) << 16) \
| (static_cast<unsigned long>(_x3) << 8) | static_cast<unsigned long>(_x4))
/**
* The following code is from SDL2_ttf (2 Jan 2017).

View File

@ -369,7 +369,7 @@ ScriptEngine::ScriptEngine(InteractiveConsole& console, IPlatformEnvironment& en
void ScriptEngine::Initialise()
{
auto ctx = (duk_context*)_context;
auto ctx = static_cast<duk_context*>(_context);
ScCheats::Register(ctx);
ScConfiguration::Register(ctx);
ScConsole::Register(ctx);

View File

@ -29,7 +29,7 @@ public:
uint32_t hash = 27;
for (size_t i = 0; i < bufferLength; i++)
{
hash = (13 * hash) + ((uint8_t*)buffer)[i];
hash = (13 * hash) + (reinterpret_cast<uint8_t*>(buffer))[i];
}
return hash;
}

View File

@ -46,7 +46,7 @@ TEST_F(IniWriterTest, create_one_section)
ASSERT_LE(ms.GetPosition(), 13); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = (const char*)ms.ReadString();
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(ini, "[OpenRCT2]" PLATFORM_NEWLINE);
Memory::Free(ini);
delete iw;
@ -67,7 +67,7 @@ TEST_F(IniWriterTest, create_multiple_sections)
ASSERT_LE(ms.GetPosition(), 55); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = (const char*)ms.ReadString();
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(
ini,
"[OpenRCT1]" PLATFORM_NEWLINE PLATFORM_NEWLINE "[OpenRCT2]" PLATFORM_NEWLINE PLATFORM_NEWLINE
@ -88,7 +88,7 @@ TEST_F(IniWriterTest, create_loose_bool_entry)
ASSERT_LE(ms.GetPosition(), 17); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = (const char*)ms.ReadString();
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(ini, "boolval = true" PLATFORM_NEWLINE);
Memory::Free(ini);
delete iw;
@ -107,7 +107,7 @@ TEST_F(IniWriterTest, create_loose_enum_entry)
ASSERT_LE(ms.GetPosition(), 37); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = (const char*)ms.ReadString();
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(ini, "by_string = stringval" PLATFORM_NEWLINE "int32_t = 0" PLATFORM_NEWLINE);
Memory::Free(ini);
delete iw;
@ -125,7 +125,7 @@ TEST_F(IniWriterTest, create_loose_float_entry)
ASSERT_LE(ms.GetPosition(), 17); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = (const char*)ms.ReadString();
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
// This will be non-fatal due to float.
EXPECT_STREQ(ini, "one = 1.000000" PLATFORM_NEWLINE);
Memory::Free(ini);
@ -148,7 +148,7 @@ TEST_F(IniWriterTest, create_loose_int32_t_entry)
ASSERT_LE(ms.GetPosition(), 78); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = (const char*)ms.ReadString();
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(
ini,
"one = 1" PLATFORM_NEWLINE "zero = 0" PLATFORM_NEWLINE "minusone = -1" PLATFORM_NEWLINE
@ -169,7 +169,7 @@ TEST_F(IniWriterTest, create_loose_string_entry)
ASSERT_LE(ms.GetPosition(), 44); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = (const char*)ms.ReadString();
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(ini, "path = \"C:'\\\\some/dir\\\\here/\xE7\xA5\x9E\xE9\xB7\xB9\xE6\x9A\xA2\xE9\x81\x8A\"" PLATFORM_NEWLINE);
Memory::Free(ini);
delete iw;
@ -193,7 +193,7 @@ TEST_F(IniWriterTest, create_multiple_section_with_values)
ASSERT_LE(ms.GetPosition(), 108); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = (const char*)ms.ReadString();
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(
ini,
"[bool]" PLATFORM_NEWLINE "boolval = true" PLATFORM_NEWLINE PLATFORM_NEWLINE "[int]" PLATFORM_NEWLINE
@ -217,7 +217,7 @@ TEST_F(IniWriterTest, create_duplicate_sections)
ASSERT_LE(ms.GetPosition(), 43); // Accommodate for varying-sized newline (Windows)
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
ms.SetPosition(0);
const char* ini = (const char*)ms.ReadString();
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
ASSERT_STREQ(
ini,
"[section]" PLATFORM_NEWLINE PLATFORM_NEWLINE "[section]" PLATFORM_NEWLINE PLATFORM_NEWLINE

View File

@ -48,8 +48,8 @@ protected:
{
RatingTuple ratings = ride.ratings;
std::string line = String::StdFormat(
"%s: (%d, %d, %d)", RideTypeDescriptors[ride.type].EnumName, (int)ratings.Excitement, (int)ratings.Intensity,
(int)ratings.Nausea);
"%s: (%d, %d, %d)", RideTypeDescriptors[ride.type].EnumName, static_cast<int>(ratings.Excitement),
static_cast<int>(ratings.Intensity), static_cast<int>(ratings.Nausea));
return line;
}
};

View File

@ -455,7 +455,8 @@ static void CompareStates(
{
log_warning(
"Inconsistent export size! Import Size: %llu bytes, Export Size: %llu bytes",
(unsigned long long)importBuffer.GetLength(), (unsigned long long)exportBuffer.GetLength());
static_cast<unsigned long long>(importBuffer.GetLength()),
static_cast<unsigned long long>(exportBuffer.GetLength()));
}
for (size_t spriteIdx = 0; spriteIdx < MAX_SPRITES; ++spriteIdx)