Added latest BX (nw)

This commit is contained in:
Miodrag Milanovic 2015-09-12 10:22:55 +02:00
parent 115ffcb10a
commit 6d06509293
33 changed files with 1883 additions and 301 deletions

View File

@ -58,14 +58,6 @@ namespace bx
return un.ptr;
}
/// Check if pointer is aligned. _align must be power of two.
inline bool isPtrAligned(const void* _ptr, size_t _align = BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT)
{
union { const void* ptr; size_t addr; } un;
un.ptr = _ptr;
return 0 == (un.addr & (_align-1) );
}
struct BX_NO_VTABLE AllocatorI
{
virtual ~AllocatorI() = 0;

View File

@ -1,99 +0,0 @@
/*
* Copyright 2010-2015 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#ifndef BX_BLOCKALLOC_H_HEADER_GUARD
#define BX_BLOCKALLOC_H_HEADER_GUARD
#include "bx.h"
namespace bx
{
class BlockAlloc
{
public:
static const uint16_t invalidIndex = 0xffff;
static const uint32_t minElementSize = 2;
BlockAlloc()
: m_data(NULL)
, m_num(0)
, m_size(0)
, m_numFree(0)
, m_freeIndex(invalidIndex)
{
}
BlockAlloc(void* _data, uint16_t _num, uint16_t _size)
: m_data(_data)
, m_num(_num)
, m_size(_size)
, m_numFree(_num)
, m_freeIndex(0)
{
char* data = (char*)_data;
uint16_t* index = (uint16_t*)_data;
for (uint16_t ii = 0; ii < m_num-1; ++ii)
{
*index = ii+1;
data += m_size;
index = (uint16_t*)data;
}
*index = invalidIndex;
}
~BlockAlloc()
{
}
void* alloc()
{
if (invalidIndex == m_freeIndex)
{
return NULL;
}
void* obj = ( (char*)m_data) + m_freeIndex*m_size;
m_freeIndex = *( (uint16_t*)obj);
--m_numFree;
return obj;
}
void free(void* _obj)
{
uint16_t index = getIndex(_obj);
BX_CHECK(index < m_num, "index %d, m_num %d", index, m_num);
*( (uint16_t*)_obj) = m_freeIndex;
m_freeIndex = index;
++m_numFree;
}
uint16_t getIndex(void* _obj) const
{
return (uint16_t)( ( (char*)_obj - (char*)m_data ) / m_size);
}
uint16_t getNumFree() const
{
return m_numFree;
}
void* getFromIndex(uint16_t _index)
{
return (char*)m_data + _index*m_size;
}
private:
void* m_data;
uint16_t m_num;
uint16_t m_size;
uint16_t m_numFree;
uint16_t m_freeIndex;
};
} // namespace bx
#endif // BX_BLOCKALLOC_H_HEADER_GUARD

View File

@ -44,6 +44,14 @@ namespace bx
Ty tmp = _a; _a = _b; _b = tmp;
}
/// Check if pointer is aligned. _align must be power of two.
inline bool isPtrAligned(const void* _ptr, size_t _align)
{
union { const void* ptr; size_t addr; } un;
un.ptr = _ptr;
return 0 == (un.addr & (_align-1) );
}
} // namespace bx
// Annoying C++0x stuff..

View File

@ -24,6 +24,7 @@
# define BX_CONFIG_CRT_FILE_READER_WRITER (0 \
|| BX_PLATFORM_ANDROID \
|| BX_PLATFORM_FREEBSD \
|| BX_PLATFORM_EMSCRIPTEN \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_OSX \

View File

@ -31,7 +31,7 @@ namespace bx
inline float fround(float _f)
{
return float(int(_f) );
return floorf(_f + 0.5f);
}
inline float fmin(float _a, float _b)
@ -121,6 +121,25 @@ namespace bx
return result;
}
// References:
// - Bias And Gain Are Your Friend
// http://blog.demofox.org/2012/09/24/bias-and-gain-are-your-friend/
// - http://demofox.org/biasgain.html
inline float fbias(float _time, float _bias)
{
return _time / ( ( (1.0f/_bias - 2.0f)*(1.0f - _time) ) + 1.0f);
}
inline float fgain(float _time, float _gain)
{
if (_time < 0.5f)
{
return fbias(_time * 2.0f, _gain) * 0.5f;
}
return fbias(_time * 2.0f - 1.0f, 1.0f - _gain) * 0.5f + 0.5f;
}
inline void vec3Move(float* __restrict _result, const float* __restrict _a)
{
_result[0] = _a[0];
@ -833,6 +852,82 @@ namespace bx
_result[3] = -vec3Dot(normal, _va);
}
inline void calcLinearFit2D(float _result[2], const void* _points, uint32_t _stride, uint32_t _numPoints)
{
float sumX = 0.0f;
float sumY = 0.0f;
float sumXX = 0.0f;
float sumXY = 0.0f;
const uint8_t* ptr = (const uint8_t*)_points;
for (uint32_t ii = 0; ii < _numPoints; ++ii, ptr += _stride)
{
const float* point = (const float*)ptr;
float xx = point[0];
float yy = point[1];
sumX += xx;
sumY += yy;
sumXX += xx*xx;
sumXY += xx*yy;
}
// [ sum(x^2) sum(x) ] [ A ] = [ sum(x*y) ]
// [ sum(x) numPoints ] [ B ] [ sum(y) ]
float det = (sumXX*_numPoints - sumX*sumX);
float invDet = 1.0f/det;
_result[0] = (-sumX * sumY + _numPoints * sumXY) * invDet;
_result[1] = (sumXX * sumY - sumX * sumXY) * invDet;
}
inline void calcLinearFit3D(float _result[3], const void* _points, uint32_t _stride, uint32_t _numPoints)
{
float sumX = 0.0f;
float sumY = 0.0f;
float sumZ = 0.0f;
float sumXX = 0.0f;
float sumXY = 0.0f;
float sumXZ = 0.0f;
float sumYY = 0.0f;
float sumYZ = 0.0f;
const uint8_t* ptr = (const uint8_t*)_points;
for (uint32_t ii = 0; ii < _numPoints; ++ii, ptr += _stride)
{
const float* point = (const float*)ptr;
float xx = point[0];
float yy = point[1];
float zz = point[2];
sumX += xx;
sumY += yy;
sumZ += zz;
sumXX += xx*xx;
sumXY += xx*yy;
sumXZ += xx*zz;
sumYY += yy*yy;
sumYZ += yy*zz;
}
// [ sum(x^2) sum(x*y) sum(x) ] [ A ] [ sum(x*z) ]
// [ sum(x*y) sum(y^2) sum(y) ] [ B ] = [ sum(y*z) ]
// [ sum(x) sum(y) numPoints ] [ C ] [ sum(z) ]
float mtx[9] =
{
sumXX, sumXY, sumX,
sumXY, sumYY, sumY,
sumX, sumY, float(_numPoints),
};
float invMtx[9];
mtx3Inverse(invMtx, mtx);
_result[0] = invMtx[0]*sumXZ + invMtx[1]*sumYZ + invMtx[2]*sumZ;
_result[1] = invMtx[3]*sumXZ + invMtx[4]*sumYZ + invMtx[5]*sumZ;
_result[2] = invMtx[6]*sumXZ + invMtx[7]*sumYZ + invMtx[8]*sumZ;
}
inline void rgbToHsv(float _hsv[3], const float _rgb[3])
{
const float rr = _rgb[0];

View File

@ -11,102 +11,16 @@
namespace bx
{
template <uint16_t MaxHandlesT>
class HandleAllocT
{
public:
static const uint16_t invalid = 0xffff;
HandleAllocT()
: m_numHandles(0)
{
for (uint16_t ii = 0; ii < MaxHandlesT; ++ii)
{
m_handles[ii] = ii;
}
}
~HandleAllocT()
{
}
const uint16_t* getHandles() const
{
return m_handles;
}
uint16_t getHandleAt(uint16_t _at) const
{
return m_handles[_at];
}
uint16_t getNumHandles() const
{
return m_numHandles;
}
uint16_t getMaxHandles() const
{
return MaxHandlesT;
}
uint16_t alloc()
{
if (m_numHandles < MaxHandlesT)
{
uint16_t index = m_numHandles;
++m_numHandles;
uint16_t handle = m_handles[index];
uint16_t* sparse = &m_handles[MaxHandlesT];
sparse[handle] = index;
return handle;
}
return invalid;
}
bool isValid(uint16_t _handle)
{
uint16_t* sparse = &m_handles[MaxHandlesT];
uint16_t index = sparse[_handle];
return index < m_numHandles
&& m_handles[index] == _handle
;
}
void free(uint16_t _handle)
{
BX_CHECK(0 < m_numHandles, "Freeing invalid handle %d.", _handle);
uint16_t* sparse = &m_handles[MaxHandlesT];
uint16_t index = sparse[_handle];
--m_numHandles;
uint16_t temp = m_handles[m_numHandles];
m_handles[m_numHandles] = _handle;
sparse[temp] = index;
m_handles[index] = temp;
}
private:
uint16_t m_handles[MaxHandlesT*2];
uint16_t m_numHandles;
};
class HandleAlloc
{
public:
static const uint16_t invalid = 0xffff;
static const uint16_t invalid = UINT16_MAX;
HandleAlloc(uint16_t _maxHandles, void* _handles)
: m_handles( (uint16_t*)_handles)
, m_numHandles(0)
HandleAlloc(uint16_t _maxHandles)
: m_numHandles(0)
, m_maxHandles(_maxHandles)
{
for (uint16_t ii = 0; ii < _maxHandles; ++ii)
{
m_handles[ii] = ii;
}
reset();
}
~HandleAlloc()
@ -115,12 +29,12 @@ namespace bx
const uint16_t* getHandles() const
{
return m_handles;
return getDensePtr();
}
uint16_t getHandleAt(uint16_t _at) const
{
return m_handles[_at];
return getDensePtr()[_at];
}
uint16_t getNumHandles() const
@ -140,8 +54,9 @@ namespace bx
uint16_t index = m_numHandles;
++m_numHandles;
uint16_t handle = m_handles[index];
uint16_t* sparse = &m_handles[m_maxHandles];
uint16_t* dense = getDensePtr();
uint16_t handle = dense[index];
uint16_t* sparse = getSparsePtr();
sparse[handle] = index;
return handle;
}
@ -149,27 +64,53 @@ namespace bx
return invalid;
}
bool isValid(uint16_t _handle)
bool isValid(uint16_t _handle) const
{
uint16_t* sparse = &m_handles[m_maxHandles];
uint16_t* dense = getDensePtr();
uint16_t* sparse = getSparsePtr();
uint16_t index = sparse[_handle];
return (index < m_numHandles && m_handles[index] == _handle);
return index < m_numHandles
&& dense[index] == _handle
;
}
void free(uint16_t _handle)
{
uint16_t* sparse = &m_handles[m_maxHandles];
uint16_t* dense = getDensePtr();
uint16_t* sparse = getSparsePtr();
uint16_t index = sparse[_handle];
--m_numHandles;
uint16_t temp = m_handles[m_numHandles];
m_handles[m_numHandles] = _handle;
uint16_t temp = dense[m_numHandles];
dense[m_numHandles] = _handle;
sparse[temp] = index;
m_handles[index] = temp;
dense[index] = temp;
}
void reset()
{
m_numHandles = 0;
uint16_t* dense = getDensePtr();
for (uint16_t ii = 0, num = m_maxHandles; ii < num; ++ii)
{
dense[ii] = ii;
}
}
private:
uint16_t* m_handles;
HandleAlloc();
uint16_t* getDensePtr() const
{
uint8_t* ptr = (uint8_t*)reinterpret_cast<const uint8_t*>(this);
return (uint16_t*)&ptr[sizeof(HandleAlloc)];
}
uint16_t* getSparsePtr() const
{
return &getDensePtr()[m_maxHandles];
}
uint16_t m_numHandles;
uint16_t m_maxHandles;
};
@ -177,7 +118,7 @@ namespace bx
inline HandleAlloc* createHandleAlloc(AllocatorI* _allocator, uint16_t _maxHandles)
{
uint8_t* ptr = (uint8_t*)BX_ALLOC(_allocator, sizeof(HandleAlloc) + 2*_maxHandles*sizeof(uint16_t) );
return ::new (ptr) HandleAlloc(_maxHandles, &ptr[sizeof(HandleAlloc)]);
return ::new (ptr) HandleAlloc(_maxHandles);
}
inline void destroyHandleAlloc(AllocatorI* _allocator, HandleAlloc* _handleAlloc)
@ -186,6 +127,301 @@ namespace bx
BX_FREE(_allocator, _handleAlloc);
}
template <uint16_t MaxHandlesT>
class HandleAllocT : public HandleAlloc
{
public:
HandleAllocT()
: HandleAlloc(MaxHandlesT)
{
}
~HandleAllocT()
{
}
private:
uint16_t m_padding[2*MaxHandlesT];
};
template <uint16_t MaxHandlesT>
class HandleListT
{
public:
static const uint16_t invalid = UINT16_MAX;
HandleListT()
: m_front(invalid)
, m_back(invalid)
{
reset();
}
void pushBack(uint16_t _handle)
{
insertAfter(m_back, _handle);
}
uint16_t popBack()
{
uint16_t last = invalid != m_back
? m_back
: m_front
;
if (invalid != last)
{
remove(last);
}
return last;
}
void pushFront(uint16_t _handle)
{
insertBefore(m_front, _handle);
}
uint16_t popFront()
{
uint16_t front = m_front;
if (invalid != front)
{
remove(front);
}
return front;
}
uint16_t getFront() const
{
return m_front;
}
uint16_t getBack() const
{
return m_back;
}
uint16_t getNext(uint16_t _handle) const
{
BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle);
const Link& curr = m_links[_handle];
return curr.m_next;
}
uint16_t getPrev(uint16_t _handle) const
{
BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle);
const Link& curr = m_links[_handle];
return curr.m_prev;
}
void remove(uint16_t _handle)
{
BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle);
Link& curr = m_links[_handle];
if (invalid != curr.m_prev)
{
Link& prev = m_links[curr.m_prev];
prev.m_next = curr.m_next;
}
else
{
m_front = curr.m_next;
}
if (invalid != curr.m_next)
{
Link& next = m_links[curr.m_next];
next.m_prev = curr.m_prev;
}
else
{
m_back = curr.m_prev;
}
curr.m_prev = invalid;
curr.m_next = invalid;
}
void reset()
{
memset(m_links, 0xff, sizeof(m_links) );
}
private:
void insertBefore(int16_t _before, uint16_t _handle)
{
Link& curr = m_links[_handle];
curr.m_next = _before;
if (invalid != _before)
{
Link& link = m_links[_before];
if (invalid != link.m_prev)
{
Link& prev = m_links[link.m_prev];
prev.m_next = _handle;
}
curr.m_prev = link.m_prev;
link.m_prev = _handle;
}
updateFrontBack(_handle);
}
void insertAfter(uint16_t _after, uint16_t _handle)
{
Link& curr = m_links[_handle];
curr.m_prev = _after;
if (invalid != _after)
{
Link& link = m_links[_after];
if (invalid != link.m_next)
{
Link& next = m_links[link.m_next];
next.m_prev = _handle;
}
curr.m_next = link.m_next;
link.m_next = _handle;
}
updateFrontBack(_handle);
}
bool isValid(uint16_t _handle) const
{
return _handle < MaxHandlesT;
}
void updateFrontBack(uint16_t _handle)
{
Link& curr = m_links[_handle];
if (invalid == curr.m_prev)
{
m_front = _handle;
}
if (invalid == curr.m_next)
{
m_back = _handle;
}
}
uint16_t m_front;
uint16_t m_back;
struct Link
{
uint16_t m_prev;
uint16_t m_next;
};
Link m_links[MaxHandlesT];
};
template <uint16_t MaxHandlesT>
class HandleAllocLruT
{
public:
static const uint16_t invalid = UINT16_MAX;
HandleAllocLruT()
{
reset();
}
~HandleAllocLruT()
{
}
const uint16_t* getHandles() const
{
return m_alloc.getHandles();
}
uint16_t getHandleAt(uint16_t _at) const
{
return m_alloc.getHandleAt(_at);
}
uint16_t getNumHandles() const
{
return m_alloc.getNumHandles();
}
uint16_t getMaxHandles() const
{
return m_alloc.getMaxHandles();
}
uint16_t alloc()
{
uint16_t handle = m_alloc.alloc();
if (invalid != handle)
{
m_list.pushFront(handle);
}
return handle;
}
bool isValid(uint16_t _handle) const
{
return m_alloc.isValid(_handle);
}
void free(uint16_t _handle)
{
BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle);
m_list.remove(_handle);
m_alloc.free(_handle);
}
void touch(uint16_t _handle)
{
BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle);
m_list.remove(_handle);
m_list.pushFront(_handle);
}
uint16_t getFront() const
{
return m_list.getFront();
}
uint16_t getBack() const
{
return m_list.getBack();
}
uint16_t getNext(uint16_t _handle) const
{
return m_list.getNext(_handle);
}
uint16_t getPrev(uint16_t _handle) const
{
return m_list.getPrev(_handle);
}
void reset()
{
m_list.reset();
m_alloc.reset();
}
private:
HandleListT<MaxHandlesT> m_list;
HandleAllocT<MaxHandlesT> m_alloc;
};
} // namespace bx
#endif // BX_HANDLE_ALLOC_H_HEADER_GUARD

View File

@ -30,7 +30,19 @@ namespace bx
void add(const void* _data, int _len)
{
const uint8_t* data = (uint8_t*)_data;
if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN)
&& BX_UNLIKELY(!isPtrAligned(_data, 4) ) )
{
addUnaligned(_data, _len);
return;
}
addAligned(_data, _len);
}
void addAligned(const void* _data, int _len)
{
const uint8_t* data = (const uint8_t*)_data;
m_size += _len;
mixTail(data, _len);
@ -48,6 +60,27 @@ namespace bx
mixTail(data, _len);
}
void addUnaligned(const void* _data, int _len)
{
const uint8_t* data = (const uint8_t*)_data;
m_size += _len;
mixTail(data, _len);
while(_len >= 4)
{
uint32_t kk;
readUnaligned(data, kk);
mmix(m_hash, kk);
data += 4;
_len -= 4;
}
mixTail(data, _len);
}
template<typename Ty>
void add(Ty _value)
{
@ -67,6 +100,29 @@ namespace bx
}
private:
static void readUnaligned(const void* _data, uint32_t& _out)
{
const uint8_t* data = (const uint8_t*)_data;
if (BX_ENABLED(BX_CPU_ENDIAN_LITTLE) )
{
_out = 0
| data[0]<<24
| data[1]<<16
| data[2]<<8
| data[3]
;
}
else
{
_out = 0
| data[0]
| data[1]<<8
| data[2]<<16
| data[3]<<24
;
}
}
void mixTail(const uint8_t*& _data, int& _len)
{
while( _len && ((_len<4) || m_count) )

View File

@ -53,6 +53,8 @@
# define BX_ALLOW_UNUSED __attribute__( (unused) )
# define BX_FORCE_INLINE __extension__ static __inline __attribute__( (__always_inline__) )
# define BX_FUNCTION __PRETTY_FUNCTION__
# define BX_LIKELY(_x) __builtin_expect(!!(_x), 1)
# define BX_UNLIKELY(_x) __builtin_expect(!!(_x), 0)
# define BX_NO_INLINE __attribute__( (noinline) )
# define BX_NO_RETURN __attribute__( (noreturn) )
# define BX_NO_VTABLE
@ -61,11 +63,7 @@
# if BX_COMPILER_CLANG && (BX_PLATFORM_OSX || BX_PLATFORM_IOS)
# define BX_THREAD /* not supported right now */
# else
# if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 2)
# define BX_THREAD /* not supported right now */
# else
# define BX_THREAD __thread
# endif // __GNUC__ <= 4.2
# endif // BX_COMPILER_CLANG
# define BX_ATTRIBUTE(_x) __attribute__( (_x) )
# if BX_COMPILER_MSVC_COMPATIBLE
@ -76,6 +74,8 @@
# define BX_ALLOW_UNUSED
# define BX_FORCE_INLINE __forceinline
# define BX_FUNCTION __FUNCTION__
# define BX_LIKELY(_x) (_x)
# define BX_UNLIKELY(_x) (_x)
# define BX_NO_INLINE __declspec(noinline)
# define BX_NO_RETURN
# define BX_NO_VTABLE __declspec(novtable)

View File

@ -11,18 +11,23 @@
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT
# include <windows.h>
# include <psapi.h>
#elif BX_PLATFORM_ANDROID \
|| BX_PLATFORM_EMSCRIPTEN \
|| BX_PLATFORM_FREEBSD \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_NACL \
|| BX_PLATFORM_NETBSD \
|| BX_PLATFORM_OSX \
|| BX_PLATFORM_PS4 \
|| BX_PLATFORM_RPI
# include <sched.h> // sched_yield
# if BX_PLATFORM_FREEBSD || BX_PLATFORM_IOS || BX_PLATFORM_NACL || BX_PLATFORM_NETBSD || BX_PLATFORM_OSX
# if BX_PLATFORM_FREEBSD \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_NACL \
|| BX_PLATFORM_OSX \
|| BX_PLATFORM_PS4
# include <pthread.h> // mach_port_t
# endif // BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL
@ -30,15 +35,19 @@
# include <sys/nacl_syscalls.h> // nanosleep
# else
# include <time.h> // nanosleep
# if !BX_PLATFORM_PS4
# include <dlfcn.h> // dlopen, dlclose, dlsym
# endif // !BX_PLATFORM_PS4
# endif // BX_PLATFORM_NACL
# if BX_PLATFORM_LINUX || BX_PLATFORM_RPI
# if BX_PLATFORM_ANDROID
# include <malloc.h> // mallinfo
# elif BX_PLATFORM_LINUX || BX_PLATFORM_RPI
# include <unistd.h> // syscall
# include <sys/syscall.h>
# endif // BX_PLATFORM_LINUX || BX_PLATFORM_RPI
# if BX_PLATFORM_ANDROID
# elif BX_PLATFORM_OSX
# include <mach/mach.h> // mach_task_basic_info
# elif BX_PLATFORM_ANDROID
# include "debug.h" // getTid is not implemented...
# endif // BX_PLATFORM_ANDROID
#endif // BX_PLATFORM_
@ -94,7 +103,7 @@ namespace bx
return (pid_t)::syscall(SYS_gettid);
#elif BX_PLATFORM_IOS || BX_PLATFORM_OSX
return (mach_port_t)::pthread_mach_thread_np(pthread_self() );
#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_NACL || BX_PLATFORM_NETBSD
#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_NACL
// Casting __nc_basic_thread_data*... need better way to do this.
return *(uint32_t*)::pthread_self();
#else
@ -104,11 +113,60 @@ namespace bx
#endif //
}
inline size_t getProcessMemoryUsed()
{
#if BX_PLATFORM_ANDROID
struct mallinfo mi = mallinfo();
return mi.uordblks;
#elif BX_PLATFORM_LINUX
FILE* file = fopen("/proc/self/statm", "r");
if (NULL == file)
{
return 0;
}
long pages = 0;
int items = fscanf(file, "%*s%ld", &pages);
fclose(file);
return 1 == items
? pages * sysconf(_SC_PAGESIZE)
: 0
;
#elif BX_PLATFORM_OSX
mach_task_basic_info info;
mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
int result = task_info(mach_task_self()
, MACH_TASK_BASIC_INFO
, (task_info_t)&info
, &infoCount
);
if (KERN_SUCCESS != result)
{
return 0;
}
return info.resident_size;
#elif BX_PLATFORM_WINDOWS
PROCESS_MEMORY_COUNTERS pmc;
GetProcessMemoryInfo(GetCurrentProcess()
, &pmc
, sizeof(pmc)
);
return pmc.WorkingSetSize;
#else
return 0;
#endif // BX_PLATFORM_*
}
inline void* dlopen(const char* _filePath)
{
#if BX_PLATFORM_WINDOWS
return (void*)::LoadLibraryA(_filePath);
#elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT
#elif BX_PLATFORM_EMSCRIPTEN \
|| BX_PLATFORM_NACL \
|| BX_PLATFORM_PS4 \
|| BX_PLATFORM_WINRT
BX_UNUSED(_filePath);
return NULL;
#else
@ -120,7 +178,10 @@ namespace bx
{
#if BX_PLATFORM_WINDOWS
::FreeLibrary( (HMODULE)_handle);
#elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT
#elif BX_PLATFORM_EMSCRIPTEN \
|| BX_PLATFORM_NACL \
|| BX_PLATFORM_PS4 \
|| BX_PLATFORM_WINRT
BX_UNUSED(_handle);
#else
::dlclose(_handle);
@ -131,7 +192,10 @@ namespace bx
{
#if BX_PLATFORM_WINDOWS
return (void*)::GetProcAddress( (HMODULE)_handle, _symbol);
#elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT
#elif BX_PLATFORM_EMSCRIPTEN \
|| BX_PLATFORM_NACL \
|| BX_PLATFORM_PS4 \
|| BX_PLATFORM_WINRT
BX_UNUSED(_handle, _symbol);
return NULL;
#else
@ -143,7 +207,8 @@ namespace bx
{
#if BX_PLATFORM_WINDOWS
::SetEnvironmentVariableA(_name, _value);
#elif BX_PLATFORM_WINRT
#elif BX_PLATFORM_PS4 \
|| BX_PLATFORM_WINRT
BX_UNUSED(_name, _value);
#else
::setenv(_name, _value, 1);
@ -154,7 +219,8 @@ namespace bx
{
#if BX_PLATFORM_WINDOWS
::SetEnvironmentVariableA(_name, NULL);
#elif BX_PLATFORM_WINRT
#elif BX_PLATFORM_PS4 \
|| BX_PLATFORM_WINRT
BX_UNUSED(_name);
#else
::unsetenv(_name);
@ -163,7 +229,8 @@ namespace bx
inline int chdir(const char* _path)
{
#if BX_PLATFORM_WINRT
#if BX_PLATFORM_PS4 \
|| BX_PLATFORM_WINRT
BX_UNUSED(_path);
return -1;
#elif BX_COMPILER_MSVC_COMPATIBLE
@ -175,7 +242,8 @@ namespace bx
inline char* pwd(char* _buffer, uint32_t _size)
{
#if BX_PLATFORM_WINRT
#if BX_PLATFORM_PS4 \
|| BX_PLATFORM_WINRT
BX_UNUSED(_buffer, _size);
return NULL;
#elif BX_COMPILER_MSVC_COMPATIBLE

View File

@ -18,7 +18,6 @@
#define BX_PLATFORM_IOS 0
#define BX_PLATFORM_LINUX 0
#define BX_PLATFORM_NACL 0
#define BX_PLATFORM_NETBSD 0
#define BX_PLATFORM_OSX 0
#define BX_PLATFORM_PS4 0
#define BX_PLATFORM_QNX 0
@ -176,7 +175,7 @@
#elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
# undef BX_PLATFORM_OSX
# define BX_PLATFORM_OSX 1
#elif defined(EMSCRIPTEN)
#elif defined(__EMSCRIPTEN__)
# undef BX_PLATFORM_EMSCRIPTEN
# define BX_PLATFORM_EMSCRIPTEN 1
#elif defined(__ORBIS__)
@ -188,9 +187,6 @@
#elif defined(__FreeBSD__)
# undef BX_PLATFORM_FREEBSD
# define BX_PLATFORM_FREEBSD 1
#elif defined(__NetBSD__)
# undef BX_PLATFORM_NETBSD
# define BX_PLATFORM_NETBSD 1
#else
# error "BX_PLATFORM_* is not defined!"
#endif //
@ -202,9 +198,9 @@
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_NACL \
|| BX_PLATFORM_NETBSD \
|| BX_PLATFORM_OSX \
|| BX_PLATFORM_QNX \
|| BX_PLATFORM_PS4 \
|| BX_PLATFORM_RPI \
)
@ -255,8 +251,6 @@
#elif BX_PLATFORM_NACL
# define BX_PLATFORM_NAME "NaCl " \
BX_STRINGIZE(BX_PLATFORM_NACL)
#elif BX_PLATFORM_NETBSD
# define BX_PLATFORM_NAME "NetBSD"
#elif BX_PLATFORM_OSX
# define BX_PLATFORM_NAME "OSX"
#elif BX_PLATFORM_PS4

80
3rdparty/bx/include/bx/process.h vendored Normal file
View File

@ -0,0 +1,80 @@
/*
* Copyright 2010-2015 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#ifndef BX_PROCESS_H_HEADER_GUARD
#define BX_PROCESS_H_HEADER_GUARD
#include "string.h"
#include "uint32_t.h"
#if BX_PLATFORM_LINUX
# include <unistd.h>
#endif // BX_PLATFORM_LINUX
namespace bx
{
///
inline void* exec(const char* const* _argv)
{
#if BX_PLATFORM_LINUX
pid_t pid = fork();
if (0 == pid)
{
int result = execvp(_argv[0], const_cast<char *const*>(&_argv[1]) );
BX_UNUSED(result);
return NULL;
}
return (void*)uintptr_t(pid);
#elif BX_PLATFORM_WINDOWS
STARTUPINFO si;
memset(&si, 0, sizeof(STARTUPINFO) );
si.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(PROCESS_INFORMATION) );
int32_t total = 0;
for (uint32_t ii = 0; NULL != _argv[ii]; ++ii)
{
total += (int32_t)strlen(_argv[ii]) + 1;
}
char* temp = (char*)alloca(total);
int32_t len = 0;
for(uint32_t ii = 0; NULL != _argv[ii]; ++ii)
{
len += snprintf(&temp[len], bx::uint32_imax(0, total-len)
, "%s "
, _argv[ii]
);
}
bool ok = CreateProcessA(_argv[0]
, temp
, NULL
, NULL
, false
, 0
, NULL
, NULL
, &si
, &pi
);
if (ok)
{
return pi.hProcess;
}
return NULL;
#else
return NULL;
#endif // BX_PLATFORM_LINUX
}
} // namespace bx
#endif // BX_PROCESS_H_HEADER_GUARD

View File

@ -40,7 +40,7 @@ namespace bx
uint32_t consume(uint32_t _size) // consumer only
{
const uint32_t maxSize = distance(m_read, m_current);
const uint32_t sizeNoSign = uint32_and(_size, 0x7FFFFFFF);
const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff);
const uint32_t test = uint32_sub(sizeNoSign, maxSize);
const uint32_t size = uint32_sels(test, _size, maxSize);
const uint32_t advance = uint32_add(m_read, size);
@ -53,7 +53,7 @@ namespace bx
{
const uint32_t dist = distance(m_write, m_read)-1;
const uint32_t maxSize = uint32_sels(dist, m_size-1, dist);
const uint32_t sizeNoSign = uint32_and(_size, 0x7FFFFFFF);
const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff);
const uint32_t test = uint32_sub(sizeNoSign, maxSize);
const uint32_t size = uint32_sels(test, _size, maxSize);
const uint32_t advance = uint32_add(m_write, size);
@ -65,7 +65,7 @@ namespace bx
uint32_t commit(uint32_t _size) // producer only
{
const uint32_t maxSize = distance(m_current, m_write);
const uint32_t sizeNoSign = uint32_and(_size, 0x7FFFFFFF);
const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff);
const uint32_t test = uint32_sub(sizeNoSign, maxSize);
const uint32_t size = uint32_sels(test, _size, maxSize);
const uint32_t advance = uint32_add(m_current, size);
@ -124,7 +124,7 @@ namespace bx
uint32_t consume(uint32_t _size) // consumer only
{
const uint32_t maxSize = distance(m_read, m_current);
const uint32_t sizeNoSign = uint32_and(_size, 0x7FFFFFFF);
const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff);
const uint32_t test = uint32_sub(sizeNoSign, maxSize);
const uint32_t size = uint32_sels(test, _size, maxSize);
const uint32_t advance = uint32_add(m_read, size);
@ -137,7 +137,7 @@ namespace bx
{
const uint32_t dist = distance(m_write, m_read)-1;
const uint32_t maxSize = uint32_sels(dist, m_size-1, dist);
const uint32_t sizeNoSign = uint32_and(_size, 0x7FFFFFFF);
const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff);
const uint32_t test = uint32_sub(sizeNoSign, maxSize);
const uint32_t size = uint32_sels(test, _size, maxSize);
const uint32_t advance = uint32_add(m_write, size);
@ -149,7 +149,7 @@ namespace bx
uint32_t commit(uint32_t _size) // producer only
{
const uint32_t maxSize = distance(m_current, m_write);
const uint32_t sizeNoSign = uint32_and(_size, 0x7FFFFFFF);
const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff);
const uint32_t test = uint32_sub(sizeNoSign, maxSize);
const uint32_t size = uint32_sels(test, _size, maxSize);
const uint32_t advance = uint32_add(m_current, size);

View File

@ -113,24 +113,24 @@ namespace bx
return NULL;
}
/// Find substring in string. Case insensitive. Limit search to _size.
/// Find substring in string. Case insensitive. Limit search to _max.
inline const char* stristr(const char* _str, const char* _find, size_t _max)
{
const char* ptr = _str;
const size_t total = strlen(_str);
size_t len = _max < total ? _max : total;
size_t stringLen = strnlen(_str, _max);
const size_t findLen = strlen(_find);
for (const size_t searchLen = strlen(_find); len >= searchLen; ++ptr, --len)
for (; stringLen >= findLen; ++ptr, --stringLen)
{
// Find start of the string.
while (tolower(*ptr) != tolower(*_find) )
{
++ptr;
--len;
--stringLen;
// Search pattern lenght can't be longer than the string.
if (searchLen > len)
if (findLen > stringLen)
{
return NULL;
}

View File

@ -31,8 +31,9 @@ namespace bx
public:
Thread()
#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT
: m_handle(INVALID_HANDLE_VALUE)
, m_threadId(UINT32_MAX)
#elif BX_PLATFORM_POSIX
: m_handle(0)
#endif // BX_PLATFORM_
@ -52,7 +53,7 @@ namespace bx
}
}
void init(ThreadFn _fn, void* _userData = NULL, uint32_t _stackSize = 0)
void init(ThreadFn _fn, void* _userData = NULL, uint32_t _stackSize = 0, const char* _name = NULL)
{
BX_CHECK(!m_running, "Already running!");
@ -61,7 +62,7 @@ namespace bx
m_stackSize = _stackSize;
m_running = true;
#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
m_handle = CreateThread(NULL
, m_stackSize
, threadFunc
@ -102,12 +103,17 @@ namespace bx
#endif // BX_PLATFORM_
m_sem.wait();
if (NULL != _name)
{
setThreadName(_name);
}
}
void shutdown()
{
BX_CHECK(m_running, "Not running!");
#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
WaitForSingleObject(m_handle, INFINITE);
GetExitCodeThread(m_handle, (DWORD*)&m_exitCode);
CloseHandle(m_handle);
@ -139,14 +145,56 @@ namespace bx
return m_exitCode;
}
void setThreadName(const char* _name)
{
#if BX_PLATFORM_OSX || BX_PLATFORM_IOS
pthread_setname_np(_name);
#elif BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
pthread_setname_np(m_handle, _name);
#elif BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
# pragma pack(push, 8)
struct ThreadName
{
DWORD type;
LPCSTR name;
DWORD id;
DWORD flags;
};
# pragma pack(pop)
ThreadName tn;
tn.type = 0x1000;
tn.name = _name;
tn.id = m_threadId;
tn.flags = 0;
__try
{
RaiseException(0x406d1388
, 0
, sizeof(tn)/4
, reinterpret_cast<ULONG_PTR*>(&tn)
);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
#else
BX_UNUSED(_name);
#endif // BX_PLATFORM_
}
private:
int32_t entry()
{
#if BX_PLATFORM_WINDOWS
m_threadId = ::GetCurrentThreadId();
#endif // BX_PLATFORM_WINDOWS
m_sem.post();
return m_fn(m_userData);
}
#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT
static DWORD WINAPI threadFunc(LPVOID _arg)
{
Thread* thread = (Thread*)_arg;
@ -167,8 +215,9 @@ namespace bx
}
#endif // BX_PLATFORM_
#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT
HANDLE m_handle;
DWORD m_threadId;
#elif BX_PLATFORM_POSIX
pthread_t m_handle;
#endif // BX_PLATFORM_

View File

@ -652,8 +652,8 @@ namespace bx
inline uint64_t uint64_cntlz_ref(uint64_t _val)
{
return _val & UINT64_C(0xffffffff00000000)
? uint32_cntlz(uint32_t(_val>>32) ) + 32
: uint32_cntlz(uint32_t(_val) )
? uint32_cntlz(uint32_t(_val>>32) )
: uint32_cntlz(uint32_t(_val) ) + 32
;
}

View File

@ -0,0 +1 @@
#include <sys/signal.h>

View File

@ -42,7 +42,7 @@
#define __ecount(size)
#define __bcount(size)
#define __in
// #define __in // Conflicts with STL.
#define __in_ecount(size)
#define __in_bcount(size)
#define __in_z
@ -52,7 +52,7 @@
#define __in_ecount_nz(size)
#define __in_bcount_nz(size)
#define __in_xcount_opt(size)
#define __out
// #define __out // Conflicts with STL.
#define __out_ecount(size)
#define __out_bcount(size)
#define __out_ecount_part(size,length)
@ -246,6 +246,642 @@
#define __control_entrypoint(category)
#define __data_entrypoint(category)
#define _Always_(annos)
#define _Analysis_noreturn_
#define _Analysis_assume_(expr)
#define _At_(target, annos)
#define _At_buffer_(target, iter, bound, annos)
#define _COM_Outptr_
#define _COM_Outptr_opt_
#define _COM_Outptr_opt_result_maybenull_
#define _COM_Outptr_result_maybenull_
#define _Check_return_
#define _Const_
#define _Deref2_pre_readonly_
#define _Deref_in_bound_
#define _Deref_in_range_(lb,ub)
#define _Deref_inout_bound_
#define _Deref_inout_z_
#define _Deref_inout_z_bytecap_c_(size)
#define _Deref_inout_z_cap_c_(size)
#define _Deref_opt_out_
#define _Deref_opt_out_opt_
#define _Deref_opt_out_opt_z_
#define _Deref_opt_out_z_
#define _Deref_out_
#define _Deref_out_bound_
#define _Deref_out_opt_
#define _Deref_out_opt_z_
#define _Deref_out_range_(lb,ub)
#define _Deref_out_z_
#define _Deref_out_z_bytecap_c_(size)
#define _Deref_out_z_cap_c_(size)
#define _Deref_post_bytecap_(size)
#define _Deref_post_bytecap_c_(size)
#define _Deref_post_bytecap_x_(size)
#define _Deref_post_bytecount_(size)
#define _Deref_post_bytecount_c_(size)
#define _Deref_post_bytecount_x_(size)
#define _Deref_post_cap_(size)
#define _Deref_post_cap_c_(size)
#define _Deref_post_cap_x_(size)
#define _Deref_post_count_(size)
#define _Deref_post_count_c_(size)
#define _Deref_post_count_x_(size)
#define _Deref_post_maybenull_
#define _Deref_post_notnull_
#define _Deref_post_null_
#define _Deref_post_opt_bytecap_(size)
#define _Deref_post_opt_bytecap_c_(size)
#define _Deref_post_opt_bytecap_x_(size)
#define _Deref_post_opt_bytecount_(size)
#define _Deref_post_opt_bytecount_c_(size)
#define _Deref_post_opt_bytecount_x_(size)
#define _Deref_post_opt_cap_(size)
#define _Deref_post_opt_cap_c_(size)
#define _Deref_post_opt_cap_x_(size)
#define _Deref_post_opt_count_(size)
#define _Deref_post_opt_count_c_(size)
#define _Deref_post_opt_count_x_(size)
#define _Deref_post_opt_valid_
#define _Deref_post_opt_valid_bytecap_(size)
#define _Deref_post_opt_valid_bytecap_c_(size)
#define _Deref_post_opt_valid_bytecap_x_(size)
#define _Deref_post_opt_valid_cap_(size)
#define _Deref_post_opt_valid_cap_c_(size)
#define _Deref_post_opt_valid_cap_x_(size)
#define _Deref_post_opt_z_
#define _Deref_post_opt_z_bytecap_(size)
#define _Deref_post_opt_z_bytecap_c_(size)
#define _Deref_post_opt_z_bytecap_x_(size)
#define _Deref_post_opt_z_cap_(size)
#define _Deref_post_opt_z_cap_c_(size)
#define _Deref_post_opt_z_cap_x_(size)
#define _Deref_post_valid_
#define _Deref_post_valid_bytecap_(size)
#define _Deref_post_valid_bytecap_c_(size)
#define _Deref_post_valid_bytecap_x_(size)
#define _Deref_post_valid_cap_(size)
#define _Deref_post_valid_cap_c_(size)
#define _Deref_post_valid_cap_x_(size)
#define _Deref_post_z_
#define _Deref_post_z_bytecap_(size)
#define _Deref_post_z_bytecap_c_(size)
#define _Deref_post_z_bytecap_x_(size)
#define _Deref_post_z_cap_(size)
#define _Deref_post_z_cap_c_(size)
#define _Deref_post_z_cap_x_(size)
#define _Deref_pre_bytecap_(size)
#define _Deref_pre_bytecap_c_(size)
#define _Deref_pre_bytecap_x_(size)
#define _Deref_pre_bytecount_(size)
#define _Deref_pre_bytecount_c_(size)
#define _Deref_pre_bytecount_x_(size)
#define _Deref_pre_cap_(size)
#define _Deref_pre_cap_c_(size)
#define _Deref_pre_cap_x_(size)
#define _Deref_pre_count_(size)
#define _Deref_pre_count_c_(size)
#define _Deref_pre_count_x_(size)
#define _Deref_pre_invalid_
#define _Deref_pre_maybenull_
#define _Deref_pre_notnull_
#define _Deref_pre_null_
#define _Deref_pre_opt_bytecap_(size)
#define _Deref_pre_opt_bytecap_c_(size)
#define _Deref_pre_opt_bytecap_x_(size)
#define _Deref_pre_opt_bytecount_(size)
#define _Deref_pre_opt_bytecount_c_(size)
#define _Deref_pre_opt_bytecount_x_(size)
#define _Deref_pre_opt_cap_(size)
#define _Deref_pre_opt_cap_c_(size)
#define _Deref_pre_opt_cap_x_(size)
#define _Deref_pre_opt_count_(size)
#define _Deref_pre_opt_count_c_(size)
#define _Deref_pre_opt_count_x_(size)
#define _Deref_pre_opt_valid_
#define _Deref_pre_opt_valid_bytecap_(size)
#define _Deref_pre_opt_valid_bytecap_c_(size)
#define _Deref_pre_opt_valid_bytecap_x_(size)
#define _Deref_pre_opt_valid_cap_(size)
#define _Deref_pre_opt_valid_cap_c_(size)
#define _Deref_pre_opt_valid_cap_x_(size)
#define _Deref_pre_opt_z_
#define _Deref_pre_opt_z_bytecap_(size)
#define _Deref_pre_opt_z_bytecap_c_(size)
#define _Deref_pre_opt_z_bytecap_x_(size)
#define _Deref_pre_opt_z_cap_(size)
#define _Deref_pre_opt_z_cap_c_(size)
#define _Deref_pre_opt_z_cap_x_(size)
#define _Deref_pre_readonly_
#define _Deref_pre_valid_
#define _Deref_pre_valid_bytecap_(size)
#define _Deref_pre_valid_bytecap_c_(size)
#define _Deref_pre_valid_bytecap_x_(size)
#define _Deref_pre_valid_cap_(size)
#define _Deref_pre_valid_cap_c_(size)
#define _Deref_pre_valid_cap_x_(size)
#define _Deref_pre_writeonly_
#define _Deref_pre_z_
#define _Deref_pre_z_bytecap_(size)
#define _Deref_pre_z_bytecap_c_(size)
#define _Deref_pre_z_bytecap_x_(size)
#define _Deref_pre_z_cap_(size)
#define _Deref_pre_z_cap_c_(size)
#define _Deref_pre_z_cap_x_(size)
#define _Deref_prepost_bytecap_(size)
#define _Deref_prepost_bytecap_x_(size)
#define _Deref_prepost_bytecount_(size)
#define _Deref_prepost_bytecount_x_(size)
#define _Deref_prepost_cap_(size)
#define _Deref_prepost_cap_x_(size)
#define _Deref_prepost_count_(size)
#define _Deref_prepost_count_x_(size)
#define _Deref_prepost_opt_bytecap_(size)
#define _Deref_prepost_opt_bytecap_x_(size)
#define _Deref_prepost_opt_bytecount_(size)
#define _Deref_prepost_opt_bytecount_x_(size)
#define _Deref_prepost_opt_cap_(size)
#define _Deref_prepost_opt_cap_x_(size)
#define _Deref_prepost_opt_count_(size)
#define _Deref_prepost_opt_count_x_(size)
#define _Deref_prepost_opt_valid_
#define _Deref_prepost_opt_valid_bytecap_(size)
#define _Deref_prepost_opt_valid_bytecap_x_(size)
#define _Deref_prepost_opt_valid_cap_(size)
#define _Deref_prepost_opt_valid_cap_x_(size)
#define _Deref_prepost_opt_z_
#define _Deref_prepost_opt_z_bytecap_(size)
#define _Deref_prepost_opt_z_cap_(size)
#define _Deref_prepost_valid_
#define _Deref_prepost_valid_bytecap_(size)
#define _Deref_prepost_valid_bytecap_x_(size)
#define _Deref_prepost_valid_cap_(size)
#define _Deref_prepost_valid_cap_x_(size)
#define _Deref_prepost_z_
#define _Deref_prepost_z_bytecap_(size)
#define _Deref_prepost_z_cap_(size)
#define _Deref_ret_bound_
#define _Deref_ret_opt_z_
#define _Deref_ret_range_(lb,ub)
#define _Deref_ret_z_
#define _Field_range_(min,max)
#define _Field_size_(size)
#define _Field_size_bytes_(size)
#define _Field_size_bytes_full_(size)
#define _Field_size_bytes_full_opt_(size)
#define _Field_size_bytes_opt_(size)
#define _Field_size_bytes_part_(size, count)
#define _Field_size_bytes_part_opt_(size, count)
#define _Field_size_full_(size)
#define _Field_size_full_opt_(size)
#define _Field_size_opt_(size)
#define _Field_size_part_(size, count)
#define _Field_size_part_opt_(size, count)
#define _Field_z_
#define _Function_class_(x)
#define _Group_(annos)
#define _In_
#define _In_bound_
#define _In_bytecount_(size)
#define _In_bytecount_c_(size)
#define _In_bytecount_x_(size)
#define _In_count_(size)
#define _In_count_c_(size)
#define _In_count_x_(size)
#define _In_defensive_(annotes)
#define _In_opt_
#define _In_opt_bytecount_(size)
#define _In_opt_bytecount_c_(size)
#define _In_opt_bytecount_x_(size)
#define _In_opt_count_(size)
#define _In_opt_count_c_(size)
#define _In_opt_count_x_(size)
#define _In_opt_ptrdiff_count_(size)
#define _In_opt_z_
#define _In_opt_z_bytecount_(size)
#define _In_opt_z_bytecount_c_(size)
#define _In_opt_z_count_(size)
#define _In_opt_z_count_c_(size)
#define _In_ptrdiff_count_(size)
#define _In_range_(lb,ub)
#define _In_reads_(size)
#define _In_reads_bytes_(size)
#define _In_reads_bytes_opt_(size)
#define _In_reads_opt_(size)
#define _In_reads_opt_z_(size)
#define _In_reads_or_z_(size)
#define _In_reads_to_ptr_(ptr)
#define _In_reads_to_ptr_opt_(ptr)
#define _In_reads_to_ptr_opt_z_(ptr)
#define _In_reads_to_ptr_z_(ptr)
#define _In_reads_z_(size)
#define _In_z_
#define _In_z_bytecount_(size)
#define _In_z_bytecount_c_(size)
#define _In_z_count_(size)
#define _In_z_count_c_(size)
#define _Inout_
#define _Inout_bytecap_(size)
#define _Inout_bytecap_c_(size)
#define _Inout_bytecap_x_(size)
#define _Inout_bytecount_(size)
#define _Inout_bytecount_c_(size)
#define _Inout_bytecount_x_(size)
#define _Inout_cap_(size)
#define _Inout_cap_c_(size)
#define _Inout_cap_x_(size)
#define _Inout_count_(size)
#define _Inout_count_c_(size)
#define _Inout_count_x_(size)
#define _Inout_defensive_(annotes)
#define _Inout_opt_
#define _Inout_opt_bytecap_(size)
#define _Inout_opt_bytecap_c_(size)
#define _Inout_opt_bytecap_x_(size)
#define _Inout_opt_bytecount_(size)
#define _Inout_opt_bytecount_c_(size)
#define _Inout_opt_bytecount_x_(size)
#define _Inout_opt_cap_(size)
#define _Inout_opt_cap_c_(size)
#define _Inout_opt_cap_x_(size)
#define _Inout_opt_count_(size)
#define _Inout_opt_count_c_(size)
#define _Inout_opt_count_x_(size)
#define _Inout_opt_ptrdiff_count_(size)
#define _Inout_opt_z_
#define _Inout_opt_z_bytecap_(size)
#define _Inout_opt_z_bytecap_c_(size)
#define _Inout_opt_z_bytecap_x_(size)
#define _Inout_opt_z_bytecount_(size)
#define _Inout_opt_z_bytecount_c_(size)
#define _Inout_opt_z_cap_(size)
#define _Inout_opt_z_cap_c_(size)
#define _Inout_opt_z_cap_x_(size)
#define _Inout_opt_z_count_(size)
#define _Inout_opt_z_count_c_(size)
#define _Inout_ptrdiff_count_(size)
#define _Inout_updates_(size)
#define _Inout_updates_all_(size)
#define _Inout_updates_all_opt_(size)
#define _Inout_updates_bytes_(size)
#define _Inout_updates_bytes_all_(size)
#define _Inout_updates_bytes_all_opt_(size)
#define _Inout_updates_bytes_opt_(size)
#define _Inout_updates_bytes_to_(size,count)
#define _Inout_updates_bytes_to_opt_(size,count)
#define _Inout_updates_opt_(size)
#define _Inout_updates_opt_z_(size)
#define _Inout_updates_to_(size,count)
#define _Inout_updates_to_opt_(size,count)
#define _Inout_updates_z_(size)
#define _Inout_z_
#define _Inout_z_bytecap_(size)
#define _Inout_z_bytecap_c_(size)
#define _Inout_z_bytecap_x_(size)
#define _Inout_z_bytecount_(size)
#define _Inout_z_bytecount_c_(size)
#define _Inout_z_cap_(size)
#define _Inout_z_cap_c_(size)
#define _Inout_z_cap_x_(size)
#define _Inout_z_count_(size)
#define _Inout_z_count_c_(size)
#define _Interlocked_operand_
#define _Literal_
#define _Maybe_raises_SEH_exception
#define _Maybe_raises_SEH_exception_
#define _Maybenull_
#define _Maybevalid_
#define _Must_inspect_result_
#define _Notliteral_
#define _Notnull_
#define _Notref_
#define _Notvalid_
#define _NullNull_terminated_
#define _Null_
#define _Null_terminated_
#define _On_failure_(annos)
#define _Out_
#define _Out_bound_
#define _Out_bytecap_(size)
#define _Out_bytecap_c_(size)
#define _Out_bytecap_post_bytecount_(cap,count)
#define _Out_bytecap_x_(size)
#define _Out_bytecapcount_(capcount)
#define _Out_bytecapcount_x_(capcount)
#define _Out_cap_(size)
#define _Out_cap_c_(size)
#define _Out_cap_m_(mult,size)
#define _Out_cap_post_count_(cap,count)
#define _Out_cap_x_(size)
#define _Out_capcount_(capcount)
#define _Out_capcount_x_(capcount)
#define _Out_defensive_(annotes)
#define _Out_opt_
#define _Out_opt_bytecap_(size)
#define _Out_opt_bytecap_c_(size)
#define _Out_opt_bytecap_post_bytecount_(cap,count)
#define _Out_opt_bytecap_x_(size)
#define _Out_opt_bytecapcount_(capcount)
#define _Out_opt_bytecapcount_x_(capcount)
#define _Out_opt_cap_(size)
#define _Out_opt_cap_c_(size)
#define _Out_opt_cap_m_(mult,size)
#define _Out_opt_cap_post_count_(cap,count)
#define _Out_opt_cap_x_(size)
#define _Out_opt_capcount_(capcount)
#define _Out_opt_capcount_x_(capcount)
#define _Out_opt_ptrdiff_cap_(size)
#define _Out_opt_z_bytecap_(size)
#define _Out_opt_z_bytecap_c_(size)
#define _Out_opt_z_bytecap_post_bytecount_(cap,count)
#define _Out_opt_z_bytecap_x_(size)
#define _Out_opt_z_bytecapcount_(capcount)
#define _Out_opt_z_cap_(size)
#define _Out_opt_z_cap_c_(size)
#define _Out_opt_z_cap_m_(mult,size)
#define _Out_opt_z_cap_post_count_(cap,count)
#define _Out_opt_z_cap_x_(size)
#define _Out_opt_z_capcount_(capcount)
#define _Out_ptrdiff_cap_(size)
#define _Out_range_(lb,ub)
#define _Out_writes_(size)
#define _Out_writes_all_(size)
#define _Out_writes_all_opt_(size)
#define _Out_writes_bytes_(size)
#define _Out_writes_bytes_all_(size)
#define _Out_writes_bytes_all_opt_(size)
#define _Out_writes_bytes_opt_(size)
#define _Out_writes_bytes_to_(size,count)
#define _Out_writes_bytes_to_opt_(size,count)
#define _Out_writes_opt_(size)
#define _Out_writes_opt_z_(size)
#define _Out_writes_to_(size,count)
#define _Out_writes_to_opt_(size,count)
#define _Out_writes_to_ptr_(ptr)
#define _Out_writes_to_ptr_opt_(ptr)
#define _Out_writes_to_ptr_opt_z_(ptr)
#define _Out_writes_to_ptr_z_(ptr)
#define _Out_writes_z_(size)
#define _Out_z_bytecap_(size)
#define _Out_z_bytecap_c_(size)
#define _Out_z_bytecap_post_bytecount_(cap,count)
#define _Out_z_bytecap_x_(size)
#define _Out_z_bytecapcount_(capcount)
#define _Out_z_cap_(size)
#define _Out_z_cap_c_(size)
#define _Out_z_cap_m_(mult,size)
#define _Out_z_cap_post_count_(cap,count)
#define _Out_z_cap_x_(size)
#define _Out_z_capcount_(capcount)
#define _Outptr_
#define _Outptr_opt_
#define _Outptr_opt_result_buffer_(size)
#define _Outptr_opt_result_buffer_all_(size)
#define _Outptr_opt_result_buffer_all_maybenull_(size)
#define _Outptr_opt_result_buffer_maybenull_(size)
#define _Outptr_opt_result_buffer_to_(size, count)
#define _Outptr_opt_result_buffer_to_maybenull_(size, count)
#define _Outptr_opt_result_bytebuffer_(size)
#define _Outptr_opt_result_bytebuffer_all_(size)
#define _Outptr_opt_result_bytebuffer_all_maybenull_(size)
#define _Outptr_opt_result_bytebuffer_maybenull_(size)
#define _Outptr_opt_result_bytebuffer_to_(size, count)
#define _Outptr_opt_result_bytebuffer_to_maybenull_(size, count)
#define _Outptr_opt_result_maybenull_
#define _Outptr_opt_result_maybenull_z_
#define _Outptr_opt_result_nullonfailure_
#define _Outptr_opt_result_z_
#define _Outptr_result_buffer_(size)
#define _Outptr_result_buffer_all_(size)
#define _Outptr_result_buffer_all_maybenull_(size)
#define _Outptr_result_buffer_maybenull_(size)
#define _Outptr_result_buffer_to_(size, count)
#define _Outptr_result_buffer_to_maybenull_(size, count)
#define _Outptr_result_bytebuffer_(size)
#define _Outptr_result_bytebuffer_all_(size)
#define _Outptr_result_bytebuffer_all_maybenull_(size)
#define _Outptr_result_bytebuffer_maybenull_(size)
#define _Outptr_result_bytebuffer_to_(size, count)
#define _Outptr_result_bytebuffer_to_maybenull_(size, count)
#define _Outptr_result_maybenull_
#define _Outptr_result_maybenull_z_
#define _Outptr_result_nullonfailure_
#define _Outptr_result_z_
#define _Outref_
#define _Outref_result_buffer_(size)
#define _Outref_result_buffer_all_(size)
#define _Outref_result_buffer_all_maybenull_(size)
#define _Outref_result_buffer_maybenull_(size)
#define _Outref_result_buffer_to_(size, count)
#define _Outref_result_buffer_to_maybenull_(size, count)
#define _Outref_result_bytebuffer_(size)
#define _Outref_result_bytebuffer_all_(size)
#define _Outref_result_bytebuffer_all_maybenull_(size)
#define _Outref_result_bytebuffer_maybenull_(size)
#define _Outref_result_bytebuffer_to_(size, count)
#define _Outref_result_bytebuffer_to_maybenull_(size, count)
#define _Outref_result_maybenull_
#define _Outref_result_nullonfailure_
#define _Points_to_data_
#define _Post_
#define _Post_bytecap_(size)
#define _Post_bytecount_(size)
#define _Post_bytecount_c_(size)
#define _Post_bytecount_x_(size)
#define _Post_cap_(size)
#define _Post_count_(size)
#define _Post_count_c_(size)
#define _Post_count_x_(size)
#define _Post_defensive_
#define _Post_equal_to_(expr)
#define _Post_invalid_
#define _Post_maybenull_
#define _Post_maybez_
#define _Post_notnull_
#define _Post_null_
#define _Post_ptr_invalid_
#define _Post_readable_byte_size_(size)
#define _Post_readable_size_(size)
#define _Post_satisfies_(cond)
#define _Post_valid_
#define _Post_writable_byte_size_(size)
#define _Post_writable_size_(size)
#define _Post_z_
#define _Post_z_bytecount_(size)
#define _Post_z_bytecount_c_(size)
#define _Post_z_bytecount_x_(size)
#define _Post_z_count_(size)
#define _Post_z_count_c_(size)
#define _Post_z_count_x_(size)
#define _Pre_
#define _Pre_bytecap_(size)
#define _Pre_bytecap_c_(size)
#define _Pre_bytecap_x_(size)
#define _Pre_bytecount_(size)
#define _Pre_bytecount_c_(size)
#define _Pre_bytecount_x_(size)
#define _Pre_cap_(size)
#define _Pre_cap_c_(size)
#define _Pre_cap_c_one_
#define _Pre_cap_for_(param)
#define _Pre_cap_m_(mult,size)
#define _Pre_cap_x_(size)
#define _Pre_count_(size)
#define _Pre_count_c_(size)
#define _Pre_count_x_(size)
#define _Pre_defensive_
#define _Pre_equal_to_(expr)
#define _Pre_invalid_
#define _Pre_maybenull_
#define _Pre_notnull_
#define _Pre_null_
#define _Pre_opt_bytecap_(size)
#define _Pre_opt_bytecap_c_(size)
#define _Pre_opt_bytecap_x_(size)
#define _Pre_opt_bytecount_(size)
#define _Pre_opt_bytecount_c_(size)
#define _Pre_opt_bytecount_x_(size)
#define _Pre_opt_cap_(size)
#define _Pre_opt_cap_c_(size)
#define _Pre_opt_cap_c_one_
#define _Pre_opt_cap_for_(param)
#define _Pre_opt_cap_m_(mult,size)
#define _Pre_opt_cap_x_(size)
#define _Pre_opt_count_(size)
#define _Pre_opt_count_c_(size)
#define _Pre_opt_count_x_(size)
#define _Pre_opt_ptrdiff_cap_(ptr)
#define _Pre_opt_ptrdiff_count_(ptr)
#define _Pre_opt_valid_
#define _Pre_opt_valid_bytecap_(size)
#define _Pre_opt_valid_bytecap_c_(size)
#define _Pre_opt_valid_bytecap_x_(size)
#define _Pre_opt_valid_cap_(size)
#define _Pre_opt_valid_cap_c_(size)
#define _Pre_opt_valid_cap_x_(size)
#define _Pre_opt_z_
#define _Pre_opt_z_bytecap_(size)
#define _Pre_opt_z_bytecap_c_(size)
#define _Pre_opt_z_bytecap_x_(size)
#define _Pre_opt_z_cap_(size)
#define _Pre_opt_z_cap_c_(size)
#define _Pre_opt_z_cap_x_(size)
#define _Pre_ptrdiff_cap_(ptr)
#define _Pre_ptrdiff_count_(ptr)
#define _Pre_readable_byte_size_(size)
#define _Pre_readable_size_(size)
#define _Pre_readonly_
#define _Pre_satisfies_(cond)
#define _Pre_valid_
#define _Pre_valid_bytecap_(size)
#define _Pre_valid_bytecap_c_(size)
#define _Pre_valid_bytecap_x_(size)
#define _Pre_valid_cap_(size)
#define _Pre_valid_cap_c_(size)
#define _Pre_valid_cap_x_(size)
#define _Pre_writable_byte_size_(size)
#define _Pre_writable_size_(size)
#define _Pre_writeonly_
#define _Pre_z_
#define _Pre_z_bytecap_(size)
#define _Pre_z_bytecap_c_(size)
#define _Pre_z_bytecap_x_(size)
#define _Pre_z_cap_(size)
#define _Pre_z_cap_c_(size)
#define _Pre_z_cap_x_(size)
#define _Prepost_bytecount_(size)
#define _Prepost_bytecount_c_(size)
#define _Prepost_bytecount_x_(size)
#define _Prepost_count_(size)
#define _Prepost_count_c_(size)
#define _Prepost_count_x_(size)
#define _Prepost_opt_bytecount_(size)
#define _Prepost_opt_bytecount_c_(size)
#define _Prepost_opt_bytecount_x_(size)
#define _Prepost_opt_count_(size)
#define _Prepost_opt_count_c_(size)
#define _Prepost_opt_count_x_(size)
#define _Prepost_opt_valid_
#define _Prepost_opt_z_
#define _Prepost_valid_
#define _Prepost_z_
#define _Printf_format_string_
#define _Raises_SEH_exception_
#define _Readable_bytes_(size)
#define _Readable_elements_(size)
#define _Reserved_
#define _Result_nullonfailure_
#define _Result_zeroonfailure_
#define _Ret_
#define _Ret_bound_
#define _Ret_bytecap_(size)
#define _Ret_bytecap_c_(size)
#define _Ret_bytecap_x_(size)
#define _Ret_bytecount_(size)
#define _Ret_bytecount_c_(size)
#define _Ret_bytecount_x_(size)
#define _Ret_cap_(size)
#define _Ret_cap_c_(size)
#define _Ret_cap_x_(size)
#define _Ret_count_(size)
#define _Ret_count_c_(size)
#define _Ret_count_x_(size)
#define _Ret_maybenull_
#define _Ret_maybenull_z_
#define _Ret_notnull_
#define _Ret_null_
#define _Ret_opt_
#define _Ret_opt_bytecap_(size)
#define _Ret_opt_bytecap_c_(size)
#define _Ret_opt_bytecap_x_(size)
#define _Ret_opt_bytecount_(size)
#define _Ret_opt_bytecount_c_(size)
#define _Ret_opt_bytecount_x_(size)
#define _Ret_opt_cap_(size)
#define _Ret_opt_cap_c_(size)
#define _Ret_opt_cap_x_(size)
#define _Ret_opt_count_(size)
#define _Ret_opt_count_c_(size)
#define _Ret_opt_count_x_(size)
#define _Ret_opt_valid_
#define _Ret_opt_z_
#define _Ret_opt_z_bytecap_(size)
#define _Ret_opt_z_bytecount_(size)
#define _Ret_opt_z_cap_(size)
#define _Ret_opt_z_count_(size)
#define _Ret_range_(lb,ub)
#define _Ret_valid_
#define _Ret_writes_(size)
#define _Ret_writes_bytes_(size)
#define _Ret_writes_bytes_maybenull_(size)
#define _Ret_writes_bytes_to_(size,count)
#define _Ret_writes_bytes_to_maybenull_(size,count)
#define _Ret_writes_maybenull_(size)
#define _Ret_writes_maybenull_z_(size)
#define _Ret_writes_to_(size,count)
#define _Ret_writes_to_maybenull_(size,count)
#define _Ret_writes_z_(size)
#define _Ret_z_
#define _Ret_z_bytecap_(size)
#define _Ret_z_bytecount_(size)
#define _Ret_z_cap_(size)
#define _Ret_z_count_(size)
#define _Return_type_success_(expr)
#define _Scanf_format_string_
#define _Scanf_s_format_string_
#define _Struct_size_bytes_(size)
#define _Success_(expr)
#define _Unchanged_(e)
#define _Use_decl_annotations_
#define _Valid_
#define _When_(expr, annos)
#define _Writable_bytes_(size)
#define _Writable_elements_(size)
#define __inner_callback
#define __inner_exceptthat
#define __inner_typefix(ctype)
#ifndef __fallthrough
# define __fallthrough __inner_fallthrough
#endif

View File

@ -1,5 +1,5 @@
/*-
* Copyright 2012 Matthew Endsley
* Copyright 2012-1015 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
@ -54,6 +54,18 @@ namespace tinystl {
buffer_destroy_range_traits(first, last, pod_traits<T>());
}
template<typename T>
static inline void buffer_fill_urange_traits(T* first, T* last, pod_traits<T, false>) {
for (; first < last; ++first)
new(placeholder(), first) T();
}
template<typename T>
static inline void buffer_fill_urange_traits(T* first, T* last, pod_traits<T, true>) {
for (; first < last; ++first)
*first = T();
}
template<typename T>
static inline void buffer_fill_urange_traits(T* first, T* last, const T& value, pod_traits<T, false>) {
for (; first < last; ++first)
@ -105,6 +117,11 @@ namespace tinystl {
buffer_bmove_urange_traits(dest, first, last, pod_traits<T>());
}
template<typename T>
static inline void buffer_fill_urange(T* first, T* last) {
buffer_fill_urange_traits(first, last, pod_traits<T>());
}
template<typename T>
static inline void buffer_fill_urange(T* first, T* last, const T& value) {
buffer_fill_urange_traits(first, last, value, pod_traits<T>());
@ -137,6 +154,15 @@ namespace tinystl {
b->capacity = newfirst + capacity;
}
template<typename T, typename Alloc>
static inline void buffer_resize(buffer<T, Alloc>* b, size_t size) {
buffer_reserve(b, size);
buffer_fill_urange(b->last, b->first + size);
buffer_destroy_range(b->first + size, b->last);
b->last = b->first + size;
}
template<typename T, typename Alloc>
static inline void buffer_resize(buffer<T, Alloc>* b, size_t size, const T& value) {
buffer_reserve(b, size);
@ -169,22 +195,34 @@ namespace tinystl {
}
template<typename T, typename Alloc>
static inline void buffer_insert(buffer<T, Alloc>* b, T* where, const T* first, const T* last) {
static inline T* buffer_insert_common(buffer<T, Alloc>* b, T* where, size_t count) {
const size_t offset = (size_t)(where - b->first);
const size_t newsize = (size_t)((b->last - b->first) + (last - first));
const size_t newsize = (size_t)((b->last - b->first) + count);
if (b->first + newsize > b->capacity)
buffer_reserve(b, (newsize * 3) / 2);
where = b->first + offset;
const size_t count = (size_t)(last - first);
if (where != b->last)
buffer_bmove_urange(where + count, where, b->last);
b->last = b->first + newsize;
return where;
}
template<typename T, typename Alloc, typename Param>
static inline void buffer_insert(buffer<T, Alloc>* b, T* where, const Param* first, const Param* last) {
where = buffer_insert_common(b, where, last - first);
for (; first != last; ++first, ++where)
new(placeholder(), where) T(*first);
}
b->last = b->first + newsize;
template<typename T, typename Alloc>
static inline void buffer_insert(buffer<T, Alloc>* b, T* where, size_t count) {
where = buffer_insert_common(b, where, count);
for (size_t i = 0; i < count; ++i)
new(placeholder(), where) T();
}
template<typename T, typename Alloc>

View File

@ -1,5 +1,5 @@
/*-
* Copyright 2012 Matthew Endsley
* Copyright 2012-1015 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
@ -56,6 +56,8 @@ namespace tinystl {
T& operator[](size_t idx);
const T& operator[](size_t idx) const;
const T& front() const;
T& front();
const T& back() const;
T& back();
@ -67,6 +69,10 @@ namespace tinystl {
void push_back(const T& t);
void pop_back();
void emplace_back();
template<typename Param>
void emplace_back(const Param& param);
void shrink_to_fit();
void swap(vector& other);
@ -81,9 +87,13 @@ namespace tinystl {
const_iterator begin() const;
const_iterator end() const;
void insert(iterator where);
void insert(iterator where, const T& value);
void insert(iterator where, const T* first, const T* last);
template<typename Param>
void emplace(iterator where, const Param& param);
iterator erase(iterator where);
iterator erase(iterator first, iterator last);
@ -109,7 +119,7 @@ namespace tinystl {
template<typename T, typename Alloc>
inline vector<T, Alloc>::vector(size_t _size) {
buffer_init(&m_buffer);
buffer_resize(&m_buffer, _size, T());
buffer_resize(&m_buffer, _size);
}
template<typename T, typename Alloc>
@ -176,6 +186,16 @@ namespace tinystl {
return m_buffer.first[idx];
}
template<typename T, typename Alloc>
inline const T& vector<T, Alloc>::front() const {
return m_buffer.first[0];
}
template<typename T, typename Alloc>
inline T& vector<T, Alloc>::front() {
return m_buffer.first[0];
}
template<typename T, typename Alloc>
inline const T& vector<T, Alloc>::back() const {
return m_buffer.last[-1];
@ -188,7 +208,7 @@ namespace tinystl {
template<typename T, typename Alloc>
inline void vector<T, Alloc>::resize(size_t _size) {
buffer_resize(&m_buffer, _size, T());
buffer_resize(&m_buffer, _size);
}
template<typename T, typename Alloc>
@ -211,6 +231,19 @@ namespace tinystl {
buffer_insert(&m_buffer, m_buffer.last, &t, &t + 1);
}
template<typename T, typename Alloc>
inline void vector<T, Alloc>::emplace_back()
{
buffer_insert(&m_buffer, m_buffer.last, 1);
}
template<typename T, typename Alloc>
template<typename Param>
inline void vector<T, Alloc>::emplace_back(const Param& param)
{
buffer_insert(&m_buffer, m_buffer.last, &param, &param + 1);
}
template<typename T, typename Alloc>
inline void vector<T, Alloc>::pop_back() {
buffer_erase(&m_buffer, m_buffer.last - 1, m_buffer.last);
@ -246,6 +279,11 @@ namespace tinystl {
return m_buffer.last;
}
template<typename T, typename Alloc>
inline void vector<T, Alloc>::insert(iterator where) {
buffer_insert(&m_buffer, where, 1);
}
template<typename T, typename Alloc>
inline void vector<T, Alloc>::insert(iterator where, const T& value) {
buffer_insert(&m_buffer, where, &value, &value + 1);
@ -275,6 +313,12 @@ namespace tinystl {
inline typename vector<T, Alloc>::iterator vector<T, Alloc>::erase_unordered(iterator first, iterator last) {
return buffer_erase_unordered(&m_buffer, first, last);
}
template<typename T, typename Alloc>
template<typename Param>
void vector<T, Alloc>::emplace(iterator where, const Param& param) {
buffer_insert(&m_buffer, where, &param, &param + 1);
}
}
#endif

View File

@ -36,7 +36,6 @@ dofile "unittest++.lua"
dofile "bin2c.lua"
project "bx.test"
uuid "8a653da8-23d6-11e3-acb4-887628d43830"
kind "ConsoleApp"
debugdir (path.join(BX_DIR, "tests"))

View File

@ -29,6 +29,7 @@ function toolchain(_buildDir, _libDir)
{ "nacl-arm", "Native Client - ARM" },
{ "osx", "OSX" },
{ "pnacl", "Native Client - PNaCl" },
{ "ps4", "PS4" },
{ "qnx-arm", "QNX/Blackberry - ARM" },
{ "rpi", "RaspberryPi" },
},
@ -47,7 +48,7 @@ function toolchain(_buildDir, _libDir)
{ "winphone8", "Windows Phone 8.0" },
{ "winphone81", "Windows Phone 8.1" },
{ "winstore81", "Windows Store 8.1" },
{ "winstore82", "Universal Windows App" }
{ "winstore82", "Universal Windows App" },
},
}
@ -257,6 +258,19 @@ function toolchain(_buildDir, _libDir)
premake.gcc.ar = naclToolchain .. "ar"
location (path.join(_buildDir, "projects", _ACTION .. "-pnacl"))
elseif "ps4" == _OPTIONS["gcc"] then
if not os.getenv("PS4_SDK_ROOT") then
print("Set PS4_SDK_ROOT enviroment variables.")
end
ps4Toolchain = "$(PS4_SDK_ROOT)/host_tools/bin/orbis-"
premake.gcc.cc = ps4Toolchain .. "clang"
premake.gcc.cxx = ps4Toolchain .. "clang++"
premake.gcc.ar = ps4Toolchain .. "ar"
location (path.join(_buildDir, "projects", _ACTION .. "-ps4"))
elseif "qnx-arm" == _OPTIONS["gcc"] then
if not os.getenv("QNX_HOST") then
@ -799,6 +813,10 @@ function toolchain(_buildDir, _libDir)
"-m64",
}
configuration { "osx", "Universal" }
targetdir (path.join(_buildDir, "osx_universal/bin"))
objdir (path.join(_buildDir, "osx_universal/bin"))
configuration { "osx" }
buildoptions {
"-Wfatal-errors",
@ -855,6 +873,23 @@ function toolchain(_buildDir, _libDir)
"--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator" ..iosPlatform .. ".sdk",
}
configuration { "ps4" }
targetdir (path.join(_buildDir, "ps4/bin"))
objdir (path.join(_buildDir, "ps4/obj"))
libdirs { path.join(_libDir, "lib/ps4") }
includedirs {
path.join(bxDir, "include/compat/freebsd"),
"$(PS4_SDK_ROOT)/target/include",
"$(PS4_SDK_ROOT)/target/include_common",
}
buildoptions {
}
buildoptions_cpp {
"-std=c++0x",
}
linkoptions {
}
configuration { "qnx-arm" }
targetdir (path.join(_buildDir, "qnx-arm/bin"))
objdir (path.join(_buildDir, "qnx-arm/obj"))
@ -951,8 +986,14 @@ function strip()
configuration { "asmjs" }
postbuildcommands {
"$(SILENT) echo Running asmjs finalize.",
"$(SILENT) $(EMSCRIPTEN)/emcc -O2 -s TOTAL_MEMORY=268435456 \"$(TARGET)\" -o \"$(TARGET)\".html"
-- ALLOW_MEMORY_GROWTH
"$(SILENT) $(EMSCRIPTEN)/emcc -O2 "
-- .. "-s EMTERPRETIFY=1 "
-- .. "-s EMTERPRETIFY_ASYNC=1 "
.. "-s TOTAL_MEMORY=268435456 "
-- .. "-s ALLOW_MEMORY_GROWTH=1 "
.. "--memory-init-file 1 "
.. "\"$(TARGET)\" -o \"$(TARGET)\".html "
-- .. "--preload-file ../../../examples/runtime@/"
}
configuration {} -- reset configuration

View File

@ -4,7 +4,6 @@
--
project "UnitTest++"
uuid "ab932f5c-2409-11e3-b000-887628d43830"
kind "StaticLib"
removeflags {
@ -16,7 +15,7 @@ project "UnitTest++"
"../3rdparty/UnitTest++/src/*.h",
}
configuration { "linux or osx or android-* or *nacl*" }
configuration { "linux or osx or android-* or *nacl* or ps4" }
files {
"../3rdparty/UnitTest++/src/Posix/**.cpp",
"../3rdparty/UnitTest++/src/Posix/**.h",

79
3rdparty/bx/tests/handle.cpp vendored Normal file
View File

@ -0,0 +1,79 @@
/*
* Copyright 2010-2015 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "test.h"
#include <bx/handlealloc.h>
TEST(HandleListT)
{
bx::HandleListT<32> list;
list.pushBack(16);
CHECK(list.getFront() == 16);
CHECK(list.getBack() == 16);
list.pushFront(7);
CHECK(list.getFront() == 7);
CHECK(list.getBack() == 16);
uint16_t expected0[] = { 15, 31, 7, 16, 17, 11, 13 };
list.pushBack(17);
list.pushBack(11);
list.pushBack(13);
list.pushFront(31);
list.pushFront(15);
uint16_t count = 0;
for (uint16_t it = list.getFront(); it != UINT16_MAX; it = list.getNext(it), ++count)
{
CHECK(it == expected0[count]);
}
CHECK(count == BX_COUNTOF(expected0) );
list.remove(17);
list.remove(31);
list.remove(16);
list.pushBack(16);
uint16_t expected1[] = { 15, 7, 11, 13, 16 };
count = 0;
for (uint16_t it = list.getFront(); it != UINT16_MAX; it = list.getNext(it), ++count)
{
CHECK(it == expected1[count]);
}
CHECK(count == BX_COUNTOF(expected1) );
list.popBack();
list.popFront();
list.popBack();
list.popBack();
CHECK(list.getFront() == 7);
CHECK(list.getBack() == 7);
list.popBack();
CHECK(list.getFront() == UINT16_MAX);
CHECK(list.getBack() == UINT16_MAX);
}
TEST(HandleAllocLruT)
{
bx::HandleAllocLruT<16> lru;
uint16_t handle[4] =
{
lru.alloc(),
lru.alloc(),
lru.alloc(),
lru.alloc(),
};
lru.touch(handle[1]);
uint16_t expected0[] = { handle[1], handle[3], handle[2], handle[0] };
uint16_t count = 0;
for (uint16_t it = lru.getFront(); it != UINT16_MAX; it = lru.getNext(it), ++count)
{
CHECK(it == expected0[count]);
}
}

8
3rdparty/bx/tests/misc.cpp vendored Normal file
View File

@ -0,0 +1,8 @@
#include "test.h"
#include <bx/os.h>
TEST(getProcessMemoryUsed)
{
CHECK(0 != bx::getProcessMemoryUsed() );
// DBG("bx::getProcessMemoryUsed %d", bx::getProcessMemoryUsed() );
}

View File

@ -20,3 +20,33 @@ TEST(StrideAlign)
CHECK(48 == bx::strideAlign16(ii+1, 12) );
}
}
TEST(uint32_cnt)
{
CHECK( 0 == bx::uint32_cnttz(UINT32_C(1) ) );
CHECK( 0 == bx::uint32_cnttz_ref(UINT32_C(1) ) );
CHECK(31 == bx::uint32_cntlz(UINT32_C(1) ) );
CHECK(31 == bx::uint32_cntlz_ref(UINT32_C(1) ) );
CHECK( 0 == bx::uint64_cnttz(UINT64_C(1) ) );
CHECK( 0 == bx::uint64_cnttz_ref(UINT64_C(1) ) );
CHECK(63 == bx::uint64_cntlz(UINT64_C(1) ) );
CHECK(63 == bx::uint64_cntlz_ref(UINT64_C(1) ) );
CHECK( 1 == bx::uint32_cntbits(1) );
CHECK( 1 == bx::uint32_cntbits_ref(1) );
CHECK(16 == bx::uint32_cntbits(UINT16_MAX) );
CHECK(16 == bx::uint32_cntbits_ref(UINT16_MAX) );
CHECK(32 == bx::uint32_cntbits(UINT32_MAX) );
CHECK(32 == bx::uint32_cntbits_ref(UINT32_MAX) );
}
TEST(uint32_part)
{
CHECK(UINT32_C(0x55555555) == bx::uint32_part1by1(UINT16_MAX) );
CHECK(UINT32_C(0x09249249) == bx::uint32_part1by2(0x3ff) );
}

View File

@ -1,5 +1,5 @@
/*-
* Copyright 2012-2014 Matthew Endsley
* Copyright 2012-2015 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
@ -29,7 +29,9 @@
#include <tinystl/allocator.h>
#include <tinystl/unordered_map.h>
struct Foo { int bar; };
namespace {
struct Foo { int bar; };
}
TEST(uomap_nonpod_compiles) {

View File

@ -1,5 +1,5 @@
/*-
* Copyright 2012 Matthew Endsley
* Copyright 2012-1015 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
@ -35,9 +35,9 @@
struct complex {
complex() {data = 0;}
complex(const char* s) { data = _strdup(s); }
complex(const char* s) { data = strdup(s); }
~complex() { free(data); }
complex(const complex& other) { data = 0; if (other.data) data = _strdup(other.data); }
complex(const complex& other) { data = 0; if (other.data) data = strdup(other.data); }
complex& operator=(const complex& other) { complex(other).swap(*this); return *this; }
void swap(complex& other) { std::swap(data, other.data); }

View File

@ -1,5 +1,5 @@
/*-
* Copyright 2012 Matthew Endsley
* Copyright 2012-1015 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without

229
3rdparty/bx/tests/vector_nocopy.cpp vendored Normal file
View File

@ -0,0 +1,229 @@
/*-
* Copyright 2012-1015 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted providing that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
#include <tinystl/allocator.h>
#include <tinystl/vector.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
struct nocopy {
nocopy() { data = 0; }
explicit nocopy(const char* s) { data = s; }
~nocopy() { }
void swap(nocopy& other) { std::swap(data, other.data); }
void reset(const char* s) { data = s; }
const char* release() { const char* ret = data; data = 0; return ret; }
const char* data;
private:
nocopy(const nocopy& other);
nocopy& operator=(const nocopy& other);
};
static inline bool operator==(const nocopy& lhs, const char* rhs) {
if (lhs.data == 0 && rhs == 0)
return true;
if (lhs.data != 0 && rhs != 0)
return 0 == strcmp(lhs.data, rhs);
return false;
}
static inline bool operator==(const nocopy& lhs, const nocopy& rhs) {
if (lhs.data == 0 && rhs.data == 0)
return true;
if (lhs.data != 0 && rhs.data != 0)
return 0 == strcmp(lhs.data, rhs.data);
return false;
}
TEST(vector_nocopy_constructor) {
typedef tinystl::vector<nocopy> vector;
{
vector v;
CHECK( v.empty() );
CHECK( v.size() == 0 );
}
{
vector v(10);
CHECK( v.size() == 10 );
for (tinystl::vector<nocopy>::iterator it = v.begin(); it != v.end(); ++it) {
CHECK( it->data == 0 );
}
}
}
TEST(vector_nocopy_pushback) {
tinystl::vector<nocopy> v;
v.emplace_back("42");
v.emplace_back();
v.back().reset("24");
CHECK( v.size() == 2 );
CHECK( v[0] == "42" );
CHECK( v[1] == "24" );
}
TEST(vector_nocopy_vector) {
tinystl::vector< tinystl::vector<nocopy> > v(10);
tinystl::vector< tinystl::vector<nocopy> >::iterator it = v.begin(), end = v.end();
for (; it != end; ++it) {
CHECK( (*it).empty() );
CHECK( (*it).size() == 0 );
CHECK( (*it).begin() == (*it).end() );
}
}
TEST(vector_nocopy_swap) {
tinystl::vector<nocopy> v1;
v1.emplace_back("12");
v1.emplace_back("20");
tinystl::vector<nocopy> v2;
v2.emplace_back("54");
v1.swap(v2);
CHECK(v1.size() == 1);
CHECK(v2.size() == 2);
CHECK(v1[0] == "54");
CHECK(v2[0] == "12");
CHECK(v2[1] == "20");
}
TEST(vector_nocopy_popback) {
tinystl::vector<nocopy> v;
v.emplace_back("12");
v.emplace_back("24");
CHECK(v.back() == "24");
v.pop_back();
CHECK(v.back() == "12");
CHECK(v.size() == 1);
}
TEST(vector_nocopy_erase) {
tinystl::vector<nocopy> v;
v.emplace_back("1");
v.emplace_back("2");
v.emplace_back("3");
v.emplace_back("4");
v.emplace_back("5");
tinystl::vector<nocopy>::iterator it = v.erase(v.begin());
CHECK(*it == "2");
CHECK(v.size() == 4);
it = v.erase(v.end() - 1);
CHECK(it == v.end());
CHECK(v.size() == 3);
v.erase(v.begin() + 1, v.end() - 1);
CHECK(v.size() == 2);
CHECK(v[0] == "2");
CHECK(v[1] == "4");
}
TEST(vector_nocopy_erase_unordered) {
typedef tinystl::vector<nocopy> vector;
vector v;
v.emplace_back("1");
v.emplace_back("2");
v.emplace_back("3");
v.emplace_back("4");
v.emplace_back("5");
const char* first = v.front().release();
vector::iterator it = v.erase_unordered(v.begin());
CHECK( it == v.begin() );
CHECK( v.size() == 4 );
CHECK( std::count(v.begin(), v.end(), first) == 0 );
for (it = v.begin(); it != v.end(); ++it) {
CHECK( std::count(v.begin(), v.end(), *it) == 1 );
}
const char* last = v.back().release();
it = v.erase_unordered(v.end() - 1);
CHECK( it == v.end() );
CHECK( v.size() == 3 );
CHECK( std::count(v.begin(), v.end(), last) == 0 );
for (it = v.begin(); it != v.end(); ++it) {
CHECK( std::count(v.begin(), v.end(), *it) == 1 );
}
first = v.begin()->data;
last = (v.end() - 1)->data;
v.erase_unordered(v.begin() + 1, v.end() - 1);
CHECK( v.size() == 2 );
CHECK( std::count(v.begin(), v.end(), first) == 1 );
CHECK( std::count(v.begin(), v.end(), last) == 1 );
}
TEST(vector_nocopy_insert) {
tinystl::vector<nocopy> v;
v.emplace_back("1");
v.emplace_back("2");
v.emplace_back("3");
v.emplace_back("4");
v.emplace_back("5");
v.emplace(v.begin(), "0");
CHECK( v.size() == 6 );
CHECK( v[0] == "0" );
CHECK( v[1] == "1" );
CHECK( v[5] == "5" );
v.emplace(v.end(), "6");
CHECK( v.size() == 7 );
CHECK( v.front() == "0" );
CHECK( v.back() == "6" );
}
TEST(vector_nocopy_iterator) {
tinystl::vector<nocopy> v(5);
v[0].reset("1");
v[1].reset("2");
v[2].reset("3");
v[3].reset("4");
v[4].reset("5");
const tinystl::vector<nocopy>& cv = v;
//CHECK(v.data() == &*v.begin());
//CHECK(v.data() == &v[0]);
//CHECK(v.data() + v.size() == &*v.end());
CHECK(v.begin() == cv.begin());
CHECK(v.end() == cv.end());
//CHECK(v.data() == cv.data());
}

View File

@ -1,5 +1,5 @@
/*-
* Copyright 2012 Matthew Endsley
* Copyright 2012-1015 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
@ -33,14 +33,10 @@
#include <string.h>
#include <stdlib.h>
#if !BX_COMPILER_MSVC
# define _strdup strdup
#endif // !BX_COMPILER_MSVC
struct nodefault {
nodefault(const char* s) { data = _strdup(s); }
nodefault(const char* s) { data = strdup(s); }
~nodefault() { free(data); }
nodefault(const nodefault& other) { data = 0; if (other.data) data = _strdup(other.data); }
nodefault(const nodefault& other) { data = 0; if (other.data) data = strdup(other.data); }
nodefault& operator=(const nodefault& other) { nodefault(other).swap(*this); return *this; }
void swap(nodefault& other) { std::swap(data, other.data); }

Binary file not shown.

Binary file not shown.

Binary file not shown.