diff options
author | svoj@mysql.com <> | 2005-04-28 18:23:27 +0500 |
---|---|---|
committer | svoj@mysql.com <> | 2005-04-28 18:23:27 +0500 |
commit | c1fd1d6a5b6842d99fbbfabeb0598f2e92535f96 (patch) | |
tree | faf48fd8da1c6b1e9b69a5e89ebff26bb440b34b /extra/yassl/mySTL/memory.hpp | |
parent | 9c9149571d0fa42be28ec221277b382935cb0e82 (diff) | |
download | mariadb-git-c1fd1d6a5b6842d99fbbfabeb0598f2e92535f96.tar.gz |
WL#2286 Compile MySQL w/YASSL support
yaSSL-0.9.7 library bundled.
Diffstat (limited to 'extra/yassl/mySTL/memory.hpp')
-rw-r--r-- | extra/yassl/mySTL/memory.hpp | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/extra/yassl/mySTL/memory.hpp b/extra/yassl/mySTL/memory.hpp new file mode 100644 index 00000000000..4049ed80813 --- /dev/null +++ b/extra/yassl/mySTL/memory.hpp @@ -0,0 +1,127 @@ +/* mySTL memory.hpp + * + * Copyright (C) 2003 Sawtooth Consulting Ltd. + * + * This file is part of yaSSL. + * + * yaSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * yaSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +/* mySTL memory implements auto_ptr + * + */ + +#ifndef mySTL_MEMORY_HPP +#define mySTL_MEMORY_HPP + + +#ifdef _MSC_VER + // disable operator-> warning for builtins + #pragma warning(disable:4284) +#endif + + +namespace mySTL { + + +template<typename T> +struct auto_ptr_ref { + T* ptr_; + explicit auto_ptr_ref(T* p) : ptr_(p) {} +}; + + +template<typename T> +class auto_ptr { + T* ptr_; +public: + explicit auto_ptr(T* p = 0) : ptr_(p) {} + ~auto_ptr() + { + delete ptr_; + } + + + auto_ptr(auto_ptr& other) : ptr_(other.release()) {} + auto_ptr& operator=(auto_ptr& that) + { + if (this != &that) { + delete ptr_; + ptr_ = that.release(); + } + return *this; + } + + + T* operator->() const + { + return ptr_; + } + + T& operator*() const + { + return *ptr_; + } + + T* get() const + { + return ptr_; + } + + T* release() + { + T* tmp = ptr_; + ptr_ = 0; + return tmp; + } + + void reset(T* p = 0) + { + if (ptr_ != p) { + delete ptr_; + ptr_ = p; + } + } + + // auto_ptr_ref conversions + auto_ptr(auto_ptr_ref<T> ref) : ptr_(ref.ptr_) {} + + auto_ptr& operator=(auto_ptr_ref<T> ref) + { + if (this->ptr_ != ref.ptr_) { + delete ptr_; + ptr_ = ref.ptr_; + } + return *this; + } + + template<typename T2> + operator auto_ptr<T2>() + { + return auto_ptr<T2>(this->release()); + } + + template<typename T2> + operator auto_ptr_ref<T2>() + { + return auto_ptr_ref<T2>(this->release()); + } +}; + + +} // namespace mySTL + +#endif // mySTL_MEMORY_HPP |