instantiation_policy.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_INSTANTIATION_POLICY_HH
00021 #define PALUDIS_GUARD_PALUDIS_INSTANTIATION_POLICY_HH 1
00022 
00023 #include <paludis/util/attributes.hh>
00024 
00025 /** \file
00026  * InstantiationPolicy patterns.
00027  *
00028  * \ingroup g_oo
00029  *
00030  * \section Examples
00031  *
00032  * - None at this time.
00033  */
00034 
00035 namespace paludis
00036 {
00037     /**
00038      * Instantiation policies for paludis::InstantiationPolicy.
00039      *
00040      * \ingroup g_oo
00041      */
00042     namespace instantiation_method
00043     {
00044         /**
00045          * Cannot be copied or assigned to.
00046          *
00047          * \ingroup g_oo
00048          */
00049         struct NonCopyableTag;
00050 
00051         /**
00052          * Cannot be instantiated
00053          *
00054          * \ingroup g_oo
00055          */
00056         struct NonInstantiableTag;
00057 
00058         /**
00059          * Single instance.
00060          *
00061          * \ingroup g_oo
00062          */
00063         struct SingletonTag;
00064     }
00065 
00066     /**
00067      * InstantiationPolicy is used to specify behaviour of classes that have
00068      * something other than the default C++ instantiation behaviour.
00069      *
00070      * \ingroup g_oo
00071      */
00072     template <typename OurType_, typename InstantiationMethodTag_>
00073     struct InstantiationPolicy;
00074 
00075     /**
00076      * InstantiationPolicy: specialisation for classes that cannot be copied
00077      * or assigned to.
00078      *
00079      * \ingroup g_oo
00080      * \nosubgrouping
00081      */
00082     template<typename OurType_>
00083     class PALUDIS_VISIBLE InstantiationPolicy<OurType_, instantiation_method::NonCopyableTag>
00084     {
00085         private:
00086             InstantiationPolicy(const InstantiationPolicy &);
00087             const InstantiationPolicy & operator= (const InstantiationPolicy &);
00088 
00089         public:
00090             InstantiationPolicy()
00091             {
00092             }
00093     };
00094 
00095     /**
00096      * InstantiationPolicy: specialisation for classes that cannot be created.
00097      *
00098      * \ingroup g_oo
00099      * \nosubgrouping
00100      */
00101     template<typename OurType_>
00102     class InstantiationPolicy<OurType_, instantiation_method::NonInstantiableTag>
00103     {
00104         private:
00105             InstantiationPolicy(const InstantiationPolicy &);
00106             const InstantiationPolicy & operator= (const InstantiationPolicy &);
00107             InstantiationPolicy();
00108     };
00109 
00110     /**
00111      * InstantiationPolicy: specialisation for singleton classes that are
00112      * created as needed.
00113      *
00114      * \ingroup g_oo
00115      * \nosubgrouping
00116      */
00117     template<typename OurType_>
00118     class PALUDIS_VISIBLE InstantiationPolicy<OurType_, instantiation_method::SingletonTag>
00119     {
00120         private:
00121             InstantiationPolicy(const InstantiationPolicy &);
00122 
00123             const InstantiationPolicy & operator= (const InstantiationPolicy &);
00124 
00125             static OurType_ * * _get_instance_ptr();
00126 
00127             class DeleteOnDestruction;
00128             friend class DeleteOnDestruction;
00129 
00130             static void _delete(OurType_ * const p);
00131 
00132             class DeleteOnDestruction;
00133 
00134         protected:
00135             ///\name Basic operations
00136             ///\{
00137 
00138             InstantiationPolicy()
00139             {
00140             }
00141 
00142             ///\}
00143 
00144         public:
00145             ///\name Singleton operations
00146             ///\{
00147 
00148             /**
00149              * Fetch our instance.
00150              */
00151             static OurType_ * get_instance()
00152                 PALUDIS_ATTRIBUTE((warn_unused_result));
00153 
00154             /**
00155              * Destroy our instance.
00156              */
00157             static void destroy_instance();
00158 
00159             ///\}
00160     };
00161 }
00162 
00163 #endif

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