Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
static_table< KeyType, ValueType, Size, Traits > Class Template Reference

A simple lookup table of fixed size. [under review]. More...

#include <static_table.hpp>

Public Types

typedef Traits traits_type
typedef traits_type::key_type key_type
typedef traits_type::value_type value_type
typedef traits_type::entry_type entry_type

Public Member Functions

const value_typeoperator() (const key_type &key) const
bool operator() (const key_type &key, value_type &result) const
void sort ()

Public Attributes

entry_type table_m [Size]

Detailed Description

template<typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType>>
class adobe::static_table< KeyType, ValueType, Size, Traits >

static_table is intended to encapsulate the code used to initialize, sort, and perform lookups on lookup tables of static size. They are intended to be initialized without runtime code, though they must be sorted at runtime before any lookups can occur. Performing a lookup before the table is sorted will have undefined results.

Example
using table_t = adobe::static_table<adobe::name_t, std::function<void (int)>, 4>;
static table_t some_table_s =
{{
table_t::entry_type("foo"_name, &do_foo),
table_t::entry_type("bar"_name, &do_bar),
table_t::entry_type("baz"_name, &do_baz),
table_t::entry_type("snafu"_name, &do_snafu)
}};
some_table_s.sort();
some_table_s("baz"_name)(42); // calls do_baz
A character string class for immutable strings.
Definition name.hpp:220
A simple lookup table of fixed size. [under review].

Definition at line 221 of file static_table.hpp.

Member Typedef Documentation

◆ traits_type

template<typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType>>
typedef Traits traits_type

The static_table_traits used to extend this static_table's functionality.

Definition at line 222 of file static_table.hpp.

◆ key_type

template<typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType>>
typedef traits_type::key_type key_type

The type used for lookups in the table.

Definition at line 223 of file static_table.hpp.

◆ value_type

template<typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType>>
typedef traits_type::value_type value_type

The resultant type from a table lookup.

Definition at line 224 of file static_table.hpp.

◆ entry_type

template<typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType>>
typedef traits_type::entry_type entry_type

A pair comprised of a key_type and a value_type.

Definition at line 225 of file static_table.hpp.

Member Function Documentation

◆ operator()() [1/2]

template<typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType>>
const value_type & operator() ( const key_type & key) const
Parameters
keyThe key whose stored value we are searching for.
Exceptions
std::logic_errorThrown if the key does not exist in the table.
Returns
a reference to the value found associated with key.
Note
Calling this function before calling sort() yields undefined results.

Definition at line 227 of file static_table.hpp.

◆ operator()() [2/2]

template<typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType>>
bool operator() ( const key_type & key,
value_type & result ) const
Parameters
keyThe key whose stored value we are searching for.
resultSet to the value associated with the key if key is found.
Exceptions
NoneGuaranteed not to throw.
Returns
true if key was found and result's assignment did not throw. false otherwise.
Note
Calling this function before calling sort() yields undefined results.

Definition at line 236 of file static_table.hpp.

◆ sort()

template<typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType>>
void sort ( )

Sorts the contents of the table according to the static_table_traits type.

Definition at line 247 of file static_table.hpp.

Member Data Documentation

◆ table_m

template<typename KeyType, typename ValueType, std::size_t Size, typename Traits = static_table_traits<KeyType, ValueType>>
entry_type table_m[Size]

The static lookup table contents. This variable is not intended to be manipulated directly. It is publicly available to support static table initialization by the C++ compiler.

Definition at line 250 of file static_table.hpp.