Bromeon
SmartPtr/MovedPtr.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
00023 //
00025 
00028 
00029 #ifndef THOR_MOVEDPTR_HPP
00030 #define THOR_MOVEDPTR_HPP
00031 
00032 #include <Thor/Detail/MovedPtrRef.hpp>
00033 #include <Thor/Detail/SmartPtrImpl.hpp>
00034 #include <Thor/Config.hpp>
00035 
00036 #include <algorithm>
00037 #include <cassert>
00038 
00039 
00040 namespace thor
00041 {
00042 
00045 
00059 template <typename T>
00060 class MovedPtr
00061 {
00062     // ---------------------------------------------------------------------------------------------------------------------------
00063     // Public member functions
00064     public:
00067                                     MovedPtr();
00068 
00072         explicit                    MovedPtr(T* pointer);
00073         
00076                                     MovedPtr(MovedPtr& origin);
00077                                             
00080                                     ~MovedPtr();
00081         
00084         MovedPtr&                   operator= (MovedPtr& origin);
00085         
00088         void                        Swap(MovedPtr& other);
00089         
00093         void                        Reset();
00094             
00099         void                        Reset(T* pointer);
00100         
00104         T*                          Release();
00105         
00111                                     operator THOR_DETAIL SafeBool() const;
00112 
00115         T&                          operator* () const;
00116         
00119         T*                          operator-> () const;
00120         
00123         T*                          Get() const;
00124         
00125         
00126     // ---------------------------------------------------------------------------------------------------------------------------
00127     // Implementation details
00128     public:
00129         // Constructor to allow interaction with function arguments and return values
00130                                     MovedPtr(detail::MovedPtrRef<T> ref);
00131     
00132         // Assignment operator to allow interaction with function arguments and return values
00133         MovedPtr&                   operator= (detail::MovedPtrRef<T> ref);
00134                                 
00135         // Conversion operator to allow interaction with function arguments and return values
00136                                     operator detail::MovedPtrRef<T> ();
00137 
00138 
00139     // ---------------------------------------------------------------------------------------------------------------------------
00140     // Private variables
00141     private:
00142         detail::SmartPtrImpl<T>     mImpl;
00143         
00144     
00145     // ---------------------------------------------------------------------------------------------------------------------------
00146     // Friends
00147     friend detail::SmartPtrImpl<T>& detail::GetImpl<T>(MovedPtr<T>& smartPointer);
00148 };
00149 
00153 template <typename T>
00154 void swap(MovedPtr<T>& lhs, MovedPtr<T>& rhs);
00155 
00157 
00158 } // namespace thor
00159 
00160 #include <Thor/Detail/MovedPtr.inl>
00161 #endif // THOR_MOVEDPTR_HPP