Ariles
Loading...
Searching...
No Matches
pointer.h
Go to the documentation of this file.
1/**
2 @file
3 @author Alexander Sherikov
4 @copyright 2018 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
5 (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6
7 @brief
8*/
9
10#pragma once
11
12#include <memory>
13#include "../internal/helpers.h"
14
15
16namespace ariles2
17{
18 template <class t_Value>
19 class PointerHandler<std::shared_ptr<t_Value>>
20 {
21 public:
22 using Pointer = std::shared_ptr<t_Value>;
23 using Value = t_Value;
24
25
26 public:
27 static void allocate(Pointer &ptr)
28 {
29 ptr = std::make_shared<t_Value>();
30 }
31
32 static void reset(Pointer &ptr)
33 {
34 ptr.reset();
35 }
36
37 static bool isNull(const Pointer &ptr)
38 {
39 return (nullptr == ptr);
40 }
41 };
42
43
44 template <class t_Value>
45 class PointerHandler<std::unique_ptr<t_Value>>
46 {
47 public:
48 using Pointer = std::unique_ptr<t_Value>;
49 using Value = t_Value;
50
51
52 public:
53 static void allocate(Pointer &ptr)
54 {
55 ptr.reset(new t_Value);
56 }
57
58 static void reset(Pointer &ptr)
59 {
60 ptr.reset();
61 }
62
63 static bool isNull(const Pointer &ptr)
64 {
65 return (nullptr == ptr);
66 }
67 };
68} // namespace ariles2
69
70#define ARILES2_POINTER_TYPE std::shared_ptr
72
73
74#define ARILES2_POINTER_TYPE std::unique_ptr
static bool isNull(const Pointer &ptr)
Definition pointer.h:37
static bool isNull(const Pointer &ptr)
Definition pointer.h:63