Skip to content

Commit

Permalink
Merge pull request #14 from deeplex/dev/13-parse_context-state-API
Browse files Browse the repository at this point in the history
feat: Add state API to `parse_context`
  • Loading branch information
BurningEnlightenment authored Mar 30, 2023
2 parents 3bb050c + 451c58b commit e8ce326
Show file tree
Hide file tree
Showing 10 changed files with 595 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cpp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: lukka/run-vcpkg@v10
with:
vcpkgDirectory: ${{ github.workspace }}/build/vcpkg
vcpkgGitCommitId: 71d3fa60b67540e9bf5fde2bf2188f579ff09433
vcpkgGitCommitId: 1271068e139c1fc30bae405c0bca0e379e155bd2
prependedCacheKey: compiler=${{ matrix.compiler }}
#appendedCacheKey: r00

Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
uses: lukka/run-vcpkg@v10
with:
vcpkgDirectory: ${{ github.workspace }}/../vcpkg
vcpkgGitCommitId: 71d3fa60b67540e9bf5fde2bf2188f579ff09433
vcpkgGitCommitId: 1271068e139c1fc30bae405c0bca0e379e155bd2
prependedCacheKey: compiler=clang-15
#appendedCacheKey: r00

Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
/Zc:__cplusplus # correctly define the __cplusplus macro
)
endif()
if (WIN32)
target_compile_definitions(compiler_settings INTERFACE
-D_ENABLE_EXTENDED_ALIGNED_STORAGE=1
)
endif()


########################################################################
Expand Down
1 change: 1 addition & 0 deletions sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dplx_target_sources(deeppack
dp/layout_descriptor
dp/macros
dp/object_def
dp/state
dp/tuple_def

dp/codecs/auto_enum
Expand Down
9 changes: 6 additions & 3 deletions src/dp_tests/test_input_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,25 @@ class simple_test_input_stream final : public dp::input_buffer
}
};

class simple_test_parse_context final : private dp::parse_context
class simple_test_parse_context final
{
dp::parse_context ctx;

public:
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
simple_test_input_stream stream;

explicit simple_test_parse_context(
std::span<std::byte const> const readBuffer,
bool const initiallyEmpty = false)
: parse_context{stream}
: ctx{stream}
, stream(readBuffer, initiallyEmpty)
{
}

auto as_parse_context() noexcept -> dp::parse_context &
{
return *this;
return ctx;
}
};

Expand Down
9 changes: 6 additions & 3 deletions src/dp_tests/test_output_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,25 @@ class test_output_stream final : public dp::output_buffer
}
};

class test_emit_context final : private dp::emit_context
class test_emit_context final
{
dp::emit_context ctx;

public:
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
test_output_stream stream;

explicit test_emit_context(
std::initializer_list<std::size_t> const gatherBufferSizes,
bool const initiallyEmpty = false)
: emit_context{stream}
: ctx{stream}
, stream(gatherBufferSizes, initiallyEmpty)
{
}

auto as_emit_context() noexcept -> dp::emit_context &
{
return *this;
return ctx;
}
};

Expand Down
22 changes: 22 additions & 0 deletions src/dplx/dp/items/parse_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,36 @@

#pragma once

#include <cstddef>
#include <memory_resource>

#include <dplx/dp/fwd.hpp>
#include <dplx/dp/state.hpp>

namespace dplx::dp
{

struct parse_context
{
input_buffer &in;
state_store states;
link_store links;

explicit parse_context(
input_buffer &inStreamBuffer,
std::pmr::polymorphic_allocator<std::byte> const &allocator
= std::pmr::polymorphic_allocator<std::byte>{})
: in(inStreamBuffer)
, states(allocator)
, links(allocator)
{
}

[[nodiscard]] auto get_allocator() const noexcept
-> std::pmr::polymorphic_allocator<std::byte>
{
return states.get_allocator();
}
};

} // namespace dplx::dp
Loading

0 comments on commit e8ce326

Please sign in to comment.