🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
ClonePtr.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "ScopedPtr.hpp"
25
26AST_NAMESPACE_BEGIN
27
36template<typename T>
37class ClonePtr: public ScopedPtr<T>
38{
39public:
40 ClonePtr() = default;
41 ClonePtr(const ClonePtr& other)
42 {
43 if(other.get())
44 this->m_pointer = other.get()->clone();
45 }
46 ClonePtr(ClonePtr&& other)
47 {
48 this->m_pointer = other.m_pointer;
49 other.m_pointer = nullptr;
50 }
51 ClonePtr& operator=(const ClonePtr& other)
52 {
53 if(other.get())
54 this->reset(other.get()->clone());
55 else
56 this->reset(nullptr);
57 return *this;
58 }
59 ClonePtr& operator=(ClonePtr&& other)
60 {
61 std::swap(this->m_pointer, other.m_pointer);
62 return *this;
63 }
64 ClonePtr& operator=(T* ptr)
65 {
66 this->reset(ptr);
67 return *this;
68 }
69};
70
73AST_NAMESPACE_END
作用域指针
克隆指针类
定义 ClonePtr.hpp:38
作用域指针类
定义 ScopedPtr.hpp:65