Skip to content

Commit e8ce326

Browse files
Merge pull request #14 from deeplex/dev/13-parse_context-state-API
feat: Add state API to `parse_context`
2 parents 3bb050c + 451c58b commit e8ce326

10 files changed

+595
-13
lines changed

.github/workflows/cpp-ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
uses: lukka/run-vcpkg@v10
4141
with:
4242
vcpkgDirectory: ${{ github.workspace }}/build/vcpkg
43-
vcpkgGitCommitId: 71d3fa60b67540e9bf5fde2bf2188f579ff09433
43+
vcpkgGitCommitId: 1271068e139c1fc30bae405c0bca0e379e155bd2
4444
prependedCacheKey: compiler=${{ matrix.compiler }}
4545
#appendedCacheKey: r00
4646

@@ -100,7 +100,7 @@ jobs:
100100
uses: lukka/run-vcpkg@v10
101101
with:
102102
vcpkgDirectory: ${{ github.workspace }}/../vcpkg
103-
vcpkgGitCommitId: 71d3fa60b67540e9bf5fde2bf2188f579ff09433
103+
vcpkgGitCommitId: 1271068e139c1fc30bae405c0bca0e379e155bd2
104104
prependedCacheKey: compiler=clang-15
105105
#appendedCacheKey: r00
106106

CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
109109
/Zc:__cplusplus # correctly define the __cplusplus macro
110110
)
111111
endif()
112+
if (WIN32)
113+
target_compile_definitions(compiler_settings INTERFACE
114+
-D_ENABLE_EXTENDED_ALIGNED_STORAGE=1
115+
)
116+
endif()
112117

113118

114119
########################################################################

sources.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dplx_target_sources(deeppack
3131
dp/layout_descriptor
3232
dp/macros
3333
dp/object_def
34+
dp/state
3435
dp/tuple_def
3536

3637
dp/codecs/auto_enum

src/dp_tests/test_input_stream.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,25 @@ class simple_test_input_stream final : public dp::input_buffer
8888
}
8989
};
9090

91-
class simple_test_parse_context final : private dp::parse_context
91+
class simple_test_parse_context final
9292
{
93+
dp::parse_context ctx;
94+
9395
public:
96+
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
9497
simple_test_input_stream stream;
9598

9699
explicit simple_test_parse_context(
97100
std::span<std::byte const> const readBuffer,
98101
bool const initiallyEmpty = false)
99-
: parse_context{stream}
102+
: ctx{stream}
100103
, stream(readBuffer, initiallyEmpty)
101104
{
102105
}
103106

104107
auto as_parse_context() noexcept -> dp::parse_context &
105108
{
106-
return *this;
109+
return ctx;
107110
}
108111
};
109112

src/dp_tests/test_output_stream.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,25 @@ class test_output_stream final : public dp::output_buffer
250250
}
251251
};
252252

253-
class test_emit_context final : private dp::emit_context
253+
class test_emit_context final
254254
{
255+
dp::emit_context ctx;
256+
255257
public:
258+
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
256259
test_output_stream stream;
257260

258261
explicit test_emit_context(
259262
std::initializer_list<std::size_t> const gatherBufferSizes,
260263
bool const initiallyEmpty = false)
261-
: emit_context{stream}
264+
: ctx{stream}
262265
, stream(gatherBufferSizes, initiallyEmpty)
263266
{
264267
}
265268

266269
auto as_emit_context() noexcept -> dp::emit_context &
267270
{
268-
return *this;
271+
return ctx;
269272
}
270273
};
271274

src/dplx/dp/items/parse_context.hpp

+22
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,36 @@
77

88
#pragma once
99

10+
#include <cstddef>
11+
#include <memory_resource>
12+
1013
#include <dplx/dp/fwd.hpp>
14+
#include <dplx/dp/state.hpp>
1115

1216
namespace dplx::dp
1317
{
1418

1519
struct parse_context
1620
{
1721
input_buffer &in;
22+
state_store states;
23+
link_store links;
24+
25+
explicit parse_context(
26+
input_buffer &inStreamBuffer,
27+
std::pmr::polymorphic_allocator<std::byte> const &allocator
28+
= std::pmr::polymorphic_allocator<std::byte>{})
29+
: in(inStreamBuffer)
30+
, states(allocator)
31+
, links(allocator)
32+
{
33+
}
34+
35+
[[nodiscard]] auto get_allocator() const noexcept
36+
-> std::pmr::polymorphic_allocator<std::byte>
37+
{
38+
return states.get_allocator();
39+
}
1840
};
1941

2042
} // namespace dplx::dp

0 commit comments

Comments
 (0)