[857] | 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
|
---|
| 7 |
|
---|
| 8 | # include <boost/python/detail/prefix.hpp>
|
---|
| 9 |
|
---|
| 10 | # include <boost/python/object.hpp>
|
---|
| 11 | # include <boost/python/converter/pytype_object_mgr_traits.hpp>
|
---|
| 12 |
|
---|
| 13 | namespace boost { namespace python {
|
---|
| 14 |
|
---|
| 15 | namespace detail
|
---|
| 16 | {
|
---|
| 17 | struct BOOST_PYTHON_DECL list_base : object
|
---|
| 18 | {
|
---|
| 19 | void append(object_cref); // append object to end
|
---|
| 20 |
|
---|
| 21 | long count(object_cref value) const; // return number of occurrences of value
|
---|
| 22 |
|
---|
| 23 | void extend(object_cref sequence); // extend list by appending sequence elements
|
---|
| 24 |
|
---|
| 25 | long index(object_cref value) const; // return index of first occurrence of value
|
---|
| 26 |
|
---|
| 27 | void insert(int index, object_cref); // insert object before index
|
---|
| 28 | void insert(object const& index, object_cref);
|
---|
| 29 |
|
---|
| 30 | object pop(); // remove and return item at index (default last)
|
---|
| 31 | object pop(long index);
|
---|
| 32 | object pop(object const& index);
|
---|
| 33 |
|
---|
| 34 | void remove(object_cref value); // remove first occurrence of value
|
---|
| 35 |
|
---|
| 36 | void reverse(); // reverse *IN PLACE*
|
---|
| 37 |
|
---|
| 38 | void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
|
---|
| 39 | void sort(object_cref cmpfunc);
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | protected:
|
---|
| 43 | list_base(); // new list
|
---|
| 44 | explicit list_base(object_cref sequence); // new list initialized from sequence's items
|
---|
| 45 |
|
---|
| 46 | BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list_base, object)
|
---|
| 47 | private:
|
---|
| 48 | static detail::new_non_null_reference call(object const&);
|
---|
| 49 | };
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | class list : public detail::list_base
|
---|
| 53 | {
|
---|
| 54 | typedef detail::list_base base;
|
---|
| 55 | public:
|
---|
| 56 | list() {} // new list
|
---|
| 57 |
|
---|
| 58 | template <class T>
|
---|
| 59 | explicit list(T const& sequence)
|
---|
| 60 | : base(object(sequence))
|
---|
| 61 | {
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | template <class T>
|
---|
| 65 | void append(T const& x)
|
---|
| 66 | {
|
---|
| 67 | base::append(object(x));
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | template <class T>
|
---|
| 71 | long count(T const& value) const
|
---|
| 72 | {
|
---|
| 73 | return base::count(object(value));
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | template <class T>
|
---|
| 77 | void extend(T const& x)
|
---|
| 78 | {
|
---|
| 79 | base::extend(object(x));
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | template <class T>
|
---|
| 83 | long index(T const& x) const
|
---|
| 84 | {
|
---|
| 85 | return base::index(object(x));
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | template <class T>
|
---|
| 89 | void insert(int index, T const& x) // insert object before index
|
---|
| 90 | {
|
---|
| 91 | base::insert(index, object(x));
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | template <class T>
|
---|
| 95 | void insert(object const& index, T const& x) // insert object before index
|
---|
| 96 | {
|
---|
| 97 | base::insert(index, object(x));
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | object pop() { return base::pop(); }
|
---|
| 101 | object pop(long index) { return base::pop(index); }
|
---|
| 102 |
|
---|
| 103 | template <class T>
|
---|
| 104 | object pop(T const& index)
|
---|
| 105 | {
|
---|
| 106 | return base::pop(object(index));
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | template <class T>
|
---|
| 110 | void remove(T const& value)
|
---|
| 111 | {
|
---|
| 112 | base::remove(object(value));
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | void sort() { base::sort(); }
|
---|
| 116 |
|
---|
| 117 | template <class T>
|
---|
| 118 | void sort(T const& value)
|
---|
| 119 | {
|
---|
| 120 | base::sort(object(value));
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | public: // implementation detail -- for internal use only
|
---|
| 124 | BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, base)
|
---|
| 125 | };
|
---|
| 126 |
|
---|
| 127 | //
|
---|
| 128 | // Converter Specializations
|
---|
| 129 | //
|
---|
| 130 | namespace converter
|
---|
| 131 | {
|
---|
| 132 | template <>
|
---|
| 133 | struct object_manager_traits<list>
|
---|
| 134 | : pytype_object_manager_traits<&PyList_Type,list>
|
---|
| 135 | {
|
---|
| 136 | };
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | }} // namespace boost::python
|
---|
| 140 |
|
---|
| 141 | #endif // LIST_DWA2002627_HPP
|
---|