private_implementation_pattern.hh

Go to the documentation of this file.
00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
00005  *
00006  * This file is part of the Paludis package manager. Paludis is free software;
00007  * you can redistribute it and/or modify it under the terms of the GNU General
00008  * Public License version 2, as published by the Free Software Foundation.
00009  *
00010  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013  * details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef PALUDIS_GUARD_PALUDIS_PRIVATE_IMPLEMENTATION_PATTERN_HH
00021 #define PALUDIS_GUARD_PALUDIS_PRIVATE_IMPLEMENTATION_PATTERN_HH 1
00022 
00023 #include <paludis/util/instantiation_policy.hh>
00024 
00025 /** \file
00026  * Declarations for the PrivateImplementationPattern pattern.
00027  *
00028  * \ingroup g_oo
00029  *
00030  * \section Examples
00031  *
00032  * - None at this time.
00033  */
00034 
00035 namespace paludis
00036 {
00037     /**
00038      * Private implementation data, to be specialised for any class that
00039      * uses PrivateImplementationPattern.
00040      *
00041      * \ingroup g_oo
00042      */
00043     template <typename C_>
00044     struct Implementation;
00045 
00046     /**
00047      * A class descended from PrivateImplementationPattern has an associated
00048      * Implementation instance.
00049      *
00050      * \ingroup g_oo
00051      */
00052     template <typename C_>
00053     class PrivateImplementationPattern :
00054         private InstantiationPolicy<PrivateImplementationPattern<C_>, instantiation_method::NonCopyableTag>
00055     {
00056         protected:
00057             /**
00058              * Smart pointer to our implementation.
00059              *
00060              * \see PrivateImplementationPattern
00061              * \ingroup g_oo
00062              */
00063             class ImpPtr
00064             {
00065                 private:
00066                     ImpPtr(const ImpPtr &);
00067                     void operator= (const ImpPtr &);
00068                     Implementation<C_> * _ptr;
00069 
00070                 public:
00071                     ///\name Basic operations
00072                     ///\{
00073 
00074                     ImpPtr(Implementation<C_> * p);
00075 
00076                     ~ImpPtr();
00077 
00078                     ///\}
00079 
00080                     ///\name Dereference operators
00081                     //\{
00082 
00083                     inline Implementation<C_> * operator-> ();
00084 
00085                     inline const Implementation<C_> * operator-> () const;
00086 
00087                     Implementation<C_> * get();
00088                     const Implementation<C_> * get() const;
00089 
00090                     ///\}
00091 
00092                     /**
00093                      * Reset to a new Implementation.
00094                      */
00095                     void reset(Implementation<C_> * p);
00096             };
00097 
00098             /**
00099              * Pointer to our implementation data.
00100              */
00101             ImpPtr _imp;
00102 
00103         public:
00104             /**
00105              * Constructor.
00106              */
00107             explicit PrivateImplementationPattern(Implementation<C_> * i);
00108 
00109             ~PrivateImplementationPattern();
00110     };
00111 }
00112 
00113 template <typename C_>
00114 paludis::Implementation<C_> *
00115 paludis::PrivateImplementationPattern<C_>::ImpPtr::operator-> ()
00116 {
00117     return _ptr;
00118 }
00119 
00120 template <typename C_>
00121 const paludis::Implementation<C_> *
00122 paludis::PrivateImplementationPattern<C_>::ImpPtr::operator-> () const
00123 {
00124     return _ptr;
00125 }
00126 
00127 #endif

Generated on Mon Sep 21 10:36:08 2009 for paludis by  doxygen 1.5.4