Merge branch 'master' of github.com:bkaradzic/bx

This commit is contained in:
Branimir Karadžić
2017-02-08 18:20:46 -08:00
4 changed files with 109 additions and 62 deletions

View File

@@ -15,40 +15,37 @@
#include "config.h"
#include "macros.h"
namespace bx
{
// 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];
///
#define BX_COUNTOF(_x) sizeof(bx::COUNTOF_REQUIRES_ARRAY_ARGUMENT(_x) )
// Template for avoiding MSVC: C4127: conditional expression is constant
template<bool>
inline bool isEnabled()
{
return true;
}
template<>
inline bool isEnabled<false>()
{
return false;
}
#define BX_ENABLED(_x) bx::isEnabled<!!(_x)>()
inline bool ignoreC4127(bool _x)
{
return _x;
}
///
#define BX_IGNORE_C4127(_x) bx::ignoreC4127(!!(_x) )
template<typename Ty>
inline void xchg(Ty& _a, Ty& _b)
{
Ty tmp = _a; _a = _b; _b = tmp;
}
///
#define BX_ENABLED(_x) bx::isEnabled<!!(_x)>()
namespace bx
{
/// Template for avoiding MSVC: C4127: conditional expression is constant
template<bool>
bool isEnabled();
///
void* memCopy(void* _dst, const void* _src, size_t _numBytes);
bool ignoreC4127(bool _x);
///
template<typename Ty>
void xchg(Ty& _a, Ty& _b);
///
void xchg(void* _a, void* _b, size_t _numBytes);
// 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);
///
void memCopy(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _srcPitch, uint32_t _dstPitch);
@@ -60,11 +57,13 @@ namespace bx
void scatter(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _dstPitch);
///
void* memMove(void* _dst, const void* _src, size_t _numBytes);
void memMove(void* _dst, const void* _src, size_t _numBytes);
///
void* memSet(void* _dst, uint8_t _ch, size_t _numBytes);
void memSet(void* _dst, uint8_t _ch, size_t _numBytes);
} // namespace bx
#include "bx.inl"
#endif // BX_H_HEADER_GUARD

35
include/bx/bx.inl Normal file
View File

@@ -0,0 +1,35 @@
/*
* Copyright 2010-2017 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
#ifndef BX_H_HEADER_GUARD
# error "Must be included from bx/bx.h!"
#endif // BX_H_HEADER_GUARD
namespace bx
{
template<bool>
inline bool isEnabled()
{
return true;
}
template<>
inline bool isEnabled<false>()
{
return false;
}
inline bool ignoreC4127(bool _x)
{
return _x;
}
template<typename Ty>
inline void xchg(Ty& _a, Ty& _b)
{
Ty tmp = _a; _a = _b; _b = tmp;
}
} // namespace bx