summaryrefslogtreecommitdiff
path: root/lib/stdTypeDefs.h
blob: 38ebe0b8c70225dcf6d55a49498eb6554cc3d246 (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
50
51
52
53
54
55
56
57
58
59
60
61
#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;
	}

	// NOLINTNEXTLINE(hicpp-explicit-conversions)
	operator bool() const
	{
		return ptr != nullptr;
	}

	bool
	operator!() const
	{
		return ptr == nullptr;
	}

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>;
};