it_value_type_traits.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
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 template<class Base, bool Lowest>
00046 struct base_it_key_type
00047 {
00048   typedef typename Base::it_key_type type;
00049 };
00050 
00051 template<class Base>
00052 struct base_it_key_type<
00053   Base,
00054   true>
00055 {
00056   typedef typename Base::const_key_reference type;
00057 };
00058 
00059 template<typename Base_Key_,
00060      typename Key_,
00061      typename Data_,
00062      typename Value_,
00063      class Allocator_ >
00064 struct it_value_type_traits_
00065 {
00066   typedef ref_pair< Base_Key_, Key_> key_ref_pair;
00067 
00068   typedef
00069   typename Allocator_::template rebind<
00070     key_ref_pair>::other::const_reference
00071   key_ref_pair_val;
00072 
00073   typedef key_ref_pair_val key_type;
00074 
00075   typedef ref_pair< key_ref_pair_val, Data_> value_type;
00076 
00077   typedef
00078   typename Allocator_::template rebind<
00079     value_type>::other::reference
00080   reference;
00081 
00082   typedef
00083   typename Allocator_::template rebind<
00084     value_type>::other::const_reference
00085   const_reference;
00086 
00087   typedef
00088   typename Allocator_::template rebind<
00089     value_type>::other::pointer
00090   pointer;
00091 
00092   typedef
00093   typename Allocator_::template rebind<
00094     value_type>::other::const_pointer
00095   const_pointer;
00096 
00097   struct value_type_holder
00098   {
00099     typename std::tr1::aligned_storage<sizeof(key_ref_pair),
00100       std::tr1::alignment_of<key_ref_pair>::value>::type  m_a_key_buf;
00101 
00102     typename std::tr1::aligned_storage<sizeof(value_type),
00103       std::tr1::alignment_of<value_type>::value>::type  m_a_value_buf;
00104   };
00105 
00106   typedef
00107   typename Allocator_::template rebind<
00108     value_type_holder>::other::reference
00109   value_type_hoder_valerence;
00110 
00111   inline static pointer
00112   recast(value_type_hoder_valerence r_holder)
00113   {
00114     return reinterpret_cast<pointer>(&r_holder.m_a_value_buf);
00115   }
00116 
00117   inline static void
00118   make_valid(value_type_hoder_valerence r_holder, Base_Key_ r_bk, Value_ r_val)
00119   {
00120     typedef
00121       typename Allocator_::template rebind<
00122       void* >::other::value_type
00123       void_pointer;
00124 
00125     void_pointer p_target = &r_holder.m_a_key_buf;
00126 
00127     new (p_target) key_ref_pair(r_bk, r_val.first);
00128 
00129     typedef
00130       typename Allocator_::template rebind<
00131       key_ref_pair>::other::pointer
00132       key_ref_pair_pointer;
00133 
00134     key_ref_pair_pointer p_key =
00135       reinterpret_cast<key_ref_pair_pointer>(&r_holder.m_a_key_buf);
00136 
00137     p_target = &r_holder.m_a_value_buf;
00138 
00139     new (p_target) value_type(*p_key, r_val.second);
00140   }
00141 };
00142 
00143 template<typename Base_Key_,
00144      typename Key_,
00145      typename Value_,
00146      class Allocator_>
00147 struct it_value_type_traits_<
00148   Base_Key_,
00149   Key_,
00150   null_data_type,
00151   Value_,
00152   Allocator_>
00153 {
00154   typedef ref_pair< Base_Key_, Key_> key_ref_pair;
00155 
00156   typedef
00157   typename Allocator_::template rebind<
00158     key_ref_pair>::other::const_reference
00159   key_ref_pair_val;
00160 
00161   typedef key_ref_pair_val key_type;
00162 
00163   typedef key_ref_pair value_type;
00164 
00165   typedef
00166   typename Allocator_::template rebind<
00167     value_type>::other::const_reference
00168   reference;
00169 
00170   typedef
00171   typename Allocator_::template rebind<
00172     value_type>::other::const_reference
00173   const_reference;
00174 
00175   typedef
00176   typename Allocator_::template rebind<
00177     value_type>::other::const_pointer
00178   pointer;
00179 
00180   typedef
00181   typename Allocator_::template rebind<
00182     value_type>::other::const_pointer
00183   const_pointer;
00184 
00185   struct value_type_holder
00186   {
00187     typename std::tr1::aligned_storage<sizeof(key_ref_pair),
00188       std::tr1::alignment_of<key_ref_pair>::value>::type  m_a_key_buf;
00189 
00190     typename std::tr1::aligned_storage<sizeof(value_type),
00191       std::tr1::alignment_of<value_type>::value>::type  m_a_value_buf;
00192   };
00193 
00194   typedef
00195   typename Allocator_::template rebind<
00196     value_type_holder>::other::reference
00197   value_type_hoder_valerence;
00198 
00199   inline static pointer
00200   recast(value_type_hoder_valerence r_holder)
00201   {
00202     return reinterpret_cast<pointer>(&r_holder.m_a_value_buf);
00203   }
00204 
00205   inline static void
00206   make_valid(value_type_hoder_valerence r_holder, Base_Key_ r_bk, Value_ r_val)
00207   {
00208     typedef
00209       typename Allocator_::template rebind<
00210       void* >::other::value_type
00211       void_pointer;
00212 
00213     void_pointer p_target = &r_holder.m_a_value_buf;
00214 
00215     new (p_target) key_ref_pair(r_bk, r_val.first);
00216   }
00217 };
00218 

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