1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     util_ScopedPointer.h
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 12449 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifdef __cplusplus
17 
18 #ifndef NN_UTIL_UTIL_SCOPEDPOINTER_H_
19 #define NN_UTIL_UTIL_SCOPEDPOINTER_H_
20 
21 #include <nn/util/util_NonCopyable.h>
22 
23 namespace nn {
24 namespace util {
25 
26 template <typename T>
27 class ScopedPointer : private nn::util::NonCopyable<ScopedPointer<T> >
28 {
29 private:
30     T* m_Ptr;
31 public:
ScopedPointer(T * ptr)32     ScopedPointer(T* ptr) : m_Ptr(ptr){};
~ScopedPointer()33     ~ScopedPointer()
34     {
35         delete m_Ptr;
36     }
37 
38     T& operator*() const
39     {
40         return *m_Ptr;
41     }
42 
43     T* operator->() const
44     {
45         return m_Ptr;
46     }
47 
Get()48     T* Get() const
49     {
50         return m_Ptr;
51     }
52 };
53 
54 template <void (*Deallocate)(void*)>
55 class ScopedUntypedPointer : private nn::util::NonCopyable<ScopedUntypedPointer<Deallocate> >
56 {
57 private:
58     void* m_Ptr;
59 public:
ScopedUntypedPointer(void * ptr)60     ScopedUntypedPointer(void* ptr) : m_Ptr(ptr){};
~ScopedUntypedPointer()61     ~ScopedUntypedPointer()
62     {
63         Deallocate(m_Ptr);
64     }
65 
Get()66     void* Get() const
67     {
68         return m_Ptr;
69     }
70 };
71 
72 }
73 }
74 
75 
76 #endif // #ifndef NN_UTIL_UTIL_SCOPEDPOINTER_H_
77 
78 #endif // __cplusplus
79