diff options
author | Brad King <brad.king@kitware.com> | 2006-03-16 21:04:05 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2006-03-16 21:04:05 (GMT) |
commit | 68ad66444b92f9db60cbd59bb3c91e5dec756651 (patch) | |
tree | 716c01b79cc223ce2b054939ff098662357d27c9 /Source/kwsys | |
parent | 779851f213b82869e975c0189030d5a966b6a60d (diff) | |
download | CMake-68ad66444b92f9db60cbd59bb3c91e5dec756651.zip CMake-68ad66444b92f9db60cbd59bb3c91e5dec756651.tar.gz CMake-68ad66444b92f9db60cbd59bb3c91e5dec756651.tar.bz2 |
ENH: Adding auto_ptr to KWSys to provide a conforming version everywhere.
Diffstat (limited to 'Source/kwsys')
-rw-r--r-- | Source/kwsys/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Source/kwsys/auto_ptr.hxx.in | 78 |
2 files changed, 82 insertions, 1 deletions
diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index c8f624f..76e153a 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -412,7 +412,10 @@ ENDFOREACH(header) # selected components. Initialize with required components. SET(KWSYS_CLASSES) SET(KWSYS_H_FILES Configure SharedForward) -SET(KWSYS_HXX_FILES Configure String hashtable hash_fun hash_map hash_set) +SET(KWSYS_HXX_FILES Configure String + hashtable hash_fun hash_map hash_set + auto_ptr + ) # Enforce component dependencies. IF(KWSYS_USE_SystemTools) diff --git a/Source/kwsys/auto_ptr.hxx.in b/Source/kwsys/auto_ptr.hxx.in new file mode 100644 index 0000000..90e8c86 --- /dev/null +++ b/Source/kwsys/auto_ptr.hxx.in @@ -0,0 +1,78 @@ +/*========================================================================= + + Program: KWSys - Kitware System Library + Module: $RCSfile$ + + Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef @KWSYS_NAMESPACE@_auto_ptr_hxx +#define @KWSYS_NAMESPACE@_auto_ptr_hxx + +#if !((defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)) + +// Use the conforming implementation provided by the compiler. + +#include <@KWSYS_NAMESPACE@/stl/memory> + +namespace @KWSYS_NAMESPACE@ +{ + +using @KWSYS_NAMESPACE@_stl::auto_ptr; + +} + +#else + +// This compiler does not have a conforming implementation. Use our +// own. + +namespace @KWSYS_NAMESPACE@ +{ + +// C++98 Standard Section 20.4.5 - Template class auto_ptr. +template <class X> +class auto_ptr +{ + template <class Y> struct auto_ptr_ref + { + auto_ptr<Y>& p_; + explicit auto_ptr_ref(auto_ptr<Y>& p): p_(p) {} + }; + X* x_; +public: + typedef X element_type; + + template <class Y> + auto_ptr(auto_ptr<Y>& a) throw(): x_(a.release()) {} + template <class Y> + auto_ptr& operator=(auto_ptr<Y>& a) throw() + { reset(a.release()); return *this; } + + explicit auto_ptr(X* p=0) throw(): x_(p) {} + auto_ptr(auto_ptr& a) throw(): x_(a.release()) {} + auto_ptr& operator=(auto_ptr& a) throw() { reset(a.release()); return *this; } + ~auto_ptr() throw() { delete get(); } + + X& operator*() const throw() { return *get(); } + X* operator->() const throw() { return get(); } + X* get() const throw() { return x_; } + X* release() throw() { X* x = x_; x_ = 0; return x; } + void reset(X* p=0) throw() { if(get() != p) { delete get(); x_ = p; } } + + auto_ptr(auto_ptr_ref<X> r) throw(): x_(r.p_.release()) {} + template <class Y> operator auto_ptr_ref<Y>() throw() { return *this; } + template <class Y> operator auto_ptr<Y>() throw() { return release(); } + auto_ptr& operator=(auto_ptr_ref<X> r) throw() { x_ = r.p_.release(); return *this; } +}; + +} // namespace @KWSYS_NAMESPACE@ + +#endif + +#endif |