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 LIST_DWA2002627_HPP
6 # define LIST_DWA2002627_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/object.hpp>
11 # include <boost/python/converter/pytype_object_mgr_traits.hpp>
12 # include <boost/python/ssize_t.hpp>
14 namespace boost { namespace python {
18 struct BOOST_PYTHON_DECL list_base : object
20 void append(object_cref); // append object to end
22 ssize_t count(object_cref value) const; // return number of occurrences of value
24 void extend(object_cref sequence); // extend list by appending sequence elements
26 long index(object_cref value) const; // return index of first occurrence of value
28 void insert(ssize_t index, object_cref); // insert object before index
29 void insert(object const& index, object_cref);
31 object pop(); // remove and return item at index (default last)
32 object pop(ssize_t index);
33 object pop(object const& index);
35 void remove(object_cref value); // remove first occurrence of value
37 void reverse(); // reverse *IN PLACE*
39 void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
40 #if PY_VERSION_HEX >= 0x03000000
41 void sort(args_proxy const &args,
42 kwds_proxy const &kwds);
44 void sort(object_cref cmpfunc);
48 list_base(); // new list
49 explicit list_base(object_cref sequence); // new list initialized from sequence's items
51 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list_base, object)
53 static detail::new_non_null_reference call(object const&);
57 class list : public detail::list_base
59 typedef detail::list_base base;
64 explicit list(T const& sequence)
65 : base(object(sequence))
70 void append(T const& x)
72 base::append(object(x));
76 long count(T const& value) const
78 return base::count(object(value));
82 void extend(T const& x)
84 base::extend(object(x));
88 long index(T const& x) const
90 return base::index(object(x));
94 void insert(ssize_t index, T const& x) // insert object before index
96 base::insert(index, object(x));
100 void insert(object const& index, T const& x) // insert object before index
102 base::insert(index, object(x));
105 object pop() { return base::pop(); }
106 object pop(ssize_t index) { return base::pop(index); }
109 object pop(T const& index)
111 return base::pop(object(index));
115 void remove(T const& value)
117 base::remove(object(value));
120 #if PY_VERSION_HEX <= 0x03000000
121 void sort() { base::sort(); }
124 void sort(T const& value)
126 base::sort(object(value));
130 public: // implementation detail -- for internal use only
131 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, base)
135 // Converter Specializations
140 struct object_manager_traits<list>
141 : pytype_object_manager_traits<&PyList_Type,list>
146 }} // namespace boost::python
148 #endif // LIST_DWA2002627_HPP