Bromeon
SmartPtr/CopiedPtr.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_COPIEDPTR_HPP
00030 #define THOR_COPIEDPTR_HPP
00031 
00032 #include <Thor/SmartPtr/CopiedPtrPolicies.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 
00060 template <typename T, template <typename> class OwnershipPolicy>
00061 class CopiedPtr
00062 {
00063     // --------------------------------------------------------------------------------------------------------------------------------------
00064     // Public member functions
00065     public:
00068                                     CopiedPtr();
00069 
00075         template <typename U>
00076         explicit                    CopiedPtr(U* pointer);
00077                             
00082                                     CopiedPtr(const CopiedPtr& origin);
00083 
00087                                     ~CopiedPtr();
00088         
00092         CopiedPtr&                  operator= (const CopiedPtr& origin);
00093 
00096         void                        Swap(CopiedPtr& other);
00097         
00101         void                        Reset();
00102             
00109         template <typename U>
00110         void                        Reset(U* pointer);
00111         
00115         T*                          Release();
00116             
00122                                     operator THOR_DETAIL SafeBool() const;
00123 
00126         T&                          operator* () const;
00127         
00130         T*                          operator-> () const;
00131         
00134         T*                          Get() const;
00135         
00136 
00137     // ---------------------------------------------------------------------------------------------------------------------------
00138     // Private variables
00139     private:
00140         detail::SmartPtrImpl<T>     mImpl;
00141         T*                          (*mCopyFn)(const T*);
00142     
00143         
00144     // ---------------------------------------------------------------------------------------------------------------------------
00145     // Friends
00146     friend detail::SmartPtrImpl<T>& detail::GetImpl<T, CopiedPtr>(CopiedPtr& smartPointer);
00147 };
00148 
00151 template <typename T, template <typename> class OwnershipPolicy>
00152 void swap(CopiedPtr<T, OwnershipPolicy>& lhs, CopiedPtr<T, OwnershipPolicy>& rhs);
00153 
00155 
00156 } // namespace thor
00157 
00158 #include <Thor/Detail/CopiedPtr.inl>
00159 #endif // THOR_COPIEDPTR_HPP