summaryrefslogtreecommitdiff
path: root/lib/stdTypeDefs.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stdTypeDefs.h')
-rw-r--r--lib/stdTypeDefs.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/stdTypeDefs.h b/lib/stdTypeDefs.h
new file mode 100644
index 0000000..317cdb3
--- /dev/null
+++ b/lib/stdTypeDefs.h
@@ -0,0 +1,45 @@
+#pragma once
+
+#include <memory>
+#include <vector>
+
+template<typename T> struct AnyPtr {
+ // cppcheck-suppress noExplicitConstructor
+ AnyPtr(T * p) : ptr {p} { }
+ // cppcheck-suppress noExplicitConstructor
+ template<typename S> AnyPtr(const S & p) : ptr {p.get()} { }
+ auto
+ get() const
+ {
+ return ptr;
+ }
+ auto
+ operator->() const
+ {
+ return ptr;
+ }
+ auto &
+ operator*() const
+ {
+ return *ptr;
+ }
+
+private:
+ T * ptr;
+};
+
+template<typename T> struct StdTypeDefs {
+ using AnyPtr = ::AnyPtr<T>;
+ using AnyCPtr = ::AnyPtr<const T>;
+ using Ptr = std::shared_ptr<T>;
+ using CPtr = std::shared_ptr<const T>;
+ using WPtr = std::weak_ptr<const T>;
+ using Collection = std::vector<Ptr>;
+ using CCollection = std::vector<CPtr>;
+ using WCollection = std::vector<WPtr>;
+};
+
+template<typename T> struct ConstTypeDefs {
+ using Ptr = std::shared_ptr<const T>;
+ using Collection = std::vector<Ptr>;
+};