Update contrib.
1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef DICT_20020706_HPP
6 #define DICT_20020706_HPP
8 # include <boost/python/detail/prefix.hpp>
10 #include <boost/python/object.hpp>
11 #include <boost/python/list.hpp>
12 #include <boost/python/tuple.hpp>
13 #include <boost/python/converter/pytype_object_mgr_traits.hpp>
15 namespace boost { namespace python {
21 struct BOOST_PYTHON_DECL dict_base : object
23 // D.clear() -> None. Remove all items from D.
26 // D.copy() -> a shallow copy of D
29 // D.get(k[,d]) -> D[k] if D.has_key(k), else d. d defaults to None.
30 object get(object_cref k) const;
32 object get(object_cref k, object_cref d) const;
34 // D.has_key(k) -> 1 if D has a key k, else 0
35 bool has_key(object_cref k) const;
37 // D.items() -> list of D's (key, value) pairs, as 2-tuples
40 // D.iteritems() -> an iterator over the (key, value) items of D
41 object iteritems() const;
43 // D.iterkeys() -> an iterator over the keys of D
44 object iterkeys() const;
46 // D.itervalues() -> an iterator over the values of D
47 object itervalues() const;
49 // D.keys() -> list of D's keys
52 // D.popitem() -> (k, v), remove and return some (key, value) pair as a
53 // 2-tuple; but raise KeyError if D is empty
56 // D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k)
57 object setdefault(object_cref k);
59 object setdefault(object_cref k, object_cref d);
61 // D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k]
62 void update(object_cref E);
64 // D.values() -> list of D's values
68 // dict() -> new empty dictionary.
69 // dict(mapping) -> new dictionary initialized from a mapping object's
70 // (key, value) pairs.
71 // dict(seq) -> new dictionary initialized as if via:
72 dict_base(); // new dict
73 explicit dict_base(object_cref data);
75 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict_base, object)
77 static detail::new_reference call(object const&);
81 class dict : public detail::dict_base
83 typedef detail::dict_base base;
85 // dict() -> new empty dictionary.
86 // dict(mapping) -> new dictionary initialized from a mapping object's
87 // (key, value) pairs.
88 // dict(seq) -> new dictionary initialized as if via:
92 explicit dict(T const& data)
98 object get(T const& k) const
100 return base::get(object(k));
103 template<class T1, class T2>
104 object get(T1 const& k, T2 const& d) const
106 return base::get(object(k),object(d));
110 bool has_key(T const& k) const
112 return base::has_key(object(k));
116 object setdefault(T const& k)
118 return base::setdefault(object(k));
121 template<class T1, class T2>
122 object setdefault(T1 const& k, T2 const& d)
124 return base::setdefault(object(k),object(d));
128 void update(T const& E)
130 base::update(object(E));
133 public: // implementation detail -- for internal use only
134 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict, base)
138 // Converter Specializations
143 struct object_manager_traits<dict>
144 : pytype_object_manager_traits<&PyDict_Type,dict>
149 }} // namespace boost::python