mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / extra / yassl / taocrypt / mySTL / memory_array.hpp
bloba044498cd9864f53ce1e3604b5f5c72609262a1a
1 /*
2 Copyright (C) 2000-2007 MySQL AB
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to the
15 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
16 MA 02110-1301 USA.
20 /* mySTL memory_arry implements auto_array
24 #ifndef mySTL_MEMORY_ARRAY_HPP
25 #define mySTL_MEMORY_ARRAY_HPP
28 #ifdef _MSC_VER
29 // disable operator-> warning for builtins
30 #pragma warning(disable:4284)
31 #endif
34 namespace mySTL {
37 template<typename T>
38 struct auto_array_ref {
39 T* ptr_;
40 explicit auto_array_ref(T* p) : ptr_(p) {}
44 template<typename T>
45 class auto_array {
46 T* ptr_;
48 void Destroy()
50 #ifdef YASSL_LIB
51 yaSSL::ysArrayDelete(ptr_);
52 #else
53 TaoCrypt::tcArrayDelete(ptr_);
54 #endif
56 public:
57 explicit auto_array(T* p = 0) : ptr_(p) {}
59 ~auto_array()
61 Destroy();
65 auto_array(auto_array& other) : ptr_(other.release()) {}
67 auto_array& operator=(auto_array& that)
69 if (this != &that) {
70 Destroy();
71 ptr_ = that.release();
73 return *this;
77 T* operator->() const
79 return ptr_;
82 T& operator*() const
84 return *ptr_;
87 T* get() const
89 return ptr_;
92 T* release()
94 T* tmp = ptr_;
95 ptr_ = 0;
96 return tmp;
99 void reset(T* p = 0)
101 if (ptr_ != p) {
102 Destroy();
103 ptr_ = p;
107 // auto_array_ref conversions
108 auto_array(auto_array_ref<T> ref) : ptr_(ref.ptr_) {}
110 auto_array& operator=(auto_array_ref<T> ref)
112 if (this->ptr_ != ref.ptr_) {
113 Destroy();
114 ptr_ = ref.ptr_;
116 return *this;
119 template<typename T2>
120 operator auto_array<T2>()
122 return auto_array<T2>(this->release());
125 template<typename T2>
126 operator auto_array_ref<T2>()
128 return auto_array_ref<T2>(this->release());
133 } // namespace mySTL
135 #endif // mySTL_MEMORY_ARRAY_HPP