stlab.adobe.com Adobe Systems Incorporated
static_table.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_STATIC_TABLE_HPP
10 #define ADOBE_STATIC_TABLE_HPP
11 
12 /*************************************************************************************************/
13 
14 #include <adobe/config.hpp>
15 
16 #include <utility>
17 #include <stdexcept>
18 
20 #include <adobe/algorithm/sort.hpp>
21 
22 /*************************************************************************************************/
23 
24 namespace adobe {
25 
26 /*************************************************************************************************/
27 
28 //***************************************************************************//
29 //***************************************************************************//
30 //***************************************************************************//
31 
119 //***************************************************************************//
120 //***************************************************************************//
121 //***************************************************************************//
122 
187 template <typename KeyType, typename ValueType>
189 {
190  typedef bool result_type;
191  typedef KeyType key_type;
192  typedef ValueType value_type;
193  typedef std::pair<key_type, value_type> entry_type;
194 
195  result_type operator()(const entry_type& x, const entry_type& y) const
196  {
197  return (*this)(x, y.first);
198  }
199 
200  // revisit: MM. For debugging purposes, VC 8 requires the definition of
201  // this (unnecessary overload) in debug versions.
202  result_type operator()(const key_type& x, const entry_type& y) const
203  {
204  return x < y.first;
205  }
206 
207  result_type operator()(const entry_type& x, const key_type& y) const
208  {
209  return x.first < y;
210  }
211 
212  result_type equal(const key_type& x, const key_type& y) const
213  {
214  return x == y;
215  }
216 };
217 
218 /*************************************************************************************************/
219 
220 template <typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType> >
222 {
223  typedef Traits traits_type;
224  typedef typename traits_type::key_type key_type;
225  typedef typename traits_type::value_type value_type;
226  typedef typename traits_type::entry_type entry_type;
227 
228  const value_type& operator()(const key_type& key) const
229  {
230  const entry_type* iter(adobe::lower_bound(table_m, key, traits_type()));
231 
232  if (iter == boost::end(table_m) || !traits_type().equal(iter->first, key))
233  throw std::logic_error("static_table key not found");
234 
235  return iter->second;
236  }
237 
238  bool operator()(const key_type& key, value_type& result) const
239  {
240  const entry_type* iter(adobe::lower_bound(table_m, key, traits_type()));
241 
242  if (iter == boost::end(table_m) || !traits_type().equal(iter->first, key))
243  return false;
244 
245  result = iter->second;
246 
247  return true;
248  }
249 
250  void sort()
251  {
252  adobe::sort(table_m, traits_type());
253  }
254 
255 public:
256  entry_type table_m[Size];
257 };
258 
259 /*************************************************************************************************/
260 
261 } // namespace adobe
262 
263 /*************************************************************************************************/
264 
265 #endif // ADOBE_STATIC_TABLE_HPP
266 
267 /*************************************************************************************************/
std::pair< key_type, value_type > entry_type
const value_type & operator()(const key_type &key) const
result_type operator()(const entry_type &x, const entry_type &y) const
result_type equal(const key_type &x, const key_type &y) const
traits_type::value_type value_type
A traits class for use with adobe::static_table.
result_type operator()(const entry_type &x, const key_type &y) const
I lower_bound(I f, I l, const T &x)
void sort(RandomAccessRange &range)
sort implementation
Definition: sort.hpp:41
bool operator()(const key_type &key, value_type &result) const
traits_type::key_type key_type
result_type operator()(const key_type &x, const entry_type &y) const
A simple lookup table of fixed size. [under review].
traits_type::entry_type entry_type

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google