STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
synth_access_traits.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // Copyright (C) 2005-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
9 // version.
10 
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
26 
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
34 // warranty.
35 
41 #ifndef PB_DS_SYNTH_E_ACCESS_TRAITS_HPP
42 #define PB_DS_SYNTH_E_ACCESS_TRAITS_HPP
43 
45 
46 namespace __gnu_pbds
47 {
48  namespace detail
49  {
50 
51 #define PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC \
52  template<typename Type_Traits, bool Set, typename _ATraits>
53 
54 #define PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC \
55  synth_access_traits<Type_Traits, Set, _ATraits>
56 
58  template<typename Type_Traits, bool Set, typename _ATraits>
59  struct synth_access_traits : public _ATraits
60  {
61  typedef _ATraits base_type;
62  typedef typename base_type::const_iterator const_iterator;
63  typedef Type_Traits type_traits;
64  typedef typename type_traits::const_reference const_reference;
65  typedef typename type_traits::key_const_reference key_const_reference;
66 
68 
70 
71  inline bool
73  const_iterator, bool compare_after = true) const;
74 
75  bool
77 
78  bool
80  const_iterator, bool compare_after = false) const;
81 
82  bool
84 
85  inline static key_const_reference
87 
88 #ifdef _GLIBCXX_DEBUG
89  bool
91 #endif
92 
93  private:
94  inline static key_const_reference
96 
97  inline static key_const_reference
99 
100  static integral_constant<int, Set> s_set_ind;
101  };
102 
104  integral_constant<int,Set>
105  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::s_set_ind;
106 
108  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
109  synth_access_traits()
110  { }
111 
113  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
114  synth_access_traits(const _ATraits& r_traits)
115  : _ATraits(r_traits)
116  { }
117 
119  inline bool
120  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
121  equal_prefixes(const_iterator b_l, const_iterator e_l, const_iterator b_r,
122  const_iterator e_r, bool compare_after /*= false */) const
123  {
124  while (b_l != e_l)
125  {
126  if (b_r == e_r)
127  return false;
128  if (base_type::e_pos(*b_l) != base_type::e_pos(*b_r))
129  return false;
130  ++b_l;
131  ++b_r;
132  }
133  return (!compare_after || b_r == e_r);
134  }
135 
137  bool
138  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
139  equal_keys(key_const_reference r_lhs_key,
140  key_const_reference r_rhs_key) const
141  {
142  return equal_prefixes(base_type::begin(r_lhs_key),
143  base_type::end(r_lhs_key),
144  base_type::begin(r_rhs_key),
145  base_type::end(r_rhs_key),
146  true);
147  }
148 
150  bool
151  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
152  cmp_prefixes(const_iterator b_l, const_iterator e_l, const_iterator b_r,
153  const_iterator e_r, bool compare_after /* = false*/) const
154  {
155  while (b_l != e_l)
156  {
157  if (b_r == e_r)
158  return false;
159 
160  const typename base_type::size_type l_pos = base_type::e_pos(*b_l);
161  const typename base_type::size_type r_pos = base_type::e_pos(*b_r);
162  if (l_pos != r_pos)
163  return l_pos < r_pos;
164  ++b_l;
165  ++b_r;
166  }
167 
168  if (!compare_after)
169  return false;
170  return b_r != e_r;
171  }
172 
174  bool
175  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
176  cmp_keys(key_const_reference r_lhs_key,
177  key_const_reference r_rhs_key) const
178  {
179  return cmp_prefixes(base_type::begin(r_lhs_key),
180  base_type::end(r_lhs_key),
181  base_type::begin(r_rhs_key),
182  base_type::end(r_rhs_key),
183  true);
184  }
185 
187  inline typename PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::key_const_reference
188  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
189  extract_key(const_reference r_val)
190  { return extract_key(r_val, s_set_ind); }
191 
193  inline typename PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::key_const_reference
194  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
195  extract_key(const_reference r_val, true_type)
196  { return r_val; }
197 
199  inline typename PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::key_const_reference
200  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
201  extract_key(const_reference r_val, false_type)
202  { return r_val.first; }
203 
204 #ifdef _GLIBCXX_DEBUG
206  bool
207  PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::
208  operator()(key_const_reference r_lhs, key_const_reference r_rhs)
209  { return cmp_keys(r_lhs, r_rhs); }
210 #endif
211 
212 #undef PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
213 #undef PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC
214 
215  } // namespace detail
216 } // namespace __gnu_pbds
217 
218 #endif
bool cmp_prefixes(const_iterator, const_iterator, const_iterator, const_iterator, bool compare_after=false) const
bool equal_prefixes(const_iterator, const_iterator, const_iterator, const_iterator, bool compare_after=true) const
static integral_constant< int, Set > s_set_ind
Definition: synth_access_traits.hpp:100
base_type::const_iterator const_iterator
Definition: synth_access_traits.hpp:62
bool equal_keys(key_const_reference, key_const_reference) const
_ATraits base_type
Definition: synth_access_traits.hpp:61
Synthetic element access traits.
Definition: synth_access_traits.hpp:59
Type_Traits type_traits
Definition: synth_access_traits.hpp:63
std::tr1::integral_constant< int, 1 > true_type
Definition: type_utils.hpp:70
static key_const_reference extract_key(const_reference)
bool cmp_keys(key_const_reference, key_const_reference) const
type_traits::key_const_reference key_const_reference
Definition: synth_access_traits.hpp:65
#define PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC
Definition: synth_access_traits.hpp:51
type_traits::const_reference const_reference
Definition: synth_access_traits.hpp:64
std::tr1::integral_constant< int, 0 > false_type
Definition: type_utils.hpp:71