8 #ifndef ICETRAY_PYTHON_STD_VECTOR_INDEXING_SUITE_HPP_INCLUDED 9 # define ICETRAY_PYTHON_STD_VECTOR_INDEXING_SUITE_HPP_INCLUDED 11 # include <boost/python/suite/indexing/indexing_suite.hpp> 12 # include <boost/python/suite/indexing/container_utils.hpp> 13 # include <boost/python/iterator.hpp> 15 namespace boost {
namespace python {
18 template <
class Container,
bool NoProxy,
class DerivedPolicies>
23 template <
class Container,
bool NoProxy>
26 NoProxy, final_std_vector_derived_policies<Container, NoProxy> > {};
51 :
public indexing_suite<Container, DerivedPolicies, NoProxy>
56 typedef typename Container::value_type
key_type;
61 template <
class Class>
84 get_slice(Container& container, index_type from, index_type to)
87 return object(Container());
88 return object(Container(container.begin()+from, container.begin()+to));
92 set_item(Container& container, index_type i, data_type
const& v)
99 index_type to, data_type
const& v)
105 container.erase(container.begin()+from, container.begin()+to);
106 container.insert(container.begin()+from, v);
110 template <
class Iter>
113 index_type to, Iter first, Iter last)
116 container.insert(container.begin()+from, first, last);
119 container.erase(container.begin()+from, container.begin()+to);
120 container.insert(container.begin()+from, first, last);
127 container.erase(container.begin()+i);
137 container.erase(container.begin()+from, container.begin()+to);
143 return container.size();
147 contains(Container& container, key_type
const& key)
149 return std::find(container.begin(), container.end(), key)
162 return container.size();
179 index += DerivedPolicies::size(container);
180 if (index >=
long(container.size()) || index < 0)
182 PyErr_SetString(PyExc_IndexError,
"Index out of range");
183 throw_error_already_set();
188 PyErr_SetString(PyExc_TypeError,
"Invalid index type");
189 throw_error_already_set();
194 append(Container& container, data_type
const& v)
196 container.push_back(v);
199 template <
class Iter>
201 extend(Container& container, Iter first, Iter last)
203 container.insert(container.end(), first, last);
211 extract<data_type&> elem(v);
215 DerivedPolicies::append(container, elem());
220 extract<data_type> elem(v);
223 DerivedPolicies::append(container, elem());
227 PyErr_SetString(PyExc_TypeError,
228 "Attempting to append an invalid type");
229 throw_error_already_set();
234 static boost::shared_ptr<Container >
237 boost::shared_ptr<Container > conti(
new Container());
239 container_utils::extend_container(*conti, v);
247 std::vector<data_type> temp;
248 container_utils::extend_container(temp, v);
249 DerivedPolicies::extend(container, temp.begin(), temp.end());
255 #endif // ICETRAY_PYTHON_STD_VECTOR_INDEXING_SUITE_HPP_INCLUDED static size_t size(Container &container)
Definition: std_vector_indexing_suite.hpp:141
static void delete_item(Container &container, index_type i)
Definition: std_vector_indexing_suite.hpp:125
static void delete_slice(Container &container, index_type from, index_type to)
Definition: std_vector_indexing_suite.hpp:131
static object get_slice(Container &container, index_type from, index_type to)
Definition: std_vector_indexing_suite.hpp:84
Definition: std_map_indexing_suite.hpp:20
Container::value_type key_type
Definition: std_vector_indexing_suite.hpp:56
static void extend(Container &container, Iter first, Iter last)
Definition: std_vector_indexing_suite.hpp:201
Container::difference_type difference_type
Definition: std_vector_indexing_suite.hpp:59
static bool contains(Container &container, key_type const &key)
Definition: std_vector_indexing_suite.hpp:147
static void base_append(Container &container, object v)
Definition: std_vector_indexing_suite.hpp:209
static index_type convert_index(Container &container, PyObject *i_)
Definition: std_vector_indexing_suite.hpp:172
Container::size_type size_type
Definition: std_vector_indexing_suite.hpp:58
static void extension_def(Class &cl)
Definition: std_vector_indexing_suite.hpp:63
Definition: std_vector_indexing_suite.hpp:24
static index_type get_min_index(Container &)
Definition: std_vector_indexing_suite.hpp:154
Container::value_type data_type
Definition: std_vector_indexing_suite.hpp:55
static void base_extend(Container &container, object v)
Definition: std_vector_indexing_suite.hpp:245
static void set_slice(Container &container, index_type from, index_type to, Iter first, Iter last)
Definition: std_vector_indexing_suite.hpp:112
Definition: std_vector_indexing_suite.hpp:19
Container::size_type index_type
Definition: std_vector_indexing_suite.hpp:57
static void append(Container &container, data_type const &v)
Definition: std_vector_indexing_suite.hpp:194
static boost::shared_ptr< Container > container_from_object(object v)
Definition: std_vector_indexing_suite.hpp:235
static void set_item(Container &container, index_type i, data_type const &v)
Definition: std_vector_indexing_suite.hpp:92
static index_type get_max_index(Container &container)
Definition: std_vector_indexing_suite.hpp:160
static bool compare_index(Container &, index_type a, index_type b)
Definition: std_vector_indexing_suite.hpp:166
static mpl::if_< is_class< data_type >, data_type &, data_type >::type get_item(Container &container, index_type i)
Definition: std_vector_indexing_suite.hpp:78
static void set_slice(Container &container, index_type from, index_type to, data_type const &v)
Definition: std_vector_indexing_suite.hpp:98