types_traits.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 TYPES_TRAITS_HPP
00046 #define TYPES_TRAITS_HPP
00047 
00048 #include <ext/pb_assoc/data_type.hpp>
00049 #include <ext/pb_assoc/detail/type_utils.hpp>
00050 #include <utility>
00051 
00052 namespace pb_assoc
00053 {
00054 
00055   namespace detail
00056   {
00057 
00058     template<typename Data, class Allocator>
00059     struct basic_data_types_traits
00060     {
00061 
00062     public:
00063 
00064       typedef
00065       typename Allocator::template rebind<
00066     Data>::other::value_type
00067       data_type;
00068 
00069       typedef
00070       typename Allocator::template rebind<
00071     Data>::other::pointer
00072       data_pointer;
00073 
00074       typedef
00075       typename Allocator::template rebind<
00076     Data>::other::const_pointer
00077       const_data_pointer;
00078 
00079       typedef
00080       typename Allocator::template rebind<
00081     Data>::other::reference
00082       data_reference;
00083 
00084       typedef
00085       typename Allocator::template rebind<
00086     Data>::other::const_reference
00087       const_data_reference;
00088 
00089     };
00090 
00091     template<typename Data, class Allocator>
00092     struct data_types_traits : public basic_data_types_traits<
00093       Data,
00094       Allocator>
00095     {
00096 
00097     public:
00098 
00099       typedef Data given_data_type;
00100 
00101     };
00102 
00103 #define PB_ASSOC_CLASS_T_DEC \
00104     template<class Allocator>
00105 
00106 #define PB_ASSOC_CLASS_C_DEC \
00107     data_types_traits< \
00108             null_data_type, \
00109             Allocator>
00110 
00111     template<class Allocator>
00112     struct data_types_traits<
00113       null_data_type,
00114       Allocator> : public basic_data_types_traits<
00115       null_data_type,
00116       Allocator>
00117     {
00118 
00119     public:
00120 
00121       typedef null_data_type given_data_type;
00122 
00123     };
00124 
00125 #undef PB_ASSOC_CLASS_T_DEC
00126 
00127 #undef PB_ASSOC_CLASS_C_DEC
00128 
00129     template<class Cntnr, class Allocator>
00130     struct data_types_traits<
00131       compound_data_type<
00132       Cntnr>,
00133       Allocator> : public basic_data_types_traits<
00134       Cntnr,
00135       Allocator>
00136     {
00137 
00138     public:
00139 
00140       typedef compound_data_type< Cntnr> given_data_type;
00141 
00142     };
00143 
00144 #define PB_ASSOC_CLASS_T_DEC \
00145     template<typename Key, typename Data>
00146 
00147 #define PB_ASSOC_CLASS_C_DEC \
00148     exception_throw_types_traits< \
00149         Key, \
00150         Data>
00151 
00152     template<typename Key, typename Data>
00153     struct exception_throw_types_traits
00154     {
00155 
00156     public:
00157 
00158       typedef int_to_type<false> no_throw_copies_false_indicator;
00159 
00160       typedef int_to_type<true> no_throw_copies_true_indicator;
00161 
00162     private:
00163       enum
00164     {
00165       key_no_throw = is_simple_type<Key>::value,
00166       data_no_throw = is_same_type<Data, null_data_type>::value ||
00167       is_simple_type<Data>::value,
00168       no_throw_copies = key_no_throw&&  data_no_throw
00169     };
00170 
00171       typedef int_to_type<no_throw_copies> no_throw_copies_t;
00172 
00173     public:
00174       static no_throw_copies_t s_no_throw_copies_indicator;
00175     };
00176 
00177     PB_ASSOC_CLASS_T_DEC
00178     typename PB_ASSOC_CLASS_C_DEC::no_throw_copies_t
00179     PB_ASSOC_CLASS_C_DEC::s_no_throw_copies_indicator;
00180 
00181 #undef PB_ASSOC_CLASS_T_DEC
00182 
00183 #undef PB_ASSOC_CLASS_C_DEC
00184 
00185     template<typename Key, typename Data, class Allocator>
00186     struct value_types_traits
00187     {
00188 
00189     public:
00190 
00191       typedef
00192       typename Allocator::template rebind<
00193     std::pair<const Key, Data> >::other
00194       value_type_allocator;
00195 
00196       typedef typename value_type_allocator::value_type value_type;
00197 
00198       typedef typename value_type_allocator::pointer pointer;
00199 
00200       typedef typename value_type_allocator::const_pointer const_pointer;
00201 
00202       typedef typename value_type_allocator::reference reference;
00203 
00204       typedef typename value_type_allocator::const_reference const_reference;
00205 
00206     };
00207 
00208     template<typename Key, class Allocator>
00209     struct value_types_traits<
00210       Key,
00211       null_data_type,
00212       Allocator>
00213     {
00214 
00215     public:
00216 
00217       typedef
00218       typename Allocator::template rebind<
00219     Key>::other
00220       value_type_allocator;
00221 
00222       typedef typename value_type_allocator::value_type value_type;
00223 
00224       typedef typename value_type_allocator::const_pointer pointer;
00225 
00226       typedef typename value_type_allocator::const_pointer const_pointer;
00227 
00228       typedef typename value_type_allocator::const_reference reference;
00229 
00230       typedef typename value_type_allocator::const_reference const_reference;
00231 
00232     };
00233 
00234     template<typename Key, class Cntnr, class Allocator>
00235     struct value_types_traits<
00236       Key,
00237       compound_data_type<
00238       Cntnr>,
00239       Allocator>
00240     {
00241     private:
00242 
00243       typedef
00244       typename Allocator::template rebind<
00245     std::pair<const Key, Cntnr> >::other
00246       value_type_allocator;
00247 
00248     public:
00249 
00250       typedef typename value_type_allocator::value_type value_type;
00251 
00252       typedef typename value_type_allocator::pointer pointer;
00253 
00254       typedef typename value_type_allocator::const_pointer const_pointer;
00255 
00256       typedef typename value_type_allocator::reference reference;
00257 
00258       typedef typename value_type_allocator::const_reference const_reference;
00259 
00260     };
00261 
00262     template<typename Key, typename Data, class Allocator>
00263     struct types_traits : public data_types_traits<
00264       Data,
00265       Allocator>,
00266 public value_types_traits<
00267       Key,
00268       Data,
00269       Allocator>,
00270 public exception_throw_types_traits<
00271       Key,
00272       Data>
00273     {
00274 
00275     public:
00276 
00277       typedef typename Allocator::template rebind<Key>::other key_allocator;
00278 
00279       typedef typename key_allocator::value_type key_type;
00280 
00281       typedef typename key_allocator::pointer key_pointer;
00282 
00283       typedef typename key_allocator::const_pointer const_key_pointer;
00284 
00285       typedef typename key_allocator::reference key_reference;
00286 
00287       typedef typename key_allocator::const_reference const_key_reference;
00288 
00289     };
00290 
00291   } // namespace detail
00292 
00293 } // namespace pb_assoc
00294 
00295 #endif // #ifndef TYPES_TRAITS_HPP

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