summaryrefslogtreecommitdiff
path: root/src/common/memory.hpp
blob: de72d80d577f7ab100e3c7b96398208a5fb8e91c (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
#pragma once

#include <stddef.h>

namespace common
{

template <typename memType>
memType *malloc_s(unsigned int size);

template <class Target>
class UniquePtr
{
public:
	explicit UniquePtr() = default;
	explicit UniquePtr(Target *target);

	// Move constructor
	UniquePtr(UniquePtr &&unique_ptr) noexcept;

	// Move assignment operator
	UniquePtr &operator=(UniquePtr &&unique_ptr) noexcept;

	// Disable the copy constructor
	UniquePtr(const UniquePtr &unique_ptr) = delete;

	// Disable the copy assignment operator
	UniquePtr &operator=(const UniquePtr &unique_ptr) = delete;

	~UniquePtr();

	Target operator*() const;
	Target *operator->() const;

private:
	Target *_target = nullptr;
};

template <typename Target, typename... Args>
UniquePtr<Target> make_unique(Args... args);

} // namespace common

#include "memory.tpp"