00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */ 00002 00003 /* 00004 * Copyright (c) 2007 David Leverton 00005 * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh 00006 * 00007 * This file is part of the Paludis package manager. Paludis is free software; 00008 * you can redistribute it and/or modify it under the terms of the GNU General 00009 * Public License version 2, as published by the Free Software Foundation. 00010 * 00011 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY 00012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00014 * details. 00015 * 00016 * You should have received a copy of the GNU General Public License along with 00017 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00018 * Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_CLONE_HH 00022 #define PALUDIS_GUARD_PALUDIS_UTIL_CLONE_HH 1 00023 00024 #include <paludis/util/attributes.hh> 00025 #include <tr1/memory> 00026 00027 /** \file 00028 * Declares the Cloneable class and helpers. 00029 * 00030 * \ingroup g_oo 00031 * 00032 * \section Examples 00033 * 00034 * - None at this time. 00035 */ 00036 00037 namespace paludis 00038 { 00039 /** 00040 * Base class for objects that can be cloned. 00041 * 00042 * \ingroup g_oo 00043 * \nosubgrouping 00044 */ 00045 template <typename T_> 00046 class PALUDIS_VISIBLE Cloneable 00047 { 00048 public: 00049 ///\name Cloning 00050 ///\{ 00051 00052 /** 00053 * Return a new copy of ourselves. 00054 */ 00055 virtual std::tr1::shared_ptr<T_> clone() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; 00056 00057 ///\} 00058 00059 ///\name Basic operations 00060 ///\{ 00061 00062 virtual ~Cloneable(); 00063 00064 ///\} 00065 }; 00066 00067 /** 00068 * Helper class implementing the clone() method using the copy 00069 * contructor. 00070 * 00071 * \ingroup g_oo 00072 * \nosubgrouping 00073 */ 00074 template <typename Base_, typename Child_> 00075 class PALUDIS_VISIBLE CloneUsingThis : 00076 public virtual Cloneable<Base_> 00077 { 00078 public: 00079 virtual std::tr1::shared_ptr<Base_> clone() const PALUDIS_ATTRIBUTE((warn_unused_result)); 00080 00081 ///\name Basic operations 00082 ///\{ 00083 00084 virtual ~CloneUsingThis(); 00085 00086 ///\} 00087 }; 00088 } 00089 00090 #endif 00091 00092