lu_policy.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00031 
00032 // Permission to use, copy, modify, sell, and distribute this software
00033 // is hereby granted without fee, provided that the above copyright
00034 // notice appears in all copies, and that both that copyright notice and
00035 // this permission notice appear in supporting documentation. None of
00036 // the above authors, nor IBM Haifa Research Laboratories, make any
00037 // representation about the suitability of this software for any
00038 // purpose. It is provided "as is" without express or implied warranty.
00039 
00045 #ifndef LU_POLICY_HPP
00046 #define LU_POLICY_HPP
00047 
00048 namespace pb_assoc
00049 {
00050   struct move_to_front_lu_metadata
00051   { };
00052 
00053 #define PB_ASSOC_CLASS_T_DEC \
00054     template<typename Metadata_Reference>
00055 
00056 #define PB_ASSOC_CLASS_C_DEC \
00057     move_to_front_lu_policy<Metadata_Reference>
00058 
00059   template<typename Metadata_Reference = 
00060            std::allocator<move_to_front_lu_metadata>::reference>
00061     class move_to_front_lu_policy
00062     {
00063     public:
00064       void
00065       swap(PB_ASSOC_CLASS_C_DEC& r_other);
00066       
00067     protected:
00068       typedef move_to_front_lu_metadata metadata_type;
00069       
00070       typedef Metadata_Reference metadata_reference;
00071       
00072       metadata_type
00073       operator()() const;
00074       
00075       inline bool
00076       operator()(metadata_reference r_data) const;
00077     };
00078 
00079 #include <ext/pb_assoc/detail/lu_policy/mtf_lu_policy_imp.hpp>
00080 
00081 #undef PB_ASSOC_CLASS_T_DEC
00082 
00083 #undef PB_ASSOC_CLASS_C_DEC
00084 
00085   template<typename Size_Type>
00086     class counter_lu_policy_base;
00087 
00088   template<typename Size_Type = size_t>
00089     class counter_lu_metadata
00090     {
00091     public:
00092       typedef Size_Type size_type;
00093 
00094   private:
00095       counter_lu_metadata(size_type init_count) : m_count(init_count)
00096       { }
00097       
00098       mutable size_type m_count;
00099       
00100       friend class counter_lu_policy_base<Size_Type>;
00101     };
00102 
00103   template<typename Size_Type>
00104     class counter_lu_policy_base;
00105 
00106 #define PB_ASSOC_CLASS_T_DEC \
00107     template<typename Size_Type>
00108 
00109 #define PB_ASSOC_CLASS_C_DEC \
00110     counter_lu_policy_base<Size_Type>
00111 
00112   template<typename Size_Type>
00113     class counter_lu_policy_base
00114     {
00115     protected:
00116       typedef Size_Type size_type;
00117       
00118     counter_lu_metadata<Size_Type>
00119     operator()(size_type max_size) const;
00120 
00121     template<typename Metadata_Reference>
00122       bool
00123       operator()(Metadata_Reference r_data, size_type m_max_count) const;
00124     };
00125 
00126 #include <ext/pb_assoc/detail/lu_policy/counter_lu_metadata_imp.hpp>
00127 
00128 #undef PB_ASSOC_CLASS_T_DEC
00129 
00130 #undef PB_ASSOC_CLASS_C_DEC
00131 
00132 #define PB_ASSOC_CLASS_T_DEC \
00133     template<typename Size_Type, typename Metadata_Reference>
00134 
00135 #define PB_ASSOC_CLASS_C_DEC \
00136     counter_lu_policy<Size_Type, Metadata_Reference>
00137 
00138   template<typename Size_Type = size_t,
00139        typename Metadata_Reference =
00140        typename std::allocator<counter_lu_metadata<Size_Type> >::reference>
00141     class counter_lu_policy : private counter_lu_policy_base<Size_Type>
00142     {
00143     public:
00144       typedef Size_Type size_type;
00145       
00146       counter_lu_policy(size_type max_count = 5);
00147       
00148       void
00149       swap(PB_ASSOC_CLASS_C_DEC& r_other);
00150       
00151       inline
00152       size_type
00153       get_max_count() const;
00154       
00155     protected:
00156       
00157       typedef counter_lu_metadata< Size_Type> metadata_type;
00158       
00159       typedef Metadata_Reference metadata_reference;
00160       
00161       metadata_type
00162       operator()() const;
00163       
00164       bool
00165       operator()(metadata_reference r_data) const;
00166       
00167     private:
00168       typedef counter_lu_policy_base< Size_Type> my_base;
00169       
00170       size_type m_max_count;
00171     };
00172 
00173 #include <ext/pb_assoc/detail/lu_policy/counter_lu_policy_imp.hpp>
00174 
00175 #undef PB_ASSOC_CLASS_T_DEC
00176 
00177 #undef PB_ASSOC_CLASS_C_DEC
00178 
00179 } // namespace pb_assoc
00180 
00181 #endif // #ifndef LU_POLICY_HPP

Generated on Tue Feb 2 16:56:13 2010 for GNU C++ STL by  doxygen 1.4.7