Last updated February 21, 2008
Background
Regular Type
- adobe::dictionary_t is a typedef for adobe::closed_hash_map<adobe::name_t, adobe::any_regular_t>.
Move
- adobe::dictionary_t is a movable type, which means that the container can be freely returned from functions without incurring unnecessary copies [see adobe::move].
Random Access
- Every element in an adobe::dictionary_t can be accessed in
constant
time. There are also iterator classes that allow for bidirectional iteration of the container.
adobe::value_t Elements
- adobe::dictionary_t stores key/pair elements of types <adobe::name_t, adobe::any_regular_t>. Because of the features of adobe::any_regular_t, this means that an adobe::dictionary_t can store any data type that models the Regular concept at a given key.
Usage
- A key point to remember is an adobe::dictionary_t is essentially a specialized map. Consequently just about anything you can do with a map you can do with an adobe::dictionary_t. The reasons you would want to use an adobe::dictionary_t over a std::map<adobe::name_t, adobe::any_regular_t> is primarily because of the move semantics and because the storage characteristics of a closed_hash_map, which allow for optimized copying when returned from a functions. It is also much more lightweight than a std::map.
Initialization
- One initializes an adobe::dictionary_t in one of several ways:
closed_hash_map< name_t, any_regular_t > dictionary_t
- Constructing an empty dictionary will never throw an exception - no allocations are required until something is stored into it.
Storage
- Setting a value in an dictionary can only be done just as with a map:
A runtime polymorphic type similar to boost::any which can hold any type which models Regular.
Utility wrapper to construct name_t with strings of static storage duration.
Retrieval
- Getting values out of an adobe::dictionary_t is easy, you merely index into the adobe::dictionary_t to access the values. The only thing to remember is that the data stored is wrapped in an adobe::any_regular_t, so it must first be extracted out of there before it can be used:
std::string my_string_value(my_dictionary[
adobe::name_t(
"key_string")].cast<std::string>());
for (; first != last; ++first)
{
if (first->second.type_info() == adobe::type_info<std::string>())
{
std::cout << "Found a string: " << first->second.cast<std::string>() << std::endl;
}
else if (first->second.type_info() == adobe::type_info<double>())
{
std::cout << "Found a number: " << first->second.cast<double>() << std::endl;
}
else
{
std::cout << "I have no idea what we've found!" << std::endl;
}
}
implementation::closed_hash_iterator< closed_hash_set, const value_type > const_iterator
A character string class for immutable strings.
Note that iterative retrieval of elements will not take place in key-sorted order. Use a table_index<> if key-sorted order is needed.