summaryrefslogtreecommitdiff
path: root/utility
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-01-17 19:36:30 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-01-17 22:16:48 +0000
commit0bf4ad9e4a9e1c97e92aa23a365405dfef89bd7c (patch)
tree68a80976a247836bbb1eecc835af437e3489fbb7 /utility
parentFirst cut modernizing and sanitizing (diff)
downloadilt-0bf4ad9e4a9e1c97e92aa23a365405dfef89bd7c.tar.bz2
ilt-0bf4ad9e4a9e1c97e92aa23a365405dfef89bd7c.tar.xz
ilt-0bf4ad9e4a9e1c97e92aa23a365405dfef89bd7c.zip
Big reshuffle
Fixes code quality warnings now picked up.
Diffstat (limited to 'utility')
-rw-r--r--utility/ptr.hpp25
-rw-r--r--utility/special_members.hpp12
2 files changed, 37 insertions, 0 deletions
diff --git a/utility/ptr.hpp b/utility/ptr.hpp
new file mode 100644
index 0000000..b92b63e
--- /dev/null
+++ b/utility/ptr.hpp
@@ -0,0 +1,25 @@
+#ifndef PTR_H
+#define PTR_H
+
+#include <memory>
+
+template<typename Obj> class wrapped_ptr : public std::unique_ptr<Obj, void (*)(Obj *)> {
+public:
+ using std::unique_ptr<Obj, void (*)(Obj *)>::unique_ptr;
+ wrapped_ptr() : std::unique_ptr<Obj, void (*)(Obj *)> {{}, {}} { }
+
+ inline
+ operator Obj *() const
+ {
+ return this->get();
+ }
+
+ template<typename... Args, typename... Params>
+ static auto
+ create(Obj * (*factory)(Args...), void (*deleter)(Obj *), Params &&... params)
+ {
+ return wrapped_ptr<Obj> {factory(std::forward<Params>(params)...), deleter};
+ }
+};
+
+#endif
diff --git a/utility/special_members.hpp b/utility/special_members.hpp
new file mode 100644
index 0000000..f396813
--- /dev/null
+++ b/utility/special_members.hpp
@@ -0,0 +1,12 @@
+#ifndef SPECIAL_MEMBERS_H
+#define SPECIAL_MEMBERS_H
+
+#define NO_COPY(TYPE) \
+ TYPE(const TYPE &) = delete; \
+ void operator=(const TYPE &) = delete
+
+#define NO_MOVE(TYPE) \
+ TYPE(TYPE &&) = delete; \
+ void operator=(TYPE &&) = delete
+
+#endif