From 6232d13f5321b87ddf12a1aa36b4545da45f173d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 17 Nov 2021 22:34:57 +0100 Subject: Travel3: Simple image and video display site Reads the images and videos from filesystem and builds a site in memroy. --- src/weak_ptr.hh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/weak_ptr.hh (limited to 'src/weak_ptr.hh') diff --git a/src/weak_ptr.hh b/src/weak_ptr.hh new file mode 100644 index 0000000..5859d0c --- /dev/null +++ b/src/weak_ptr.hh @@ -0,0 +1,42 @@ +#ifndef WEAK_PTR_HH +#define WEAK_PTR_HH + +#include + +template +class WeakPtr { +public: + explicit WeakPtr(T* ptr) + : ptr_(ptr) {} + + void unlink() { + ptr_ = nullptr; + } + + T* get() { + return ptr_; + } + +private: + T* ptr_; +}; + +template +class WeakPtrOwner { +public: + explicit WeakPtrOwner(T* ptr) + : ptr_(std::make_shared>(ptr)) {} + + ~WeakPtrOwner() { + ptr_->unlink(); + } + + std::shared_ptr> get() { + return ptr_; + } + +private: + std::shared_ptr> ptr_; +}; + +#endif // WEAK_PTR_HH -- cgit v1.2.3-70-g09d2