VitroIO SDK
Software development kit for Vitro Shard.
Loading...
Searching...
No Matches
scoped_ptr.h
Go to the documentation of this file.
1#ifndef VITROIO_SDK_SCOPED_PTR_H
2#define VITROIO_SDK_SCOPED_PTR_H
3
4#include <mbed.h>
5
6namespace vitroio
7{
8
9namespace sdk
10{
11
12namespace impl
13{
14
15template <typename T>
16class ScopedPtr : private NonCopyable< ScopedPtr<T> >
17{
18public:
19 typedef Callback<void(void*)> Deleter;
20
21 explicit ScopedPtr(T* ptr, Deleter deleter = Deleter(NULL)) :
22 ptr_(ptr),
23 deleter_(deleter)
24 {}
25
27 {
28 if(!ptr_){
29 return;
30 }
31
32 if(deleter_){
33 deleter_(ptr_);
34 }
35 else{
36 delete ptr_;
37 }
38 }
39
40 T* get()
41 {
42 return ptr_;
43 }
44
45 const T* get() const
46 {
47 return ptr_;
48 }
49
51 return ptr_;
52 }
53
54 T& operator*() {
55 return *ptr_;
56 }
57
58 operator bool() const
59 {
60 return ptr_;
61 }
62
63private:
64 T* ptr_;
65 Deleter deleter_;
66};
67
68} // namespace impl
69
70} // namespace sdk
71
72} // namespace vitroio
73
74#endif // VITROIO_SDK_SCOPED_PTR_H
Definition: scoped_ptr.h:17
T * operator->()
Definition: scoped_ptr.h:50
const T * get() const
Definition: scoped_ptr.h:45
~ScopedPtr()
Definition: scoped_ptr.h:26
T & operator*()
Definition: scoped_ptr.h:54
Callback< void(void *)> Deleter
Definition: scoped_ptr.h:19
ScopedPtr(T *ptr, Deleter deleter=Deleter(NULL))
Definition: scoped_ptr.h:21
T * get()
Definition: scoped_ptr.h:40
The namespace contains all of components of vitro-shard-sdk and components based on the sdk....
Definition: can_layer.h:9