summaryrefslogtreecommitdiff
path: root/lib/stdTypeDefs.h
blob: beab630f3ce5f2d70faa660f80b6e6693aaaf987 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#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>;
};