dict.qbk 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. [section boost/python/dict.hpp]
  2. [section Introduction]
  3. Exposes 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`]
  6. Exposes 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. ``
  8. namespace boost { namespace python
  9. {
  10. class dict : public object
  11. {
  12. dict();
  13. template< class T >
  14. dict(T const & data);
  15. // modifiers
  16. void clear();
  17. dict copy();
  18. template <class T1, class T2>
  19. tuple popitem();
  20. template <class T>
  21. object setdefault(T const &k);
  22. template <class T1, class T2>
  23. object setdefault(T1 const & k, T2 const & d);
  24. void update(object_cref E);
  25. template< class T >
  26. void update(T const & E);
  27. // observers
  28. list values() const;
  29. object get(object_cref k) const;
  30. template<class T>
  31. object get(T const & k) const;
  32. object get(object_cref k, object_cref d) const;
  33. object get(T1 const & k, T2 const & d) const;
  34. bool has_key(object_cref k) const;
  35. template< class T >
  36. bool has_key(T const & k) const;
  37. list items() const;
  38. object iteritems() const;
  39. object iterkeys() const;
  40. object itervalues() const;
  41. list keys() const;
  42. };
  43. }}
  44. ``
  45. [endsect]
  46. [section Example]
  47. ``
  48. using namespace boost::python;
  49. dict swap_object_dict(object target, dict d)
  50. {
  51. dict result = extract<dict>(target.attr("__dict__"));
  52. target.attr("__dict__") = d;
  53. return result;
  54. }
  55. ``
  56. [endsect]
  57. [endsect]