stlab.adobe.com Adobe Systems Incorporated
dictionary.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_DICTIONARY_HPP
10 #define ADOBE_DICTIONARY_HPP
11 
12 /**************************************************************************************************/
13 
14 #include <adobe/config.hpp>
15 
16 #include <adobe/dictionary_fwd.hpp>
17 
18 #include <stdexcept>
19 
20 #include <adobe/any_regular.hpp>
21 #include <adobe/closed_hash.hpp>
22 #include <adobe/name.hpp>
23 #include <adobe/typeinfo.hpp>
24 #include <adobe/string.hpp>
25 
26 #ifdef ADOBE_STD_SERIALIZATION
27 #include <iosfwd>
28 #endif
29 
30 /**************************************************************************************************/
31 
32 namespace adobe {
33 namespace version_1 {
34 
35 /**************************************************************************************************/
36 
37 template <typename T>
38 inline bool get_value(const dictionary_t& dict, name_t key, T& value)
39 {
40  dictionary_t::const_iterator i = dict.find(key);
41  if (i == dict.end()) return false;
42  return i->second.cast(value);
43 }
44 
45 inline bool get_value(const dictionary_t& dict, name_t key, any_regular_t& value)
46 {
47  dictionary_t::const_iterator i = dict.find(key);
48  if (i == dict.end()) return false;
49  value = i->second;
50  return true;
51 }
52 
53 inline const any_regular_t& get_value(const dictionary_t& dict, name_t key)
54 {
55  dictionary_t::const_iterator i = dict.find(key);
56  if (i == dict.end())
57  throw std::out_of_range(make_string("dictionary_t: key '", key.c_str(), "' not found"));
58 
59  return i->second;
60 }
61 
62 /**************************************************************************************************/
63 
64 #ifdef ADOBE_STD_SERIALIZATION
65 
66 // NOTE (sparent@adobe.com) : Code for serialization is located in source/any_regular.cpp.
67 std::ostream& operator<<(std::ostream& out, const dictionary_t& x);
68 
69 #endif
70 
71 /**************************************************************************************************/
72 
73 } // namespace version_1
74 
76 
77 } // namespace adobe
78 
79 /**************************************************************************************************/
80 
82 
83 /**************************************************************************************************/
84 
85 #endif
86 
87 /**************************************************************************************************/
88 
const char * c_str() const
Definition: name.hpp:63
std::ostream & operator<<(std::ostream &out, const dictionary_t &x)
bool get_value(const dictionary_t &dict, name_t key, T &value)
Definition: dictionary.hpp:38
#define ADOBE_SHORT_NAME_TYPE(a, b, c, d, T)
Definition: typeinfo.hpp:412
A runtime polymorphic type similar to boost::any which can hold any type which models Regular...
std::string make_string(const char *a, const char *b)
Definition: string.hpp:125

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