Adobe Source Libraries 2.0.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
static_table.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_STATIC_TABLE_HPP
9#define ADOBE_STATIC_TABLE_HPP
10
11/**************************************************************************************************/
12
13#include <adobe/config.hpp>
14
15#include <functional>
16#include <stdexcept>
17#include <utility>
18
21
22/**************************************************************************************************/
23
24namespace adobe {
25
26/**************************************************************************************************/
27
28//***************************************************************************//
29//***************************************************************************//
30//***************************************************************************//
31
60
66
72
78
84
91
103
117
123
124//***************************************************************************//
125//***************************************************************************//
126//***************************************************************************//
127
140
146
152
158
164
165
175
185
186
187template <typename KeyType, typename ValueType>
189 typedef bool result_type;
190 typedef KeyType key_type;
191 typedef ValueType value_type;
192 typedef std::pair<key_type, value_type> entry_type;
193
194
199 result_type operator()(const entry_type& x, const entry_type& y) const {
200 return (*this)(x, y.first);
201 }
202
203 // revisit: MM. For debugging purposes, VC 8 requires the definition of
204 // this (unnecessary overload) in debug versions.
205 result_type operator()(const key_type& x, const entry_type& y) const { return x < y.first; }
206
207 result_type operator()(const entry_type& x, const key_type& y) const { return x.first < y; }
208
209 result_type equal(const key_type& x, const key_type& y) const { return x == y; }
210};
211
212/**************************************************************************************************/
213
214template <typename KeyType, typename ValueType, std::size_t Size,
215 typename Traits = static_table_traits<KeyType, ValueType>>
217 typedef Traits traits_type;
218 typedef typename traits_type::key_type key_type;
219 typedef typename traits_type::value_type value_type;
220 typedef typename traits_type::entry_type entry_type;
221
222 const value_type& operator()(const key_type& key) const {
223 const entry_type* iter(adobe::lower_bound(table_m, key, traits_type()));
224
225 if (iter == boost::end(table_m) || !traits_type().equal(iter->first, key))
226 throw std::logic_error("static_table key not found");
227
228 return iter->second;
229 }
230
231 bool operator()(const key_type& key, value_type& result) const {
232 const entry_type* iter(adobe::lower_bound(table_m, key, traits_type()));
233
234 if (iter == boost::end(table_m) || !traits_type().equal(iter->first, key))
235 return false;
236
237 result = iter->second;
238
239 return true;
240 }
241
243
244public:
246};
247
248/**************************************************************************************************/
249
250} // namespace adobe
251
252/**************************************************************************************************/
253
254#endif // ADOBE_STATIC_TABLE_HPP
255
256/**************************************************************************************************/
bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred)
Definition equal.hpp:36
void sort(RandomAccessRange &range)
sort implementation
Definition sort.hpp:40
I lower_bound(I f, I l, const T &x)
A traits class for use with adobe::static_table.
result_type equal(const key_type &x, const key_type &y) const
result_type operator()(const key_type &x, const entry_type &y) const
std::pair< key_type, value_type > entry_type
result_type operator()(const entry_type &x, const key_type &y) const
result_type operator()(const entry_type &x, const entry_type &y) const
A simple lookup table of fixed size. [under review].
bool operator()(const key_type &key, value_type &result) const
const value_type & operator()(const key_type &key) const
traits_type::entry_type entry_type
traits_type::value_type value_type
traits_type::key_type key_type
entry_type table_m[Size]