Skip to content

Commit 557c156

Browse files
committed
New xr_array class instead of deprecated svector
Reverted changes for FixedVector.h from previous commit
1 parent 7c99022 commit 557c156

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

src/Common/Common.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
<ClInclude Include="..\xrCommon\math_funcs_inline.h" />
172172
<ClInclude Include="..\xrCommon\misc_math_types.h" />
173173
<ClInclude Include="..\xrCommon\predicates.h" />
174+
<ClInclude Include="..\xrCommon\xr_array.h" />
174175
<ClInclude Include="..\xrCommon\xr_deque.h" />
175176
<ClInclude Include="..\xrCommon\xr_list.h" />
176177
<ClInclude Include="..\xrCommon\xr_map.h" />

src/Common/Common.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
<ClInclude Include="..\xrCommon\xr_unordered_map.h">
8383
<Filter>xrCommon</Filter>
8484
</ClInclude>
85+
<ClInclude Include="..\xrCommon\xr_array.h">
86+
<Filter>xrCommon</Filter>
87+
</ClInclude>
8588
</ItemGroup>
8689
<ItemGroup>
8790
<Filter Include="NvMender2003">

src/editors/LevelEditor/Edit/ESceneDOTools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ struct SIndexDist
2424
SIndexDist() { ZeroMemory(this, sizeof(SIndexDist)); }
2525
};
2626

27-
DEFINE_SVECTOR(SIndexDist, 4, SIndexDistVec, SIndexDistIt);
27+
typedef svector<SIndexDist, 4> SIndexDistVec;
28+
typedef SIndexDistVec::iterator SIndexDistIt;
2829

2930
DEFINE_MAP(u32, DOVec, ColorIndexMap, ColorIndexPairIt);
3031

src/xrCommon/xr_array.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
#include <array>
3+
4+
template<typename T, size_t Size>
5+
using xr_array = std::array<T, Size>;
6+
7+
// compatibility with old svector
8+
template<typename T, size_t Size>
9+
class xr_array_s : public std::array<T, Size>
10+
{
11+
// svector used to contain the 'count' variable
12+
// which used 4 bytes of memory
13+
u32 dummy = 0;
14+
};

src/xrCore/FixedVector.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef FixedVectorH
33
#define FixedVectorH
44

5+
// deprecated, use xr_array instead
56
template <class T, std::size_t dim>
67
class svector
78
{
@@ -15,7 +16,7 @@ class svector
1516

1617
private:
1718
value_type array[dim];
18-
size_t count;
19+
u32 count;
1920

2021
public:
2122
svector() : count(0) {}
@@ -26,7 +27,7 @@ class svector
2627
IC const_iterator end() const { return array + count; }
2728
IC const_iterator cbegin() const { return array; }
2829
IC const_iterator cend() const { return array + count; }
29-
IC size_t size() const { return count; }
30+
IC u32 size() const { return count; }
3031
IC void clear() { count = 0; }
3132

3233
IC void resize(int c)
@@ -49,13 +50,13 @@ class svector
4950
count--;
5051
}
5152

52-
IC reference operator[](size_t id)
53+
IC reference operator[](u32 id)
5354
{
5455
VERIFY(id < count);
5556
return array[id];
5657
}
5758

58-
IC const_reference operator[](size_t id) const
59+
IC const_reference operator[](u32 id) const
5960
{
6061
VERIFY(id < count);
6162
return array[id];
@@ -80,16 +81,16 @@ class svector
8081

8182
IC void inc() { count++; }
8283
IC bool empty() const { return 0 == count; }
83-
IC void erase(size_t id)
84+
IC void erase(u32 id)
8485
{
8586
VERIFY(id < count);
8687
count--;
87-
for (size_t i = id; i < count; i++)
88+
for (u32 i = id; i < count; i++)
8889
array[i] = array[i + 1];
8990
}
9091

91-
IC void erase(iterator it) { erase(it - begin()); }
92-
IC void insert(size_t id, reference V)
92+
IC void erase(iterator it) { erase(u32(it - begin())); }
93+
IC void insert(u32 id, reference V)
9394
{
9495
VERIFY(id < count);
9596
for (int i = count; i > int(id); i--)
@@ -107,11 +108,10 @@ class svector
107108
{
108109
if (size() != base.size())
109110
return false;
110-
for (size_t cmp = 0; cmp < size(); cmp++)
111+
for (u32 cmp = 0; cmp < size(); cmp++)
111112
if ((*this)[cmp] != base[cmp])
112113
return false;
113114
return true;
114115
}
115116
};
116-
117117
#endif

src/xrCore/_stl_extensions.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "_std_extensions.h"
1010
#include "xrMemory.h"
1111
#include "xrCore/Memory/XRayAllocator.hpp"
12+
#include "xrCommon/xr_array.h"
1213
#include "xrCommon/xr_vector.h"
1314
#include "xrCommon/xr_map.h"
1415
#include "xrCommon/xr_set.h"
@@ -29,9 +30,6 @@
2930
// Xottab_DUTY: TODO: or maybe use Im-Dex variant (Get rid of this DEFINE macroses)
3031

3132
// STL extensions
32-
#define DEFINE_SVECTOR(T, C, N, I) \
33-
typedef svector<T, C> N; \
34-
typedef N::iterator I;
3533
#include "FixedVector.h"
3634
#include "buffer_vector.h"
3735
#include "xr_vector_defs.h"

0 commit comments

Comments
 (0)