libstdc++
branch_policy.hpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005-2015 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00026 
00027 // Permission to use, copy, modify, sell, and distribute this software
00028 // is hereby granted without fee, provided that the above copyright
00029 // notice appears in all copies, and that both that copyright notice
00030 // and this permission notice appear in supporting documentation. None
00031 // of the above authors, nor IBM Haifa Research Laboratories, make any
00032 // representation about the suitability of this software for any
00033 // purpose. It is provided "as is" without express or implied
00034 // warranty.
00035 
00036 /**
00037  * @file branch_policy/branch_policy.hpp
00038  * Contains a base class for branch policies.
00039  */
00040 
00041 #ifndef PB_DS_BRANCH_POLICY_BASE_HPP
00042 #define PB_DS_BRANCH_POLICY_BASE_HPP
00043 
00044 #include <ext/pb_ds/tag_and_trait.hpp>
00045 
00046 namespace __gnu_pbds
00047 {
00048   namespace detail
00049   {
00050     /// Primary template, base class for branch structure policies.
00051     template<typename Node_CItr, typename Node_Itr, typename _Alloc>
00052       struct branch_policy
00053       {
00054       protected:
00055         typedef typename Node_Itr::value_type           it_type;
00056         typedef typename std::iterator_traits<it_type>::value_type value_type;
00057         typedef typename value_type::first_type         key_type;
00058 
00059         typedef typename remove_const<value_type>::type rcvalue_type;
00060         typedef typename remove_const<key_type>::type   rckey_type;
00061 
00062         typedef typename _Alloc::template rebind<rcvalue_type>::other rebind_v;
00063         typedef typename _Alloc::template rebind<rckey_type>::other   rebind_k;
00064 
00065         typedef typename rebind_v::reference            reference;
00066         typedef typename rebind_v::const_reference      const_reference;
00067         typedef typename rebind_v::const_pointer        const_pointer;
00068 
00069         typedef typename rebind_k::const_reference      key_const_reference;
00070 
00071         static inline key_const_reference
00072         extract_key(const_reference r_val)
00073         { return r_val.first; }
00074 
00075         virtual it_type
00076         end() = 0;
00077 
00078         it_type
00079         end_iterator() const
00080         { return const_cast<branch_policy*>(this)->end(); }
00081 
00082         virtual
00083         ~branch_policy() { }
00084       };
00085 
00086     /// Specialization for const iterators.
00087     template<typename Node_CItr, typename _Alloc>
00088       struct branch_policy<Node_CItr, Node_CItr, _Alloc>
00089       {
00090       protected:
00091         typedef typename Node_CItr::value_type             it_type;
00092         typedef typename std::iterator_traits<it_type>::value_type value_type;
00093         typedef typename remove_const<value_type>::type            rcvalue_type;
00094         typedef typename _Alloc::template rebind<rcvalue_type>::other rebind_v;
00095         typedef typename rebind_v::reference            reference;
00096         typedef typename rebind_v::const_reference      const_reference;
00097         typedef typename rebind_v::const_pointer        const_pointer;
00098 
00099         typedef value_type                              key_type;
00100         typedef typename rebind_v::const_reference      key_const_reference;
00101 
00102         static inline key_const_reference
00103         extract_key(const_reference r_val)
00104         { return r_val; }
00105 
00106         virtual it_type
00107         end() const = 0;
00108 
00109         it_type
00110         end_iterator() const
00111         { return end(); }
00112 
00113         virtual
00114         ~branch_policy() { }
00115       };
00116   } // namespace detail
00117 } // namespace __gnu_pbds
00118 
00119 #endif // #ifndef PB_DS_BRANCH_POLICY_BASE_HPP