Skip to content

Commit b8ffe2c

Browse files
committed
Move STL-like container headers to core/stl/containers
Includes: - CowPtr - CowVector - FixedVector - RingBuffer - StackString - TypedSpan Move allocator aware STL-like containers to `OpenVic::stl` namespace Includes: - CowPtr - CowVector - FixedVector - RingBuffer Move BasicIterator to `core/stl` Move TslHelper.hpp to `core/stl` and rename to MutableIterator.hpp Move memory container type aliases to `core/memory` Add memory type alias for cow_ptr Add memory type alias for cow_vector Move FixedVector from namespace `OpenVic::_detail` to `OpenVic::stl` Add stateful allocator support to FixedVector's constructors Replace assert in TypedSpan with `OV_HARDEN_ASSERT_ACCESS` Move STL-like container unit tests to `core/stl/containers`
1 parent 93e1668 commit b8ffe2c

51 files changed

Lines changed: 173 additions & 120 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/openvic-simulation/InstanceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include "openvic-simulation/DefinitionManager.hpp"
44
#include "openvic-simulation/console/ConsoleInstance.hpp"
5+
#include "openvic-simulation/core/stl/containers/TypedSpan.hpp"
56
#include "openvic-simulation/misc/GameAction.hpp"
6-
#include "openvic-simulation/types/TypedSpan.hpp"
77
#include "openvic-simulation/utility/Logger.hpp"
88

99
using namespace OpenVic;

src/openvic-simulation/core/memory/CowPtr.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
#include <foonathan/memory/std_allocator.hpp>
55

66
#include "openvic-simulation/core/memory/MemoryTracker.hpp"
7-
#include "openvic-simulation/types/CowPtr.hpp"
7+
#include "openvic-simulation/core/stl/containers/CowPtr.hpp"
88

99
namespace OpenVic::memory {
1010
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
11-
using cow_ptr = ::OpenVic::cow_ptr<
12-
T,
13-
foonathan::memory::std_allocator<T, tracker<RawAllocator>>
14-
>;
15-
}
11+
using cow_ptr = ::OpenVic::stl::cow_ptr<T, foonathan::memory::std_allocator<T, tracker<RawAllocator>>>;
12+
}

src/openvic-simulation/core/memory/CowVector.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
#include <foonathan/memory/std_allocator.hpp>
55

66
#include "openvic-simulation/core/memory/MemoryTracker.hpp"
7-
#include "openvic-simulation/types/CowVector.hpp"
7+
#include "openvic-simulation/core/stl/containers/CowVector.hpp"
88

99
namespace OpenVic::memory {
1010
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
11-
using cow_vector = ::OpenVic::cow_vector<
12-
T,
13-
foonathan::memory::std_allocator<T, tracker<RawAllocator>>
14-
>;
15-
}
11+
using cow_vector = ::OpenVic::stl::cow_vector<T, foonathan::memory::std_allocator<T, tracker<RawAllocator>>>;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <foonathan/memory/default_allocator.hpp>
4+
#include <foonathan/memory/std_allocator.hpp>
5+
6+
#include "openvic-simulation/core/memory/MemoryTracker.hpp"
7+
#include "openvic-simulation/core/stl/containers/FixedVector.hpp"
8+
9+
namespace OpenVic::memory {
10+
template<typename T, typename SizeT = std::size_t, class RawAllocator = foonathan::memory::default_allocator>
11+
using FixedVector = ::OpenVic::stl::FixedVector<T, SizeT, foonathan::memory::std_allocator<T, tracker<RawAllocator>>>;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <foonathan/memory/default_allocator.hpp>
4+
#include <foonathan/memory/std_allocator.hpp>
5+
6+
#include "openvic-simulation/core/memory/MemoryTracker.hpp"
7+
#include "openvic-simulation/core/stl/containers/RingBuffer.hpp"
8+
9+
namespace OpenVic::memory {
10+
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
11+
using RingBuffer = ::OpenVic::stl::RingBuffer<T, foonathan::memory::std_allocator<T, tracker<RawAllocator>>>;
12+
}

src/openvic-simulation/core/portable/ForwardableSpan.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <type_traits>
1111

1212
#include "openvic-simulation/core/Typedefs.hpp"
13-
#include "openvic-simulation/types/BasicIterator.hpp"
13+
#include "openvic-simulation/core/stl/BasicIterator.hpp"
1414

1515
namespace OpenVic::_detail::forwardable_span {
1616
static constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max();

src/openvic-simulation/types/BasicIterator.hpp renamed to src/openvic-simulation/core/stl/BasicIterator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <concepts>
44
#include <iterator>
55

6-
#include "openvic-simulation/core/Typedefs.hpp"
76
#include "openvic-simulation/core/Compare.hpp"
7+
#include "openvic-simulation/core/Typedefs.hpp"
88

99
namespace OpenVic {
1010
template<typename Pointer, typename ContainerTag>
File renamed without changes.

src/openvic-simulation/types/CowPtr.hpp renamed to src/openvic-simulation/core/stl/containers/CowPtr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "openvic-simulation/core/template/Concepts.hpp"
1111
#include "openvic-simulation/core/Typedefs.hpp"
1212

13-
namespace OpenVic {
13+
namespace OpenVic::stl {
1414
/**
1515
* A Copy-On-Write pointer
1616
*

src/openvic-simulation/types/CowVector.hpp renamed to src/openvic-simulation/core/stl/containers/CowVector.hpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
#include <memory>
1010
#include <span>
1111
#include <type_traits>
12+
#include <vector>
1213

1314
#include "openvic-simulation/core/Assert.hpp"
14-
#include "openvic-simulation/types/BasicIterator.hpp"
15-
#include "openvic-simulation/utility/Allocator.hpp"
1615
#include "openvic-simulation/core/Compare.hpp"
16+
#include "openvic-simulation/core/stl/BasicIterator.hpp"
1717
#include "openvic-simulation/core/template/Concepts.hpp"
1818
#include "openvic-simulation/core/Typedefs.hpp"
19+
#include "openvic-simulation/utility/Allocator.hpp"
1920

20-
namespace OpenVic {
21+
namespace OpenVic::stl {
2122
/**
2223
* A Copy-On-Write vector (replicating std::vector)
2324
*
@@ -97,8 +98,7 @@ namespace OpenVic {
9798
swap(other, *this);
9899
} else if (!other.empty()) {
99100
_data = _allocate_payload(other.size());
100-
_data->array_end =
101-
uninitialized_move(other._data->array, other._data->array_end, _data->array, alloc);
101+
_data->array_end = uninitialized_move(other._data->array, other._data->array_end, _data->array, alloc);
102102
destroy(_data->array, _data->array_end, alloc);
103103
_data->array_end = _data->array;
104104
}
@@ -449,8 +449,7 @@ namespace OpenVic {
449449
if constexpr (move_insertable_allocator<allocator_type>) {
450450
_relocate(_data->array, _data->array_end, new_data->array, alloc);
451451
} else {
452-
new_data->array_end =
453-
uninitialized_move(_data->array, _data->array_end, new_data->array, alloc);
452+
new_data->array_end = uninitialized_move(_data->array, _data->array_end, new_data->array, alloc);
454453
destroy(_data->array, _data->array_end, alloc);
455454
}
456455
_deallocate_payload(_data);
@@ -1115,37 +1114,36 @@ namespace OpenVic {
11151114
return std::lexicographical_compare_three_way(x.begin(), x.end(), y.begin(), y.end(), three_way_compare);
11161115
}
11171116

1118-
namespace cow {
1119-
template<specialization_of<cow_vector> T>
1120-
T const& read(T& v) {
1121-
return v;
1122-
}
1123-
1124-
template<specialization_of<cow_vector> T>
1125-
typename T::writer& write(T& v) {
1126-
return v.write();
1127-
}
1128-
}
1129-
11301117
static_assert(
11311118
sizeof(cow_vector<int>) == sizeof(cow_vector<int>::writer), "cow_vector must always be the same size as it's writer"
11321119
);
11331120
}
11341121

1122+
namespace OpenVic::cow {
1123+
template<specialization_of<::OpenVic::stl::cow_vector> T>
1124+
T const& read(T& v) {
1125+
return v;
1126+
}
1127+
1128+
template<specialization_of<::OpenVic::stl::cow_vector> T>
1129+
typename T::writer& write(T& v) {
1130+
return v.write();
1131+
}
1132+
}
1133+
11351134
namespace std {
11361135
template<typename T, typename Allocator>
11371136
inline void swap( //
1138-
typename OpenVic::cow_vector<T, Allocator>::writer& x, typename OpenVic::cow_vector<T, Allocator>::writer& y
1137+
typename ::OpenVic::stl::cow_vector<T, Allocator>::writer& x, typename ::OpenVic::stl::cow_vector<T, Allocator>::writer& y
11391138
) {
11401139
x.swap(y);
11411140
}
11421141

11431142
template<typename T, typename Allocator, typename Predicate>
1144-
inline typename OpenVic::cow_vector<T, Allocator>::size_type erase_if( //
1145-
typename OpenVic::cow_vector<T, Allocator>::writer& cont, Predicate pred
1143+
inline typename ::OpenVic::stl::cow_vector<T, Allocator>::size_type erase_if( //
1144+
typename ::OpenVic::stl::cow_vector<T, Allocator>::writer& cont, Predicate pred
11461145
) {
1147-
using namespace OpenVic;
1148-
typename cow_vector<T, Allocator>::writer& ucont = cont;
1146+
typename ::OpenVic::stl::cow_vector<T, Allocator>::writer& ucont = cont;
11491147
const auto orig_size = cont.size();
11501148
const auto end = ucont.end();
11511149
decltype(end) removed = std::remove_if(ucont.begin(), end, std::ref(pred));
@@ -1158,11 +1156,10 @@ namespace std {
11581156
}
11591157

11601158
template<typename T, typename Allocator, typename U>
1161-
inline typename OpenVic::cow_vector<T, Allocator>::size_type erase( //
1162-
typename OpenVic::cow_vector<T, Allocator>::writer& cont, U const& value
1159+
inline typename ::OpenVic::stl::cow_vector<T, Allocator>::size_type erase( //
1160+
typename ::OpenVic::stl::cow_vector<T, Allocator>::writer& cont, U const& value
11631161
) {
1164-
using namespace OpenVic;
1165-
typename cow_vector<T, Allocator>::writer& ucont = cont;
1162+
typename ::OpenVic::stl::cow_vector<T, Allocator>::writer& ucont = cont;
11661163
const auto orig_size = cont.size();
11671164
const auto end = ucont.end();
11681165
decltype(end) removed = std::remove_if(ucont.begin(), end, [&value](auto it) {

0 commit comments

Comments
 (0)