Adobe Source Libraries 1.49.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
175
185
195
196
197template <typename KeyType, typename ValueType>
199 typedef bool result_type;
200 typedef KeyType key_type;
201 typedef ValueType value_type;
202 typedef std::pair<key_type, value_type> entry_type;
203
204 result_type operator()(const entry_type& x, const entry_type& y) const {
205 return (*this)(x, y.first);
206 }
207
208 // revisit: MM. For debugging purposes, VC 8 requires the definition of
209 // this (unnecessary overload) in debug versions.
210 result_type operator()(const key_type& x, const entry_type& y) const { return x < y.first; }
211
212 result_type operator()(const entry_type& x, const key_type& y) const { return x.first < y; }
213
214 result_type equal(const key_type& x, const key_type& y) const { return x == y; }
215};
216
217/**************************************************************************************************/
218
219template <typename KeyType, typename ValueType, std::size_t Size,
220 typename Traits = static_table_traits<KeyType, ValueType>>
222 typedef Traits traits_type;
223 typedef typename traits_type::key_type key_type;
224 typedef typename traits_type::value_type value_type;
225 typedef typename traits_type::entry_type entry_type;
226
227 const value_type& operator()(const key_type& key) const {
228 const entry_type* iter(adobe::lower_bound(table_m, key, traits_type()));
229
230 if (iter == boost::end(table_m) || !traits_type().equal(iter->first, key))
231 throw std::logic_error("static_table key not found");
232
233 return iter->second;
234 }
235
236 bool operator()(const key_type& key, value_type& result) const {
237 const entry_type* iter(adobe::lower_bound(table_m, key, traits_type()));
238
239 if (iter == boost::end(table_m) || !traits_type().equal(iter->first, key))
240 return false;
241
242 result = iter->second;
243
244 return true;
245 }
246
248
249public:
251};
252
253/**************************************************************************************************/
254
255} // namespace adobe
256
257/**************************************************************************************************/
258
259#endif // ADOBE_STATIC_TABLE_HPP
260
261/**************************************************************************************************/
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]