vrshoot

view libs/assimp/boost/scoped_array.hpp @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
2 #ifndef __AI_BOOST_SCOPED_ARRAY_INCLUDED
3 #define __AI_BOOST_SCOPED_ARRAY_INCLUDED
5 #ifndef BOOST_SCOPED_ARRAY_HPP_INCLUDED
7 namespace boost {
9 // small replacement for boost::scoped_array
10 template <class T>
11 class scoped_array
12 {
13 public:
15 // provide a default construtctor
16 scoped_array()
17 : ptr(0)
18 {
19 }
21 // construction from an existing heap object of type T
22 scoped_array(T* _ptr)
23 : ptr(_ptr)
24 {
25 }
27 // automatic destruction of the wrapped object at the
28 // end of our lifetime
29 ~scoped_array()
30 {
31 delete[] ptr;
32 }
34 inline T* get()
35 {
36 return ptr;
37 }
39 inline T* operator-> ()
40 {
41 return ptr;
42 }
44 inline void reset (T* t = 0)
45 {
46 delete[] ptr;
47 ptr = t;
48 }
50 T & operator[](std::ptrdiff_t i) const
51 {
52 return ptr[i];
53 }
55 void swap(scoped_array & b)
56 {
57 std::swap(ptr, b.ptr);
58 }
60 private:
62 // encapsulated object pointer
63 T* ptr;
65 };
67 template<class T>
68 inline void swap(scoped_array<T> & a, scoped_array<T> & b)
69 {
70 a.swap(b);
71 }
73 } // end of namespace boost
75 #else
76 # error "scoped_array.h was already included"
77 #endif
78 #endif // __AI_BOOST_SCOPED_ARRAY_INCLUDED