Lugdunum  0.1.0
Resource.inl
Go to the documentation of this file.
1 // Shared ptr
2 
3 template <typename T>
4 constexpr Resource::SharedPtr<T>::SharedPtr(T* pointer) : _resource(pointer) {
5  if (_resource) {
6  // TODO: Increment reference counting
7  }
8 }
9 
10 template <typename T>
11 Resource::SharedPtr<T>::SharedPtr(const Resource::SharedPtr<T>& rhs) : _resource(rhs._resource) {
12  if (_resource) {
13  // TODO: Increment reference counting
14  }
15 }
16 
17 template <typename T>
18 Resource::SharedPtr<T>::SharedPtr(Resource::SharedPtr<T>&& rhs) : _resource(rhs._resource) {
19  rhs._resource = nullptr;
20 }
21 
22 template <typename T>
24  if (_resource) {
25  // TODO: Decrement reference counting
26  }
27 
28  _resource = rhs._resource;
29 
30  if (_resource) {
31  // TODO: Increment reference counting
32  }
33 
34  return *this;
35 }
36 
37 template <typename T>
39  if (_resource) {
40  // TODO: Decrement reference counting
41  }
42 
43  _resource = rhs._resource;
44  rhs._resource = nullptr;
45 
46  return *this;
47 }
48 
49 template <typename T>
51  if (_resource) {
52  // TODO: Decrement reference counting
53  }
54 
55  _resource = nullptr;
56 }
57 
58 template <typename T>
60  return _resource;
61 }
62 
63 template <typename T>
64 template <typename RhsT>
66  return dynamic_cast<T*>(rhs._resource);
67 }
68 
69 // Weak ptr
70 
71 template <typename T>
72 constexpr Resource::WeakPtr<T>::WeakPtr(T* pointer) : _resource(pointer) {}
73 
74 template <typename T>
75 constexpr Resource::WeakPtr<T>::WeakPtr(const SharedPtr<T>& rhs) : _resource(&(*rhs)) {}
76 
77 template <typename T>
79 
80 template <typename T>
82  rhs._resource = nullptr;
83 }
84 
85 template <typename T>
87  _resource = rhs._resource;
88 
89  return *this;
90 }
91 
92 template <typename T>
94  _resource = rhs._resource;
95  rhs._resource = nullptr;
96 
97  return *this;
98 }
99 
100 template <typename T>
102  _resource = nullptr;
103 }
104 
105 template <typename T>
107  // TODO: Check that the resource count is greater than 0
108  return _resource;
109 }
110 
111 template <typename T>
112 template <typename RhsT>
114  return dynamic_cast<T*>(rhs._resource);
115 }
116 
117 // Resource
118 
119 template <typename T>
121  return *_resource;
122 }
123 
124 template <typename T>
126  return _resource;
127 }
128 
130  return static_cast<Resource::Type>(_handle.type);
131 }
132 
134  return _handle;
135 }
136 
137 inline const std::string& Resource::getName() const {
138  return _name;
139 }
140 
141 inline void Resource::setName(const std::string &name) {
142  _name = name;
143 }
static WeakPtr< T > cast(const WeakPtr< RhsT > &rhs)
Dynamic casting of a WeakPtr to another one (RhsT to T)
WeakPtr< T > & operator=(const WeakPtr< T > &rhs)
SharedPtr< T > lock() const
Transforms a WeakPtr to a SharedPtr.
Definition: Resource.inl:106
void setName(const std::string &name)
Sets the name of the Resource.
Definition: Resource.inl:141
Dummy class for a weak ptr.
Definition: Resource.hpp:114
Handle getHandle() const
Returns the handle of the Resource.
Definition: Resource.inl:133
Dummy class for a shared pointer.
Definition: Resource.hpp:66
Type getType() const
Returns the type of the Resource.
Definition: Resource.inl:129
Handle of the resource. It contains informations such as the type and the index in the ResourceManage...
Definition: Resource.hpp:41
const std::string & getName() const
Gets the name of the Resource.
Definition: Resource.inl:137
Type
Type of the resource.
Definition: Resource.hpp:24
uint32_t type
Type of the ressource.
Definition: Resource.hpp:44