vrshoot
annotate libs/assimp/boost/scoped_ptr.hpp @ 2:334d17aed7de
visual studio project files
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 02 Feb 2014 18:36:38 +0200 |
parents | |
children |
rev | line source |
---|---|
nuclear@0 | 1 |
nuclear@0 | 2 #ifndef __AI_BOOST_SCOPED_PTR_INCLUDED |
nuclear@0 | 3 #define __AI_BOOST_SCOPED_PTR_INCLUDED |
nuclear@0 | 4 |
nuclear@0 | 5 #ifndef BOOST_SCOPED_PTR_HPP_INCLUDED |
nuclear@0 | 6 |
nuclear@0 | 7 namespace boost { |
nuclear@0 | 8 |
nuclear@0 | 9 // small replacement for boost::scoped_ptr |
nuclear@0 | 10 template <class T> |
nuclear@0 | 11 class scoped_ptr |
nuclear@0 | 12 { |
nuclear@0 | 13 public: |
nuclear@0 | 14 |
nuclear@0 | 15 // provide a default construtctor |
nuclear@0 | 16 scoped_ptr() |
nuclear@0 | 17 : ptr(0) |
nuclear@0 | 18 { |
nuclear@0 | 19 } |
nuclear@0 | 20 |
nuclear@0 | 21 // construction from an existing heap object of type T |
nuclear@0 | 22 scoped_ptr(T* _ptr) |
nuclear@0 | 23 : ptr(_ptr) |
nuclear@0 | 24 { |
nuclear@0 | 25 } |
nuclear@0 | 26 |
nuclear@0 | 27 // automatic destruction of the wrapped object at the |
nuclear@0 | 28 // end of our lifetime |
nuclear@0 | 29 ~scoped_ptr() |
nuclear@0 | 30 { |
nuclear@0 | 31 delete ptr; |
nuclear@0 | 32 } |
nuclear@0 | 33 |
nuclear@0 | 34 inline T* get() const |
nuclear@0 | 35 { |
nuclear@0 | 36 return ptr; |
nuclear@0 | 37 } |
nuclear@0 | 38 |
nuclear@0 | 39 inline operator T*() |
nuclear@0 | 40 { |
nuclear@0 | 41 return ptr; |
nuclear@0 | 42 } |
nuclear@0 | 43 |
nuclear@0 | 44 inline T* operator-> () |
nuclear@0 | 45 { |
nuclear@0 | 46 return ptr; |
nuclear@0 | 47 } |
nuclear@0 | 48 |
nuclear@0 | 49 inline void reset (T* t = 0) |
nuclear@0 | 50 { |
nuclear@0 | 51 delete ptr; |
nuclear@0 | 52 ptr = t; |
nuclear@0 | 53 } |
nuclear@0 | 54 |
nuclear@0 | 55 void swap(scoped_ptr & b) |
nuclear@0 | 56 { |
nuclear@0 | 57 std::swap(ptr, b.ptr); |
nuclear@0 | 58 } |
nuclear@0 | 59 |
nuclear@0 | 60 private: |
nuclear@0 | 61 |
nuclear@0 | 62 // encapsulated object pointer |
nuclear@0 | 63 T* ptr; |
nuclear@0 | 64 |
nuclear@0 | 65 }; |
nuclear@0 | 66 |
nuclear@0 | 67 template<class T> |
nuclear@0 | 68 inline void swap(scoped_ptr<T> & a, scoped_ptr<T> & b) |
nuclear@0 | 69 { |
nuclear@0 | 70 a.swap(b); |
nuclear@0 | 71 } |
nuclear@0 | 72 |
nuclear@0 | 73 } // end of namespace boost |
nuclear@0 | 74 |
nuclear@0 | 75 #else |
nuclear@0 | 76 # error "scoped_ptr.h was already included" |
nuclear@0 | 77 #endif |
nuclear@0 | 78 #endif // __AI_BOOST_SCOPED_PTR_INCLUDED |
nuclear@0 | 79 |