Skip to content

Commit

Permalink
xrCommon: alias templates instead of class inherited from std::class
Browse files Browse the repository at this point in the history
Remove xalloc.h from common project (it is in xrCore project)
  • Loading branch information
Xottab-DUTY committed Jan 5, 2018
1 parent dff8844 commit 4c332f6
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 68 deletions.
1 change: 0 additions & 1 deletion src/Common/Common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
<ClInclude Include="..\xrCommon\math_funcs_inline.h" />
<ClInclude Include="..\xrCommon\misc_math_types.h" />
<ClInclude Include="..\xrCommon\predicates.h" />
<ClInclude Include="..\xrCommon\xalloc.h" />
<ClInclude Include="..\xrCommon\xr_deque.h" />
<ClInclude Include="..\xrCommon\xr_list.h" />
<ClInclude Include="..\xrCommon\xr_map.h" />
Expand Down
3 changes: 0 additions & 3 deletions src/Common/Common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
<ClInclude Include="..\xrCommon\misc_math_types.h">
<Filter>xrCommon</Filter>
</ClInclude>
<ClInclude Include="..\xrCommon\xalloc.h">
<Filter>xrCommon</Filter>
</ClInclude>
<ClInclude Include="..\xrCommon\xr_map.h">
<Filter>xrCommon</Filter>
</ClInclude>
Expand Down
18 changes: 5 additions & 13 deletions src/xrCommon/xr_deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@
#include "xrCore/Memory/XRayAllocator.hpp"

template <typename T, typename allocator = XRay::xray_allocator<T>>
class xr_deque : public std::deque<T, allocator>
{
public:
typedef typename allocator allocator_type;
typedef typename allocator_type::value_type value_type;
typedef typename allocator_type::size_type size_type;

u32 size() const { return (u32)std::deque<T, allocator>::size(); }
};
using xr_deque = std::deque<T, allocator>;

#define DEF_DEQUE(N, T)\
typedef xr_deque<T> N;\
typedef N::iterator N##_it;
using N = xr_deque<T>;\
using N##_it = N::iterator;

#define DEFINE_DEQUE(T, N, I)\
typedef xr_deque<T> N;\
typedef N::iterator I;
using N = xr_deque<T>;\
using I = N::iterator;
14 changes: 5 additions & 9 deletions src/xrCommon/xr_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
#include "xrCore/Memory/XRayAllocator.hpp"

template <typename T, typename allocator = XRay::xray_allocator<T>>
class xr_list : public std::list<T, allocator>
{
public:
u32 size() const { return (u32)std::list<T, allocator>::size(); }
};
using xr_list = std::list<T, allocator>;

#define DEF_LIST(N, T)\
typedef xr_list<T> N;\
typedef N::iterator N##_it;
using N = xr_list<T>;\
using N##_it = N::iterator;

#define DEFINE_LIST(T, N, I)\
typedef xr_list<T> N;\
typedef N::iterator I;
using N = xr_list<T>;\
using I = N::iterator;
12 changes: 2 additions & 10 deletions src/xrCommon/xr_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@
#include "xrCore/Memory/XRayAllocator.hpp"

template <typename K, class V, class P = std::less<K>, typename allocator = XRay::xray_allocator<std::pair<K, V>>>
class xr_map : public std::map<K, V, P, allocator>
{
public:
u32 size() const { return (u32)std::map<K, V, P, allocator>::size(); }
};
using xr_map = std::map<K, V, P, allocator>;

template <typename K, class V, class P = std::less<K>, typename allocator = XRay::xray_allocator<std::pair<K, V>>>
class xr_multimap : public std::multimap<K, V, P, allocator>
{
public:
u32 size() const { return (u32)std::multimap<K, V, P, allocator>::size(); }
};
using xr_multimap = std::multimap<K, V, P, allocator>;

#define DEF_MAP(N, K, T)\
typedef xr_map<K, T> N;\
Expand Down
20 changes: 6 additions & 14 deletions src/xrCommon/xr_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
#include "xrCore/Memory/XRayAllocator.hpp"

template <typename K, class P = std::less<K>, typename allocator = XRay::xray_allocator<K>>
class xr_set : public std::set<K, P, allocator>
{
public:
u32 size() const { return (u32)std::set<K, P, allocator>::size(); }
};
using xr_set = std::set<K, P, allocator>;

template <typename K, class P = std::less<K>, typename allocator = XRay::xray_allocator<K>>
class xr_multiset : public std::multiset<K, P, allocator>
{
public:
u32 size() const { return (u32)std::multiset<K, P, allocator>::size(); }
};
using xr_multiset = std::multiset<K, P, allocator>;

#define DEFINE_SET(T, N, I)\
typedef xr_set<T> N;\
typedef N::iterator I;
using N = xr_set<T>;\
using I = N::iterator;

#define DEFINE_SET_PRED(T, N, I, P)\
typedef xr_set<T, P> N;\
typedef N::iterator I;
using N = xr_set<T, P>;\
using I = N::iterator;
22 changes: 11 additions & 11 deletions src/xrCommon/xr_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ template <typename _Ty, class _C = xr_vector<_Ty>>
class xr_stack
{
public:
typedef typename _C::allocator_type allocator_type;
typedef typename allocator_type::value_type value_type;
typedef typename allocator_type::size_type size_type;
typedef xr_stack<_Ty, _C> _Myt;
using allocator_type = typename _C::allocator_type;
using value_type = typename allocator_type::value_type;
using size_type = typename allocator_type::size_type;
using _Myt = xr_stack<_Ty, _C>;

allocator_type get_allocator() const { return c.get_allocator(); }
bool empty() const { return c.empty(); }
Expand All @@ -17,15 +17,15 @@ class xr_stack
const value_type& top() const { return c.back(); }
void push(const value_type& _X) { c.push_back(_X); }
void pop() { c.pop_back(); }
bool operator==(const _Myt& _X) const { return c==_X.c; }
bool operator!=(const _Myt& _X) const { return !(*this==_X); }
bool operator<(const _Myt& _X) const { return c<_X.c; }
bool operator>(const _Myt& _X) const { return _X<*this; }
bool operator<=(const _Myt& _X) const { return !(_X<*this); }
bool operator>=(const _Myt& _X) const { return !(*this<_X); }
bool operator==(const _Myt& _X) const { return c == _X.c; }
bool operator!=(const _Myt& _X) const { return !(*this == _X); }
bool operator<(const _Myt& _X) const { return c < _X.c; }
bool operator>(const _Myt& _X) const { return _X < *this; }
bool operator<=(const _Myt& _X) const { return !(_X < *this); }
bool operator>=(const _Myt& _X) const { return !(*this < _X); }

protected:
_C c;
};

#define DEFINE_STACK(T, N) typedef xr_stack<T> N;
#define DEFINE_STACK(T, N) using N = xr_stack<T>;
14 changes: 7 additions & 7 deletions src/xrCommon/xr_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#include <vector>
#include "xrCore/Memory/XRayAllocator.hpp"

template <typename T, typename allocator = XRay::xray_allocator<T>>
using xr_vector = class std::vector<T, allocator>;

#define DEF_VECTOR(N, T)\
typedef xr_vector<T> N;\
typedef N::iterator N##_it;
using N = xr_vector<T>;\
using N##_it = N::iterator;

#define DEFINE_VECTOR(T, N, I)\
typedef xr_vector<T> N;\
typedef N::iterator I;

template <typename T, typename allocator = XRay::xray_allocator<T>>
using xr_vector = class std::vector<T, allocator>;
using N = xr_vector<T>;\
using I = N::iterator;

0 comments on commit 4c332f6

Please sign in to comment.