-
-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More header cleaning, and a few compiler warnings squashed.
- Loading branch information
1 parent
8e1d0b1
commit 6f24305
Showing
23 changed files
with
242 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#pragma once | ||
#include "xrCore/xrMemory.h" | ||
|
||
template <class T> | ||
class xalloc | ||
{ | ||
public: | ||
typedef size_t size_type; | ||
typedef std::ptrdiff_t difference_type; | ||
typedef T* pointer; | ||
typedef const T* const_pointer; | ||
typedef T& reference; | ||
typedef const T& const_reference; | ||
typedef T value_type; | ||
|
||
public: | ||
template<class _Other> | ||
struct rebind | ||
{ | ||
typedef xalloc<_Other> other; | ||
}; | ||
|
||
public: | ||
pointer address(reference _Val) const { return &_Val; } | ||
const_pointer address(const_reference _Val) const { return &_Val; } | ||
xalloc() {} | ||
xalloc(const xalloc<T>&) {} | ||
template<class _Other> | ||
xalloc(const xalloc<_Other>&) {} | ||
template<class _Other> | ||
xalloc<T>& operator=(const xalloc<_Other>&) { return *this; } | ||
pointer allocate(size_type n, const void* p = nullptr) const { return xr_alloc<T>((u32)n); } | ||
char* _charalloc(size_type n) { return (char*)allocate(n); } | ||
void deallocate(pointer p, size_type n) const { xr_free(p); } | ||
void deallocate(void* p, size_type n) const { xr_free(p); } | ||
void construct(pointer p, const T& _Val) { std::_Construct(p, _Val); } | ||
void destroy(pointer p) { std::_Destroy(p); } | ||
size_type max_size() const | ||
{ | ||
size_type _Count = (size_type)(-1)/sizeof(T); | ||
return 0<_Count ? _Count : 1; | ||
} | ||
}; | ||
|
||
struct xr_allocator | ||
{ | ||
template <typename T> | ||
struct helper | ||
{ | ||
typedef xalloc<T> result; | ||
}; | ||
|
||
static void* alloc(const u32& n) { return xr_malloc((u32)n); } | ||
template <typename T> | ||
static void dealloc(T*& p) { xr_free(p); } | ||
}; | ||
|
||
template <class _Ty, class _Other> | ||
inline bool operator==(const xalloc<_Ty>&, const xalloc<_Other>&) { return true; } | ||
|
||
template <class _Ty, class _Other> | ||
inline bool operator!=(const xalloc<_Ty>&, const xalloc<_Other>&) { return false; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#pragma once | ||
#include <vector> | ||
#include "xalloc.h" | ||
|
||
#ifdef _M_AMD64 | ||
#define M_DONTDEFERCLEAR_EXT | ||
#endif | ||
|
||
#define M_DONTDEFERCLEAR_EXT // for mem-debug only | ||
|
||
#define DEF_VECTOR(N, T)\ | ||
typedef xr_vector<T> N;\ | ||
typedef N::iterator N##_it; | ||
|
||
#define DEFINE_VECTOR(T, N, I)\ | ||
typedef xr_vector<T> N;\ | ||
typedef N::iterator I; | ||
|
||
// vector | ||
template <typename T, typename allocator = xalloc<T>> | ||
class xr_vector : public std::vector<T, allocator> | ||
{ | ||
private: | ||
typedef std::vector<T, allocator> inherited; | ||
|
||
public: | ||
typedef allocator allocator_type; | ||
|
||
public: | ||
xr_vector() : inherited() {} | ||
xr_vector(size_t _count, const T& _value) : inherited(_count, _value) {} | ||
explicit xr_vector(size_t _count) : inherited(_count) {} | ||
u32 size() const { return (u32)inherited::size(); } | ||
|
||
void clear_and_free() { inherited::clear(); } | ||
void clear_not_free() { erase(begin(), end()); } | ||
void clear_and_reserve() | ||
{ | ||
if (capacity() <= size() + size()/4) | ||
clear_not_free(); | ||
else | ||
{ | ||
u32 old = size(); | ||
clear_and_free(); | ||
reserve(old); | ||
} | ||
} | ||
#ifdef M_DONTDEFERCLEAR_EXT // defined (or not) by xalloc.h | ||
void clear() { clear_and_free(); } | ||
#else | ||
void clear() { clear_not_free(); } | ||
#endif | ||
const_reference operator[](size_type _Pos) const | ||
{ | ||
VERIFY2(_Pos<size(), | ||
make_string("index is out of range: index requested[%d], size of container[%d]", _Pos, size()).c_str()); | ||
return *(begin()+_Pos); | ||
} | ||
reference operator[](size_type _Pos) | ||
{ | ||
VERIFY2(_Pos<size(), | ||
make_string("index is out of range: index requested[%d], size of container[%d]", _Pos, size()).c_str()); | ||
return *(begin()+_Pos); | ||
} | ||
}; | ||
|
||
// vector<bool> | ||
template <> | ||
class xr_vector<bool, xalloc<bool>> : public std::vector<bool, xalloc<bool>> | ||
{ | ||
private: | ||
typedef std::vector<bool, xalloc<bool>> inherited; | ||
|
||
public: | ||
u32 size() const { return (u32)inherited::size(); } | ||
void clear() { erase(begin(), end()); } | ||
}; | ||
|
||
template <typename allocator> | ||
class xr_vector<bool, allocator> : public std::vector<bool, allocator> | ||
{ | ||
private: | ||
typedef std::vector<bool, allocator> inherited; | ||
|
||
public: | ||
u32 size() const { return (u32)inherited::size(); } | ||
void clear() { erase(begin(), end()); } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.