summaryrefslogtreecommitdiffstats
path: root/Source/cmUVHandlePtr.h
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2019-04-23 17:37:26 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2019-04-25 16:03:08 (GMT)
commit8cfd25db711c22f9478e565a496145577df24d77 (patch)
tree4903ef06ec74137f44c375bbdd23fbbce9a99676 /Source/cmUVHandlePtr.h
parentc0e6b22d0a81c0e0dc1ee87366790882a3d54667 (diff)
downloadCMake-8cfd25db711c22f9478e565a496145577df24d77.zip
CMake-8cfd25db711c22f9478e565a496145577df24d77.tar.gz
CMake-8cfd25db711c22f9478e565a496145577df24d77.tar.bz2
cmUVHandlePtr: Add cm::uv_loop_ptr
Diffstat (limited to 'Source/cmUVHandlePtr.h')
-rw-r--r--Source/cmUVHandlePtr.h40
1 files changed, 39 insertions, 1 deletions
diff --git a/Source/cmUVHandlePtr.h b/Source/cmUVHandlePtr.h
index 992c429..c09e4bf 100644
--- a/Source/cmUVHandlePtr.h
+++ b/Source/cmUVHandlePtr.h
@@ -30,7 +30,45 @@
namespace cm {
/***
- * RAII class to simplify and insure the safe usage of uv_*_t types. This
+ * RAII class to simplify and ensure the safe usage of uv_loop_t. This includes
+ * making sure resources are properly freed.
+ */
+class uv_loop_ptr
+{
+protected:
+ std::shared_ptr<uv_loop_t> loop;
+
+public:
+ uv_loop_ptr(uv_loop_ptr const&) = delete;
+ uv_loop_ptr& operator=(uv_loop_ptr const&) = delete;
+ uv_loop_ptr(uv_loop_ptr&&) noexcept;
+ uv_loop_ptr& operator=(uv_loop_ptr&&) noexcept;
+
+ // Dtor and ctor need to be inline defined like this for default ctors and
+ // dtors to work. Some compilers do not like '= default' here.
+ uv_loop_ptr() {} // NOLINT(modernize-use-equals-default)
+ uv_loop_ptr(std::nullptr_t) {}
+ ~uv_loop_ptr() { this->reset(); }
+
+ int init(void* data = nullptr);
+
+ /**
+ * Properly close the handle if needed and sets the inner handle to nullptr
+ */
+ void reset();
+
+ /**
+ * Allow less verbose calling of uv_loop_* functions
+ * @return reinterpreted handle
+ */
+ operator uv_loop_t*();
+
+ uv_loop_t* get() const;
+ uv_loop_t* operator->() const noexcept;
+};
+
+/***
+ * RAII class to simplify and ensure the safe usage of uv_*_t types. This
* includes making sure resources are properly freed and contains casting
* operators which allow for passing into relevant uv_* functions.
*