Skip to content

Commit 7a60528

Browse files
fix: helmet.hpp: pimpl implementation fixes.
Signed-off-by: Amlal El Mahrouss <[email protected]>
1 parent 73b8179 commit 7a60528

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

include/boost/http_proto/server/helmet.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ struct helmet_options
4141
class helmet
4242
{
4343
struct impl;
44-
std::unique_ptr<impl> impl_;
45-
44+
impl* impl_;
45+
4646
public:
4747
/**
4848
@brief Builds an helmet and compute its options for caching purposes.
@@ -54,6 +54,9 @@ class helmet
5454
BOOST_HTTP_PROTO_DECL
5555
~helmet();
5656

57+
helmet& operator=(helmet&&) noexcept;
58+
helmet(helmet&&) noexcept;
59+
5760
/**
5861
@brief Iterates over cachedHeaders and apply its rules to the response params.
5962
@param p route parameter argument

src/server/helmet.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ struct helmet::impl
8181
helmet::
8282
helmet(
8383
helmet_options helmet_options)
84+
: impl_(new impl())
8485
{
85-
impl_ = std::make_unique<impl>();
8686
impl_->options_ = std::move(helmet_options);
8787

8888
std::for_each(impl_->options_.headers.begin(), impl_->options_.headers.end(),
@@ -93,10 +93,27 @@ helmet(
9393
});
9494
}
9595

96-
/**
97-
AMLALE: This is here to prevent compiler erros from unique_ptr. (destructor doesnn't know how to destroy impl)
98-
*/
99-
helmet::~helmet() = default;
96+
helmet::~helmet()
97+
{
98+
delete impl_;
99+
impl_ = nullptr;
100+
}
101+
102+
helmet& helmet::operator=(helmet&& other) noexcept
103+
{
104+
impl_ = other.impl_;
105+
other.impl_ = nullptr;
106+
107+
return *this;
108+
}
109+
110+
111+
helmet::
112+
helmet(helmet&& other) noexcept
113+
: impl_(other.impl_)
114+
{
115+
other.impl_ = nullptr;
116+
}
100117

101118
route_result
102119
helmet::

0 commit comments

Comments
 (0)