wavelength 1.0.0
Loading...
Searching...
No Matches
ptr.h
Go to the documentation of this file.
1#pragma once
2
3#include "app/attachment.h"
4
15template <typename T>
16class Ptr {
17public:
30 Ptr() : mObject(nullptr) {
31 }
32
60 explicit Ptr(T *pObject) : mObject(pObject) {
61 if (pObject != nullptr) {
62 pObject->AddRef();
63 }
64 }
65
77 Ptr(const Ptr &other) : mObject(other.mObject) {
78 if (mObject != nullptr) {
79 mObject->AddRef();
80 }
81 }
82
110 if (mObject != nullptr) {
111 mObject->Release();
112 }
113 }
114
129 Ptr &operator=(const Ptr &other) {
130 if (this != &other) {
131 if (mObject != nullptr) {
132 mObject->Release();
133 }
134 mObject = other.mObject;
135 if (mObject != nullptr) {
136 mObject->AddRef();
137 }
138 }
139 return *this;
140 }
141
173 T *Get() const {
174 return mObject;
175 }
176
202 T *operator->() const {
203 return mObject;
204 }
205
206private:
207 T *mObject;
208};
~Ptr()
Give back the reference.
Definition ptr.h:109
Ptr(const Ptr &other)
Take another reference to the object of another owner.
Definition ptr.h:77
T * Get() const
Report the object.
Definition ptr.h:173
Ptr(T *pObject)
Take a reference to an object.
Definition ptr.h:60
T * operator->() const
Report the object for a member access.
Definition ptr.h:202
Ptr()
Construct a null owner.
Definition ptr.h:30
Ptr & operator=(const Ptr &other)
Take a reference to the object of another owner and give back the current one.
Definition ptr.h:129