Bromeon
SmartPtr/MovedPtr.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2012 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 
00043 template <typename T, template <typename> class OwnershipPolicy>
00044 class CopiedPtr;
00045 
00048 
00065 template <typename T, template <typename> class OwnershipPolicy = DynamicCopy>
00066 class MovedPtr
00067 {
00068     // ---------------------------------------------------------------------------------------------------------------------------
00069     // Public member functions
00070     public:
00073                                     MovedPtr();
00074 
00080         template <typename U>
00081         explicit                    MovedPtr(U* pointer);
00082         
00085                                     MovedPtr(MovedPtr& origin);
00086                                             
00089                                     ~MovedPtr();
00090         
00093         MovedPtr&                   operator= (MovedPtr& origin);
00094         
00097         void                        Swap(MovedPtr& other);
00098         
00102         void                        Reset();
00103             
00110         template <typename U>
00111         void                        Reset(U* pointer);
00112         
00116         T*                          Release();
00117         
00123                                     operator THOR_DETAIL SafeBool() const;
00124 
00127         T&                          operator* () const;
00128         
00131         T*                          operator-> () const;
00132         
00135         T*                          Get() const;
00136         
00137         
00138     // ---------------------------------------------------------------------------------------------------------------------------
00139     // Implementation details
00140     public:
00141         // Constructor to allow interaction with function arguments and return values
00142                                     MovedPtr(detail::MovedPtrRef<T, OwnershipPolicy> ref);
00143     
00144         // Assignment operator to allow interaction with function arguments and return values
00145         MovedPtr&                   operator= (detail::MovedPtrRef<T, OwnershipPolicy> ref);
00146                                 
00147         // Conversion operator to allow interaction with function arguments and return values
00148                                     operator detail::MovedPtrRef<T, OwnershipPolicy> ();
00149 
00150 
00151     // ---------------------------------------------------------------------------------------------------------------------------
00152     // Private variables
00153     private:
00154         detail::SmartPtrImpl<T, OwnershipPolicy>    mImpl;
00155 
00156 
00157     // ---------------------------------------------------------------------------------------------------------------------------
00158     // Friends
00159     friend struct detail::SmartPtrAccessor;
00160 };
00161 
00171 template <typename T, template <typename> class OwnershipPolicy>
00172 MovedPtr<T, OwnershipPolicy> Copy(const MovedPtr<T, OwnershipPolicy>& origin);
00173 
00176 template <typename T, template <typename> class OwnershipPolicy>
00177 void swap(MovedPtr<T, OwnershipPolicy>& lhs, MovedPtr<T, OwnershipPolicy>& rhs);
00178 
00180 
00181 } // namespace thor
00182 
00183 #include <Thor/Detail/MovedPtr.inl>
00184 #endif // THOR_MOVEDPTR_HPP