Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
pointer.h
Go to the documentation of this file.
1#pragma once
2#include <utility>
3
4namespace sf
5{
6
13template<typename T>
14inline void delete_null(T& p)
15{
16 if (p)
17 {
18 delete p;
19 p = nullptr;
20 }
21}
22
26template<typename T>
27inline void delete_anull(T& p)
28{
29 if (p)
30 {
31 delete[] p;
32 p = nullptr;
33 }
34}
35
39template<typename T>
40inline void free_null(T& p)
41{
42 if (p)
43 {
44 free(p);
45 p = nullptr;
46 }
47}
48
57template<typename T>
58[[deprecated]] inline void swap_it(T& t1, T& t2)
59{
60 std::swap(t1, t2);
61}
62
67template<typename T>
69{
70 public:
71 explicit scope_delete(T* p)
72 {
73 P = p;
74 }
75
77 {
78 delete_null(P);
79 }
80
81 inline void disable_delete()
82 {
83 P = nullptr;
84 }
85
86 private:
87 T* P;
88};
89
94template<typename T>
96{
97 public:
98 explicit scope_free(T* p)
99 {
100 P = p;
101 }
102
104 {
105 free_null(P);
106 }
107
108 inline void disable_free()
109 {
110 P = nullptr;
111 }
112
113 private:
114 T* P;
115};
116
122template<typename T>
123inline T& null_ref()
124{
125 return (*(static_cast<T*>(nullptr)));
126}
127
128template<typename T>
129inline bool not_ref_null(T& r)
130{
131 return &r == nullptr;
132}
133
134}// namespace sf
Deletes the pointer of type T allocated by 'new' when this instance goes out of scope.
Definition pointer.h:69
void disable_delete()
Definition pointer.h:81
scope_delete(T *p)
Definition pointer.h:71
~scope_delete()
Definition pointer.h:76
Frees the pointer of type T allocated by 'malloc' when this instance goes out of scope.
Definition pointer.h:96
void disable_free()
Definition pointer.h:108
scope_free(T *p)
Definition pointer.h:98
~scope_free()
Definition pointer.h:103
Definition Application.h:10
bool not_ref_null(T &r)
Definition pointer.h:129
void swap_it(T &t1, T &t2)
Swaps the passed two arguments of any type.
Definition pointer.h:58
void delete_null(T &p)
Deletes object and clears pointer.
Definition pointer.h:14
void free_null(T &p)
Template function freeing a pointer previous allocated by 'malloc' when the pointer is non-null and a...
Definition pointer.h:40
T & null_ref()
Definition pointer.h:123
void delete_anull(T &p)
Deletes an array previous allocated by 'new[]' when the pointer is non-null and also nulls the passed...
Definition pointer.h:27