list_update_policy.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006 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 terms
00007 // of the GNU General Public License as published by the Free Software
00008 // Foundation; either version 2, or (at your option) any later
00009 // version.
00010 
00011 // This library is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License
00017 // along with this library; see the file COPYING.  If not, write to
00018 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00019 // MA 02111-1307, USA.
00020 
00021 // As a special exception, you may use this file as part of a free
00022 // software library without restriction.  Specifically, if other files
00023 // instantiate templates or use macros or inline functions from this
00024 // file, or you compile this file and link it with other files to
00025 // produce an executable, this file does not by itself cause the
00026 // resulting executable to be covered by the GNU General Public
00027 // License.  This exception does not however invalidate any other
00028 // reasons why the executable file might be covered by the GNU General
00029 // Public License.
00030 
00031 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00032 
00033 // Permission to use, copy, modify, sell, and distribute this software
00034 // is hereby granted without fee, provided that the above copyright
00035 // notice appears in all copies, and that both that copyright notice
00036 // and this permission notice appear in supporting documentation. None
00037 // of the above authors, nor IBM Haifa Research Laboratories, make any
00038 // representation about the suitability of this software for any
00039 // purpose. It is provided "as is" without express or implied
00040 // warranty.
00041 
00042 /**
00043  * @file list_update_policy.hpp
00044  * Contains policies for list update containers.
00045  */
00046 
00047 #ifndef PB_DS_LU_POLICY_HPP
00048 #define PB_DS_LU_POLICY_HPP
00049 
00050 #include <ext/pb_ds/detail/list_update_policy/counter_lu_metadata.hpp>
00051 
00052 namespace pb_ds
00053 {
00054   // A null type that means that each link in a list-based container
00055   // does not actually need metadata.
00056   struct null_lu_metadata
00057   { };
00058 
00059 #define PB_DS_CLASS_T_DEC template<typename Allocator>
00060 #define PB_DS_CLASS_C_DEC move_to_front_lu_policy<Allocator>
00061 
00062   // A list-update policy that unconditionally moves elements to the
00063   // front of the list.
00064   template<typename Allocator = std::allocator<char> >
00065   class move_to_front_lu_policy
00066   {
00067   public:
00068     typedef Allocator allocator;
00069       
00070     // Metadata on which this functor operates.
00071     typedef null_lu_metadata metadata_type;
00072       
00073     // Reference to metadata on which this functor operates.
00074     typedef typename allocator::template rebind<metadata_type>::other metadata_rebind;
00075     typedef typename metadata_rebind::reference metadata_reference;
00076       
00077     // Creates a metadata object.
00078     metadata_type
00079     operator()() const;
00080       
00081     // Decides whether a metadata object should be moved to the front
00082     // of the list.
00083     inline bool
00084     operator()(metadata_reference r_metadata) const;
00085       
00086   private:
00087     static null_lu_metadata s_metadata;
00088   };
00089   
00090 #include <ext/pb_ds/detail/list_update_policy/mtf_lu_policy_imp.hpp>
00091 
00092 #undef PB_DS_CLASS_T_DEC
00093 #undef PB_DS_CLASS_C_DEC
00094 
00095 #define PB_DS_CLASS_T_DEC template<size_t Max_Count, class Allocator>
00096 #define PB_DS_CLASS_C_DEC counter_lu_policy<Max_Count, Allocator>
00097 
00098   // A list-update policy that moves elements to the front of the list
00099   // based on the counter algorithm.
00100   template<size_t Max_Count = 5, typename Allocator = std::allocator<char> >
00101   class counter_lu_policy 
00102   : private detail::counter_lu_policy_base<typename Allocator::size_type>
00103   {
00104   public:
00105     typedef Allocator allocator;
00106 
00107     enum
00108       {
00109     max_count = Max_Count
00110       };
00111 
00112     typedef typename allocator::size_type size_type;
00113 
00114     // Metadata on which this functor operates.
00115     typedef detail::counter_lu_metadata<size_type> metadata_type;
00116 
00117     // Reference to metadata on which this functor operates.
00118     typedef typename Allocator::template rebind<metadata_type>::other metadata_rebind;
00119     typedef typename metadata_rebind::reference metadata_reference;
00120 
00121     // Creates a metadata object.
00122     metadata_type
00123     operator()() const;
00124 
00125     // Decides whether a metadata object should be moved to the front
00126     // of the list.
00127     bool
00128     operator()(metadata_reference r_metadata) const;
00129 
00130   private:
00131     typedef detail::counter_lu_policy_base<typename Allocator::size_type> base_type;
00132   };
00133 
00134 #include <ext/pb_ds/detail/list_update_policy/counter_lu_policy_imp.hpp>
00135 
00136 #undef PB_DS_CLASS_T_DEC
00137 #undef PB_DS_CLASS_C_DEC
00138 
00139 } // namespace pb_ds
00140 
00141 #endif

Generated on Thu Nov 1 13:12:03 2007 for libstdc++ by  doxygen 1.5.1