Skip to content

Commit dfd85da

Browse files
committed
str, dict, and tuple!
[SVN r14517]
1 parent 94edc13 commit dfd85da

File tree

18 files changed

+1419
-537
lines changed

18 files changed

+1419
-537
lines changed

Jamfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ dll bpl
1515
:
1616
src/list.cpp
1717
src/long.cpp
18+
src/dict.cpp
19+
src/tuple.cpp
20+
src/str.cpp
21+
1822
src/aix_init_module.cpp
1923
src/converter/from_python.cpp
2024
src/converter/registry.cpp

include/boost/python/dict.hpp

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#ifndef DICT_20020706_HPP
2+
#define DICT_20020706_HPP
3+
4+
#include <boost/python/object.hpp>
5+
#include <boost/python/list.hpp>
6+
#include <boost/python/tuple.hpp>
7+
#include <boost/python/converter/pytype_object_manager_traits.hpp>
8+
9+
namespace boost { namespace python {
10+
11+
class dict : public object
12+
{
13+
public:
14+
// dict() -> new empty dictionary.
15+
// dict(mapping) -> new dictionary initialized from a mapping object's
16+
// (key, value) pairs.
17+
// dict(seq) -> new dictionary initialized as if via:
18+
BOOST_PYTHON_DECL dict(); // new dict
19+
explicit BOOST_PYTHON_DECL dict(object_cref data);
20+
21+
template <class T>
22+
explicit dict(T const& data)
23+
: object(dict::call(object(data)))
24+
{
25+
}
26+
27+
// D.clear() -> None. Remove all items from D.
28+
BOOST_PYTHON_DECL void clear();
29+
30+
// D.copy() -> a shallow copy of D
31+
BOOST_PYTHON_DECL dict copy();
32+
33+
// D.get(k[,d]) -> D[k] if D.has_key(k), else d. d defaults to None.
34+
BOOST_PYTHON_DECL object get(object_cref k) const;
35+
36+
template<class T>
37+
object get(T const& k) const
38+
{
39+
return this->get(object(k));
40+
}
41+
42+
BOOST_PYTHON_DECL object get(object_cref k, object_cref d) const;
43+
44+
template<class T1, class T2>
45+
object get(T1 const& k, T2 const& d) const
46+
{
47+
return this->get(object(k),object(d));
48+
}
49+
50+
// D.has_key(k) -> 1 if D has a key k, else 0
51+
BOOST_PYTHON_DECL bool has_key(object_cref k) const;
52+
53+
template<class T>
54+
bool has_key(T const& k) const
55+
{
56+
return this->has_key(object(k));
57+
}
58+
59+
// D.items() -> list of D's (key, value) pairs, as 2-tuples
60+
BOOST_PYTHON_DECL list items() const;
61+
62+
// D.iteritems() -> an iterator over the (key, value) items of D
63+
BOOST_PYTHON_DECL object iteritems() const;
64+
65+
// D.iterkeys() -> an iterator over the keys of D
66+
BOOST_PYTHON_DECL object iterkeys() const;
67+
68+
// D.itervalues() -> an iterator over the values of D
69+
BOOST_PYTHON_DECL object itervalues() const;
70+
71+
// D.keys() -> list of D's keys
72+
BOOST_PYTHON_DECL list keys() const;
73+
74+
// D.popitem() -> (k, v), remove and return some (key, value) pair as a
75+
// 2-tuple; but raise KeyError if D is empty
76+
BOOST_PYTHON_DECL tuple popitem();
77+
78+
// D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k)
79+
BOOST_PYTHON_DECL object setdefault(object_cref k);
80+
81+
template<class T>
82+
object setdefault(T const& k)
83+
{
84+
return this->setdefault(object(k));
85+
}
86+
87+
BOOST_PYTHON_DECL object setdefault(object_cref k, object_cref d);
88+
89+
template<class T1, class T2>
90+
object setdefault(T1 const& k, T2 const& d)
91+
{
92+
return this->setdefault(object(k),object(d));
93+
}
94+
95+
// D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k]
96+
BOOST_PYTHON_DECL void update(object_cref E);
97+
98+
template<class T>
99+
void update(T const& E)
100+
{
101+
this->update(object(E));
102+
}
103+
104+
// D.values() -> list of D's values
105+
BOOST_PYTHON_DECL list values() const;
106+
107+
public: // implementation detail -- for internal use only
108+
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict)
109+
110+
private:
111+
static BOOST_PYTHON_DECL detail::new_reference call(object const&);
112+
};
113+
114+
115+
//
116+
// Converter Specializations
117+
//
118+
namespace converter
119+
{
120+
template <>
121+
struct object_manager_traits<dict>
122+
: pytype_object_manager_traits<&PyDict_Type,dict>
123+
{
124+
};
125+
}
126+
127+
}} // namespace boost::python
128+
129+
#endif
130+

include/boost/python/objects.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
# define OBJECTS_DWA051100_H_
1111

1212
# ifdef BOOST_PYTHON_V2
13-
# include <boost/python/objects2.hpp>
14-
# include <boost/python/list.hpp>
13+
# error obsolete
1514
# else
1615
# include <boost/python/detail/wrap_python.hpp>
1716
# include <boost/python/detail/config.hpp>

0 commit comments

Comments
 (0)