mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Cleanup.
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
#include "macros.h"
|
||||
|
||||
///
|
||||
#define BX_COUNTOF(_x) sizeof(bx::COUNTOF_REQUIRES_ARRAY_ARGUMENT(_x) )
|
||||
#define BX_COUNTOF(_x) sizeof(bx::CountOfRequireArrayArgumentT(_x) )
|
||||
|
||||
///
|
||||
#define BX_IGNORE_C4127(_x) bx::ignoreC4127(!!(_x) )
|
||||
@@ -38,12 +38,12 @@ namespace bx
|
||||
template<class Ty>
|
||||
constexpr bool isTriviallyCopyable();
|
||||
|
||||
/// Exchange two values.
|
||||
/// Swap two values.
|
||||
template<typename Ty>
|
||||
void xchg(Ty& _a, Ty& _b);
|
||||
void swap(Ty& _a, Ty& _b);
|
||||
|
||||
/// Exchange memory.
|
||||
void xchg(void* _a, void* _b, size_t _numBytes);
|
||||
/// Swap memory.
|
||||
void swap(void* _a, void* _b, size_t _numBytes);
|
||||
|
||||
/// Returns minimum of two values.
|
||||
template<typename Ty>
|
||||
@@ -73,10 +73,6 @@ namespace bx
|
||||
template<typename Ty>
|
||||
constexpr bool isPowerOf2(Ty _a);
|
||||
|
||||
// http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/
|
||||
template<typename T, size_t N>
|
||||
char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N];
|
||||
|
||||
///
|
||||
void memCopy(void* _dst, const void* _src, size_t _numBytes);
|
||||
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
|
||||
namespace bx
|
||||
{
|
||||
// Reference:
|
||||
// https://web.archive.org/web/20181115035420/http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/
|
||||
template<typename Ty, size_t Num>
|
||||
char(&CountOfRequireArrayArgumentT(const Ty(&)[Num]))[Num];
|
||||
|
||||
template<bool>
|
||||
inline constexpr bool isEnabled()
|
||||
{
|
||||
@@ -33,7 +38,7 @@ namespace bx
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline void xchg(Ty& _a, Ty& _b)
|
||||
inline void swap(Ty& _a, Ty& _b)
|
||||
{
|
||||
Ty tmp = _a; _a = _b; _b = tmp;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace bx
|
||||
for (uint32_t ii = 0, num = _num-1; ii < num; ++ii)
|
||||
{
|
||||
uint32_t jj = ii + 1 + _rng->gen() % (num - ii);
|
||||
bx::xchg(_array[ii], _array[jj]);
|
||||
bx::swap(_array[ii], _array[jj]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#define BX_OS_H_HEADER_GUARD
|
||||
|
||||
#include "debug.h"
|
||||
#include "filepath.h"
|
||||
|
||||
#if BX_PLATFORM_OSX
|
||||
# define BX_DL_EXT "dylib"
|
||||
@@ -31,7 +32,7 @@ namespace bx
|
||||
size_t getProcessMemoryUsed();
|
||||
|
||||
///
|
||||
void* dlopen(const char* _filePath);
|
||||
void* dlopen(const FilePath& _filePath);
|
||||
|
||||
///
|
||||
void dlclose(void* _handle);
|
||||
@@ -40,13 +41,10 @@ namespace bx
|
||||
void* dlsym(void* _handle, const char* _symbol);
|
||||
|
||||
///
|
||||
bool getenv(const char* _name, char* _out, uint32_t* _inOutSize);
|
||||
bool getEnv(const char* _name, char* _out, uint32_t* _inOutSize);
|
||||
|
||||
///
|
||||
void setenv(const char* _name, const char* _value);
|
||||
|
||||
///
|
||||
void unsetenv(const char* _name);
|
||||
void setEnv(const char* _name, const char* _value);
|
||||
|
||||
///
|
||||
int chdir(const char* _path);
|
||||
|
||||
10
makefile
10
makefile
@@ -6,8 +6,7 @@
|
||||
GENIE=../bx/tools/bin/$(OS)/genie
|
||||
|
||||
all:
|
||||
$(GENIE) vs2012
|
||||
$(GENIE) vs2013
|
||||
$(GENIE) vs2017
|
||||
$(GENIE) --gcc=android-arm gmake
|
||||
$(GENIE) --gcc=android-mips gmake
|
||||
$(GENIE) --gcc=android-x86 gmake
|
||||
@@ -75,11 +74,8 @@ mingw-clang-release64: .build/projects/gmake-mingw-clang
|
||||
make -R -C .build/projects/gmake-mingw-clang config=release64
|
||||
mingw-clang: mingw-clang-debug32 mingw-clang-release32 mingw-clang-debug64 mingw-clang-release64
|
||||
|
||||
.build/projects/vs2012:
|
||||
$(GENIE) vs2012
|
||||
|
||||
.build/projects/vs2013:
|
||||
$(GENIE) vs2013
|
||||
.build/projects/vs2017:
|
||||
$(GENIE) vs2017
|
||||
|
||||
.build/projects/gmake-osx:
|
||||
$(GENIE) --gcc=osx gmake
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
|
||||
namespace bx
|
||||
{
|
||||
void xchg(void* _a, void* _b, size_t _numBytes)
|
||||
void swap(void* _a, void* _b, size_t _numBytes)
|
||||
{
|
||||
uint8_t* lhs = (uint8_t*)_a;
|
||||
uint8_t* rhs = (uint8_t*)_b;
|
||||
const uint8_t* end = rhs + _numBytes;
|
||||
while (rhs != end)
|
||||
{
|
||||
xchg(*lhs++, *rhs++);
|
||||
swap(*lhs++, *rhs++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -467,7 +467,7 @@ namespace bx
|
||||
{
|
||||
for (int32_t ii = 0, jj = _len - 1; ii < jj; ++ii, --jj)
|
||||
{
|
||||
xchg(_dst[ii], _dst[jj]);
|
||||
swap(_dst[ii], _dst[jj]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace bx
|
||||
uint32_t len = *_inOutSize;
|
||||
*_out = '\0';
|
||||
|
||||
if (getenv(_name, _out, &len) )
|
||||
if (getEnv(_name, _out, &len) )
|
||||
{
|
||||
FileInfo fi;
|
||||
if (stat(_out, fi)
|
||||
@@ -190,9 +190,13 @@ namespace bx
|
||||
static bool getCurrentPath(char* _out, uint32_t* _inOutSize)
|
||||
{
|
||||
uint32_t len = *_inOutSize;
|
||||
pwd(_out, len);
|
||||
*_inOutSize = strLen(_out);
|
||||
return true;
|
||||
if (NULL != pwd(_out, len))
|
||||
{
|
||||
*_inOutSize = strLen(_out);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool getHomePath(char* _out, uint32_t* _inOutSize)
|
||||
|
||||
33
src/os.cpp
33
src/os.cpp
@@ -171,10 +171,10 @@ namespace bx
|
||||
#endif // BX_PLATFORM_*
|
||||
}
|
||||
|
||||
void* dlopen(const char* _filePath)
|
||||
void* dlopen(const FilePath& _filePath)
|
||||
{
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
return (void*)::LoadLibraryA(_filePath);
|
||||
return (void*)::LoadLibraryA(_filePath.get() );
|
||||
#elif BX_PLATFORM_EMSCRIPTEN \
|
||||
|| BX_PLATFORM_PS4 \
|
||||
|| BX_PLATFORM_XBOXONE \
|
||||
@@ -183,7 +183,7 @@ namespace bx
|
||||
BX_UNUSED(_filePath);
|
||||
return NULL;
|
||||
#else
|
||||
return ::dlopen(_filePath, RTLD_LOCAL|RTLD_LAZY);
|
||||
return ::dlopen(_filePath.get(), RTLD_LOCAL|RTLD_LAZY);
|
||||
#endif // BX_PLATFORM_
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace bx
|
||||
#endif // BX_PLATFORM_
|
||||
}
|
||||
|
||||
bool getenv(const char* _name, char* _out, uint32_t* _inOutSize)
|
||||
bool getEnv(const char* _name, char* _out, uint32_t* _inOutSize)
|
||||
{
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
DWORD len = ::GetEnvironmentVariableA(_name, _out, *_inOutSize);
|
||||
@@ -251,7 +251,7 @@ namespace bx
|
||||
#endif // BX_PLATFORM_
|
||||
}
|
||||
|
||||
void setenv(const char* _name, const char* _value)
|
||||
void setEnv(const char* _name, const char* _value)
|
||||
{
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
::SetEnvironmentVariableA(_name, _value);
|
||||
@@ -261,21 +261,14 @@ namespace bx
|
||||
|| BX_CRT_NONE
|
||||
BX_UNUSED(_name, _value);
|
||||
#else
|
||||
::setenv(_name, _value, 1);
|
||||
#endif // BX_PLATFORM_
|
||||
}
|
||||
|
||||
void unsetenv(const char* _name)
|
||||
{
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
::SetEnvironmentVariableA(_name, NULL);
|
||||
#elif BX_PLATFORM_PS4 \
|
||||
|| BX_PLATFORM_XBOXONE \
|
||||
|| BX_PLATFORM_WINRT \
|
||||
|| BX_CRT_NONE
|
||||
BX_UNUSED(_name);
|
||||
#else
|
||||
::unsetenv(_name);
|
||||
if (NULL == _value)
|
||||
{
|
||||
::setenv(_name, _value, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
::unsetenv(_name);
|
||||
}
|
||||
#endif // BX_PLATFORM_
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,12 @@ namespace bx
|
||||
int32_t result = _fn(&data[ii*_stride], _pivot);
|
||||
if (0 > result)
|
||||
{
|
||||
xchg(&data[ll*_stride], &data[ii*_stride], _stride);
|
||||
swap(&data[ll*_stride], &data[ii*_stride], _stride);
|
||||
++ll;
|
||||
}
|
||||
else if (0 == result)
|
||||
{
|
||||
xchg(&data[gg*_stride], &data[ii*_stride], _stride);
|
||||
swap(&data[gg*_stride], &data[ii*_stride], _stride);
|
||||
++gg;
|
||||
++ii;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user