• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[section boost/python/dict.hpp]
2[section Introduction]
3Exposes a [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] for the Python [@http://www.python.org/dev/doc/devel/lib/typesmapping.html `dict`] type.
4[endsect]
5[section Class `dict`]
6Exposes the [@http://www.python.org/dev/doc/devel/lib/typesmapping.html mapping protocol] of Python's built-in `dict` type. The semantics of the constructors and member functions defined below can be fully understood by reading the [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] concept definition. Since `dict` is publicly derived from [link object_wrappers.boost_python_object_hpp.class_object `object`], the public `object` interface applies to `dict` instances as well.
7``
8namespace boost { namespace python
9{
10   class dict : public object
11   {
12      dict();
13
14      template< class T >
15      dict(T const & data);
16
17      // modifiers
18      void clear();
19      dict copy();
20
21      template <class T1, class T2>
22      tuple popitem();
23
24      template <class T>
25      object setdefault(T const &k);
26
27      template <class T1, class T2>
28      object setdefault(T1 const & k, T2 const & d);
29
30      void update(object_cref E);
31
32      template< class T >
33      void update(T const & E);
34
35      // observers
36      list values() const;
37
38      object get(object_cref k) const;
39
40      template<class T>
41      object get(T const & k) const;
42
43      object get(object_cref k, object_cref d) const;
44      object get(T1 const & k, T2 const & d) const;
45
46      bool has_key(object_cref k) const;
47
48      template< class T >
49      bool has_key(T const & k) const;
50
51      list items() const;
52      object iteritems() const;
53      object iterkeys() const;
54      object itervalues() const;
55      list keys() const;
56  };
57}}
58``
59[endsect]
60[section Example]
61``
62using namespace boost::python;
63dict swap_object_dict(object target, dict d)
64{
65    dict result = extract<dict>(target.attr("__dict__"));
66    target.attr("__dict__") = d;
67    return result;
68}
69``
70[endsect]
71[endsect]
72