summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-02-07 16:18:13 +0300
committerAndrei Karas <akaras@inbox.ru>2016-02-07 16:18:13 +0300
commit9fe21fcd8883b37bdc30224822e6e42afb35b8f0 (patch)
tree798117abd4dc7e610997d59d530a96ddc1509f53 /src/utils
parent4429cb14e9e187edef27aba692a4266733f79c17 (diff)
downloadmv-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.gz
mv-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.bz2
mv-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.xz
mv-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.zip
Replace most static_cast<Type> to shorter versions from defines.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/base64.cpp20
-rw-r--r--src/utils/copynpaste.cpp4
-rw-r--r--src/utils/mathutils.h8
-rw-r--r--src/utils/mathutils_unittest.cc2
-rw-r--r--src/utils/mkdir.cpp4
-rw-r--r--src/utils/physfsrwops.cpp14
-rw-r--r--src/utils/physfstools.cpp2
-rw-r--r--src/utils/sdlhelper.cpp8
-rw-r--r--src/utils/sdlpixel.h48
-rw-r--r--src/utils/stringutils.cpp40
-rw-r--r--src/utils/stringutils_unittest.cc4
-rw-r--r--src/utils/xml/libxml.cpp2
-rw-r--r--src/utils/xml/pugixml.cpp2
13 files changed, 79 insertions, 79 deletions
diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp
index 7be63c090..ddf117ec4 100644
--- a/src/utils/base64.cpp
+++ b/src/utils/base64.cpp
@@ -50,7 +50,7 @@ unsigned char *php3_base64_encode(const unsigned char *restrict const string,
const unsigned char *current = string;
int i = 0;
unsigned char *const result = static_cast<unsigned char *>(
- calloc(static_cast<size_t>((length + 3 - length % 3) * 4 / 3 + 1)
+ calloc(CAST_SIZE((length + 3 - length % 3) * 4 / 3 + 1)
* sizeof(unsigned char), 1));
if (!result)
return nullptr;
@@ -126,23 +126,23 @@ unsigned char *php3_base64_decode(const unsigned char *restrict const string,
const char *const chp = strchr(base64_table, ch);
if (!chp)
continue;
- ch = static_cast<int>(chp - base64_table);
+ ch = CAST_S32(chp - base64_table);
switch (i % 4)
{
case 0:
- result[j] = static_cast<unsigned char>(ch << 2U);
+ result[j] = CAST_U8(ch << 2U);
break;
case 1:
- result[j++] |= static_cast<unsigned char>(ch >> 4U);
- result[j] = static_cast<unsigned char>((ch & 0x0f) << 4U);
+ result[j++] |= CAST_U8(ch >> 4U);
+ result[j] = CAST_U8((ch & 0x0f) << 4U);
break;
case 2:
- result[j++] |= static_cast<unsigned char>(ch >>2U);
- result[j] = static_cast<unsigned char>((ch & 0x03) << 6U);
+ result[j++] |= CAST_U8(ch >>2U);
+ result[j] = CAST_U8((ch & 0x03) << 6U);
break;
case 3:
- result[j++] |= static_cast<unsigned char>(ch);
+ result[j++] |= CAST_U8(ch);
break;
default:
break;
@@ -183,7 +183,7 @@ std::string encodeBase64String(std::string value)
const unsigned char *const str = reinterpret_cast<unsigned char*>(
const_cast<char*>(value.c_str()));
unsigned char *const buf = php3_base64_encode(
- str, static_cast<int>(value.size()), &sz);
+ str, CAST_S32(value.size()), &sz);
if (!buf)
return std::string();
@@ -198,7 +198,7 @@ std::string decodeBase64String(std::string value)
const unsigned char *const str = reinterpret_cast<unsigned char*>(
const_cast<char*>(value.c_str()));
unsigned char *const buf = php3_base64_decode(
- str, static_cast<int>(value.size()), &sz);
+ str, CAST_S32(value.size()), &sz);
if (buf)
value = std::string(reinterpret_cast<char*>(buf), sz);
diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp
index 1bec05699..8a413c1f7 100644
--- a/src/utils/copynpaste.cpp
+++ b/src/utils/copynpaste.cpp
@@ -128,7 +128,7 @@ bool sendBuffer(std::string& text)
return false;
HANDLE h = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
- static_cast<size_t>(wCharsLen) * sizeof(WCHAR));
+ CAST_SIZE(wCharsLen) * sizeof(WCHAR));
WCHAR *const out = static_cast<WCHAR*>(GlobalLock(h));
MultiByteToWideChar(CP_UTF8, 0, text.c_str(), -1, out, wCharsLen);
@@ -460,7 +460,7 @@ static bool runxsel(std::string& text, const char *p1, const char *p2)
// parent
close(fd[0]);
- const int len = static_cast<int>(strlen(text.c_str()));
+ const int len = CAST_S32(strlen(text.c_str()));
if (write(fd[1], text.c_str(), len) != len)
{
close(fd[1]);
diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h
index c5b6a515d..4bc3cf104 100644
--- a/src/utils/mathutils.h
+++ b/src/utils/mathutils.h
@@ -185,7 +185,7 @@ inline uint16_t getCrc16(const std::string &str)
while (f != 0)
{
f --;
- crc16 = static_cast<uint16_t>(
+ crc16 = CAST_U16(
crc_table[(crc16 ^ (str[f])) & 0xff] ^ (crc16 >> 8));
}
@@ -225,7 +225,7 @@ constexpr inline float weightedAverage(const float n1, const float n2,
constexpr inline int roundDouble(const double v)
{
- return (v > 0.0) ? static_cast<int>(v + 0.5) : static_cast<int>(v - 0.5);
+ return (v > 0.0) ? CAST_S32(v + 0.5) : CAST_S32(v - 0.5);
}
constexpr2 inline int powerOfTwo(const unsigned int input)
@@ -239,8 +239,8 @@ constexpr2 inline int powerOfTwo(const unsigned int input)
constexpr2 inline int fastSqrtInt(const unsigned int n)
{
if (n < 1000)
- return static_cast<int>(square_roots[n]);
- return static_cast<int>(sqrt(n));
+ return CAST_S32(square_roots[n]);
+ return CAST_S32(sqrt(n));
}
#endif // UTILS_MATHUTILS_H
diff --git a/src/utils/mathutils_unittest.cc b/src/utils/mathutils_unittest.cc
index 0b5ece474..7f0cc957c 100644
--- a/src/utils/mathutils_unittest.cc
+++ b/src/utils/mathutils_unittest.cc
@@ -98,5 +98,5 @@ TEST_CASE("MathUtils powerOfTwo")
TEST_CASE("MathUtils tests fastSqrtInt")
{
for (int f = 0; f < 1005; f ++)
- REQUIRE(fastSqrtInt(f) == static_cast<int>(sqrt(f)));
+ REQUIRE(fastSqrtInt(f) == CAST_S32(sqrt(f)));
}
diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp
index 0ecd7fc31..f7a2aba37 100644
--- a/src/utils/mkdir.cpp
+++ b/src/utils/mkdir.cpp
@@ -52,7 +52,7 @@ int mkdir_r(const char *const pathname)
strncpy(tmp, pathname, sizeof(tmp) - 1);
tmp[PATH_MAX - 1] = '\0';
- const int len = static_cast<int>(strlen(tmp));
+ const int len = CAST_S32(strlen(tmp));
if (len < 1)
return -1;
@@ -117,7 +117,7 @@ int mkdir_r(const char *const pathname)
if (!pathname)
return -1;
- const size_t len = static_cast<size_t>(strlen(pathname));
+ const size_t len = CAST_SIZE(strlen(pathname));
char *tmp = new char[len + 2];
char *p = nullptr;
diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp
index 3599f7f31..e5e7e8e98 100644
--- a/src/utils/physfsrwops.cpp
+++ b/src/utils/physfsrwops.cpp
@@ -66,7 +66,7 @@ static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw, const PHYSFSINT offset,
return -1;
} /* if */
- pos = static_cast<int>(current);
+ pos = CAST_S32(current);
if (static_cast<PHYSFS_sint64>(pos) != current)
{
SDL_SetError("Can't fit current file position in an int!");
@@ -127,15 +127,15 @@ static PHYSFSSIZE physfsrwops_read(SDL_RWops *const rw,
PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
rw->hidden.unknown.data1);
const PHYSFS_sint64 rc = PHYSFS_read(handle, ptr,
- static_cast<unsigned int>(size),
- static_cast<unsigned int>(maxnum));
+ CAST_U32(size),
+ CAST_U32(maxnum));
if (rc != static_cast<PHYSFS_sint64>(maxnum))
{
if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
} /* if */
- return static_cast<int>(rc);
+ return CAST_S32(rc);
} /* physfsrwops_read */
static PHYSFSSIZE physfsrwops_write(SDL_RWops *const rw, const void *ptr,
@@ -147,12 +147,12 @@ static PHYSFSSIZE physfsrwops_write(SDL_RWops *const rw, const void *ptr,
PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
rw->hidden.unknown.data1);
const PHYSFS_sint64 rc = PHYSFS_write(handle, ptr,
- static_cast<unsigned int>(size),
- static_cast<unsigned int>(num));
+ CAST_U32(size),
+ CAST_U32(num));
if (rc != static_cast<PHYSFS_sint64>(num))
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
- return static_cast<int>(rc);
+ return CAST_S32(rc);
} /* physfsrwops_write */
static int physfsrwops_close(SDL_RWops *const rw)
diff --git a/src/utils/physfstools.cpp b/src/utils/physfstools.cpp
index 6e2332709..8ee72f7b9 100644
--- a/src/utils/physfstools.cpp
+++ b/src/utils/physfstools.cpp
@@ -152,7 +152,7 @@ namespace PhysFs
logger->log("Loaded %s/%s", PhysFs::getRealDir(fileName.c_str()),
fileName.c_str());
- fileSize = static_cast<int>(PHYSFS_fileLength(file));
+ fileSize = CAST_S32(PHYSFS_fileLength(file));
// Allocate memory and load the file
void *const buffer = calloc(fileSize, 1);
PHYSFS_read(file, buffer, 1, fileSize);
diff --git a/src/utils/sdlhelper.cpp b/src/utils/sdlhelper.cpp
index 73157f15c..bc5e75a56 100644
--- a/src/utils/sdlhelper.cpp
+++ b/src/utils/sdlhelper.cpp
@@ -44,8 +44,8 @@ bool SDL::getAllVideoModes(StringVect &modeList)
#ifdef ANDROID
const std::string modeString =
- toString(static_cast<int>(modes[0]->w)).append("x")
- .append(toString(static_cast<int>(modes[0]->h)));
+ toString(CAST_S32(modes[0]->w)).append("x")
+ .append(toString(CAST_S32(modes[0]->h)));
logger->log("support mode: " + modeString);
modeList.push_back(modeString);
return true;
@@ -66,8 +66,8 @@ bool SDL::getAllVideoModes(StringVect &modeList)
for (int i = 0; modes[i]; ++ i)
{
const std::string modeString =
- toString(static_cast<int>(modes[i]->w)).append("x")
- .append(toString(static_cast<int>(modes[i]->h)));
+ toString(CAST_S32(modes[i]->w)).append("x")
+ .append(toString(CAST_S32(modes[i]->h)));
logger->log("support mode: " + modeString);
modeList.push_back(modeString);
}
diff --git a/src/utils/sdlpixel.h b/src/utils/sdlpixel.h
index bc7236334..66f4c2862 100644
--- a/src/utils/sdlpixel.h
+++ b/src/utils/sdlpixel.h
@@ -86,31 +86,31 @@ inline void SDLputPixel(SDL_Surface* surface, int x, int y,
SDL_LockSurface(surface);
Uint8 *const p = static_cast<uint8_t*>(surface->pixels)
- + static_cast<size_t>(y * surface->pitch + x * bpp);
+ + CAST_SIZE(y * surface->pitch + x * bpp);
const Uint32 pixel = SDL_MapRGB(surface->format,
- static_cast<uint8_t>(color.r), static_cast<uint8_t>(color.g),
- static_cast<uint8_t>(color.b));
+ CAST_U8(color.r), CAST_U8(color.g),
+ CAST_U8(color.b));
switch (bpp)
{
case 1:
- *p = static_cast<uint8_t>(pixel);
+ *p = CAST_U8(pixel);
break;
case 2:
- *reinterpret_cast<uint16_t*>(p) = static_cast<uint16_t>(pixel);
+ *reinterpret_cast<uint16_t*>(p) = CAST_U16(pixel);
break;
case 3:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- p[0] = static_cast<uint8_t>((pixel >> 16) & 0xff);
- p[1] = static_cast<uint8_t>((pixel >> 8) & 0xff);
- p[2] = static_cast<uint8_t>((pixel) & 0xff);
+ p[0] = CAST_U8((pixel >> 16) & 0xff);
+ p[1] = CAST_U8((pixel >> 8) & 0xff);
+ p[2] = CAST_U8((pixel) & 0xff);
#else
- p[0] = static_cast<uint8_t>((pixel) & 0xff);
- p[1] = static_cast<uint8_t>((pixel >> 8) & 0xff);
- p[2] = static_cast<uint8_t>((pixel >> 16) & 0xff);
+ p[0] = CAST_U8((pixel) & 0xff);
+ p[1] = CAST_U8((pixel >> 8) & 0xff);
+ p[2] = CAST_U8((pixel >> 16) & 0xff);
#endif
break;
@@ -190,40 +190,40 @@ inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y,
SDL_LockSurface(surface);
Uint8 *const p = static_cast<uint8_t*>(surface->pixels)
- + static_cast<size_t>(y * surface->pitch + x * bpp);
+ + CAST_SIZE(y * surface->pitch + x * bpp);
const Uint32 pixel = SDL_MapRGB(surface->format,
- static_cast<uint8_t>(color.r),
- static_cast<uint8_t>(color.g),
- static_cast<uint8_t>(color.b));
+ CAST_U8(color.r),
+ CAST_U8(color.g),
+ CAST_U8(color.b));
switch (bpp)
{
case 1:
- *p = static_cast<uint8_t>(pixel);
+ *p = CAST_U8(pixel);
break;
case 2:
*reinterpret_cast<Uint16*>(p) = SDLAlpha16(
static_cast<unsigned short>(pixel),
*reinterpret_cast<unsigned short*>(p),
- static_cast<unsigned char>(color.a), surface->format);
+ CAST_U8(color.a), surface->format);
break;
case 3:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- p[2] = static_cast<uint8_t>((p[2] * (255 - color.a)
+ p[2] = CAST_U8((p[2] * (255 - color.a)
+ color.b * color.a) >> 8);
- p[1] = static_cast<uint8_t>((p[1] * (255 - color.a)
+ p[1] = CAST_U8((p[1] * (255 - color.a)
+ color.g * color.a) >> 8);
- p[0] = static_cast<uint8_t>((p[0] * (255 - color.a)
+ p[0] = CAST_U8((p[0] * (255 - color.a)
+ color.r * color.a) >> 8);
#else
- p[0] = static_cast<uint8_t>((p[0] * (255 - color.a)
+ p[0] = CAST_U8((p[0] * (255 - color.a)
+ color.b * color.a) >> 8);
- p[1] = static_cast<uint8_t>((p[1] * (255 - color.a)
+ p[1] = CAST_U8((p[1] * (255 - color.a)
+ color.g * color.a) >> 8);
- p[2] = static_cast<uint8_t>((p[2] * (255 - color.a)
+ p[2] = CAST_U8((p[2] * (255 - color.a)
+ color.r * color.a) >> 8);
#endif
break;
@@ -231,7 +231,7 @@ inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y,
case 4:
*reinterpret_cast<Uint32*>(p) = SDLAlpha32(pixel,
*reinterpret_cast<Uint32*>(p),
- static_cast<unsigned char>(color.a));
+ CAST_U8(color.a));
break;
default:
break;
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index ebaee1b4b..ba6e46ee0 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -85,10 +85,10 @@ const char *ipToString(const uint32_t address)
static char asciiIP[18];
snprintf(asciiIP, sizeof(asciiIP), "%i.%i.%i.%i",
- static_cast<unsigned char>(address),
- static_cast<unsigned char>(address >> 8),
- static_cast<unsigned char>(address >> 16),
- static_cast<unsigned char>(address >> 24));
+ CAST_U8(address),
+ CAST_U8(address >> 8),
+ CAST_U8(address >> 16),
+ CAST_U8(address >> 24));
asciiIP[17] = 0;
return asciiIP;
@@ -162,7 +162,7 @@ const std::string findSameSubstring(const std::string &restrict str1,
const std::string &restrict str2)
{
const int minLength = str1.length() > str2.length()
- ? static_cast<int>(str2.length()) : static_cast<int>(str1.length());
+ ? CAST_S32(str2.length()) : CAST_S32(str1.length());
for (int f = 0; f < minLength; f ++)
{
if (str1.at(f) != str2.at(f))
@@ -222,13 +222,13 @@ const std::string encodeStr(unsigned int value, const unsigned int size)
do
{
- buf += static_cast<signed char>(value % base + start);
+ buf += CAST_S8(value % base + start);
value /= base;
}
while (value);
while (buf.length() < size)
- buf += static_cast<signed char>(start);
+ buf += CAST_S8(start);
return buf;
}
@@ -261,9 +261,9 @@ std::string extractNameFromSprite(std::string str)
pos2 = pos3;
}
if (pos2 == std::string::npos)
- pos2 = static_cast<size_t>(-1);
+ pos2 = CAST_SIZE(-1);
- const int size = static_cast<int>(pos1) - static_cast<int>(pos2) - 1;
+ const int size = CAST_S32(pos1) - CAST_S32(pos2) - 1;
if (size > 0)
str = str.substr(pos2 + 1, size);
}
@@ -284,9 +284,9 @@ std::string removeSpriteIndex(std::string str)
pos2 = pos3;
}
if (pos2 == std::string::npos)
- pos2 = static_cast<size_t>(-1);
+ pos2 = CAST_SIZE(-1);
- const int size = static_cast<int>(pos1) - static_cast<int>(pos2) - 1;
+ const int size = CAST_S32(pos1) - CAST_S32(pos2) - 1;
if (size > 0)
str = str.substr(pos2 + 1, size);
}
@@ -400,7 +400,7 @@ void replaceSpecialChars(std::string &text)
if (idx + 1 < f && text[f] == ';')
{
std::string str(" ");
- str[0] = static_cast<signed char>(atoi(text.substr(
+ str[0] = CAST_S8(atoi(text.substr(
idx, f - idx).c_str()));
text = text.substr(0, pos1) + str + text.substr(f + 1);
pos1 += 1;
@@ -585,11 +585,11 @@ std::string stringToHexPath(const std::string &str)
if (str.empty())
return "";
- std::string hex = strprintf("%%%2x/", static_cast<unsigned int>(str[0]));
- for (unsigned f = 1, sz = static_cast<unsigned int>(str.size());
+ std::string hex = strprintf("%%%2x/", CAST_U32(str[0]));
+ for (unsigned f = 1, sz = CAST_U32(str.size());
f < sz; f ++)
{
- hex.append(strprintf("%%%2x", static_cast<unsigned int>(str[f])));
+ hex.append(strprintf("%%%2x", CAST_U32(str[f])));
}
return hex;
}
@@ -760,7 +760,7 @@ std::string toString(unsigned int num)
buf[29] = '\0';
size_t idx = 28;
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
return buf + idx + 1;
}
@@ -771,7 +771,7 @@ std::string toString(unsigned long num)
buf[99] = '\0';
size_t idx = 98;
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
return buf + idx + 1;
}
@@ -782,7 +782,7 @@ std::string toString(uint16_t num)
buf[9] = '\0';
size_t idx = 8;
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
return buf + idx + 1;
}
@@ -793,7 +793,7 @@ std::string toString(unsigned char num)
buf[4] = '\0';
size_t idx = 3;
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
return buf + idx + 1;
}
@@ -811,7 +811,7 @@ std::string toString(int num)
num = -num;
}
do
- buf[idx--] = static_cast<char>((num % 10) + '0');
+ buf[idx--] = CAST_8((num % 10) + '0');
while (num /= 10);
if (useSign)
buf[idx--] = '-';
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index 09120c844..f6586558c 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -127,8 +127,8 @@ TEST_CASE("stringuntils toString 1")
REQUIRE(strprintf("%d", -10000000) == toString(-10000000));
REQUIRE(strprintf("%d", 30000000) == toString(
static_cast<signed int>(30000000)));
- REQUIRE(strprintf("%d", 3000) == toString(static_cast<uint16_t>(3000)));
- REQUIRE(strprintf("%d", 123) == toString(static_cast<unsigned char>(123)));
+ REQUIRE(strprintf("%d", 3000) == toString(CAST_U16(3000)));
+ REQUIRE(strprintf("%d", 123) == toString(CAST_U8(123)));
}
TEST_CASE("stringuntils toString 2")
diff --git a/src/utils/xml/libxml.cpp b/src/utils/xml/libxml.cpp
index 29bd83b4b..46d184067 100644
--- a/src/utils/xml/libxml.cpp
+++ b/src/utils/xml/libxml.cpp
@@ -108,7 +108,7 @@ namespace XML
{
// Get length of file
file.seekg(0, std::ios::end);
- size = static_cast<int>(file.tellg());
+ size = CAST_S32(file.tellg());
if (size < 0)
{
logger->log("Error loading XML file %s", filename.c_str());
diff --git a/src/utils/xml/pugixml.cpp b/src/utils/xml/pugixml.cpp
index 9ca717d83..0f01c7f10 100644
--- a/src/utils/xml/pugixml.cpp
+++ b/src/utils/xml/pugixml.cpp
@@ -84,7 +84,7 @@ namespace XML
{
// Get length of file
file.seekg(0, std::ios::end);
- size = static_cast<int>(file.tellg());
+ size = CAST_S32(file.tellg());
if (size < 0)
{
logger->log("Error loading XML file %s", filename.c_str());