From ceda0064803e7548dae00c1042112f8971b70091 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sat, 16 Jul 2016 23:22:23 +0200 Subject: [PATCH] removed BaseWrapper --- src/uvw/resource.hpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/uvw/resource.hpp b/src/uvw/resource.hpp index 9c44559c..45fc8f50 100644 --- a/src/uvw/resource.hpp +++ b/src/uvw/resource.hpp @@ -14,28 +14,22 @@ namespace uvw { template class Resource: public Emitter, public Self { + using Deleter = void(*)(void *); + template friend class Resource; - struct BaseWrapper { - virtual ~BaseWrapper() = default; - virtual void * get() const noexcept = 0; - }; - template - struct Wrapper: BaseWrapper { - Wrapper(): resource{std::make_unique()} { } - void * get() const noexcept override { return resource.get(); } - private: - std::unique_ptr resource; - }; + static void proto(void *resource) { + delete static_cast(resource); + } protected: template class R> explicit Resource(R, std::shared_ptr ref) : Emitter{}, Self{}, - wrapper{std::make_unique>()}, + resource{new U, &proto}, pLoop{std::move(ref)} { this->template get()->data = static_cast(this); @@ -44,7 +38,7 @@ protected: uv_loop_t* parent() const noexcept { return pLoop->loop.get(); } template - U* get() const noexcept { return reinterpret_cast(wrapper->get()); } + U* get() const noexcept { return reinterpret_cast(resource.get()); } template auto invoke(F &&f, Args&&... args) { @@ -54,6 +48,12 @@ protected: } public: + Resource(const Resource &) = delete; + Resource(Resource &&) = delete; + + Resource& operator=(const Resource &) = delete; + Resource& operator=(Resource &&) = delete; + virtual ~Resource() { static_assert(std::is_base_of, T>::value, "!"); } @@ -61,7 +61,7 @@ public: Loop& loop() const noexcept { return *pLoop; } private: - std::unique_ptr wrapper; + std::unique_ptr resource; std::shared_ptr pLoop; };