22 #ifndef BOOST_PYTHON_INDEXING_SLICE_HPP 23 #define BOOST_PYTHON_INDEXING_SLICE_HPP 25 #include <boost/python/object.hpp> 26 #include <boost/python/errors.hpp> 27 #include <boost/python/converter/pytype_object_mgr_traits.hpp> 30 namespace boost {
namespace python {
namespace indexing {
31 struct slice :
public boost::python::object
37 #if defined (BOOST_NO_MEMBER_TEMPLATES) 41 explicit slice (::boost::python::handle<>
const& p)
45 explicit slice (::boost::python::detail::borrowed_reference p)
49 explicit slice (::boost::python::detail::new_reference p)
53 explicit slice (::boost::python::detail::new_non_null_reference p)
58 template<
typename T>
inline slice (T
const &ref);
71 #if PY_VERSION_HEX < 0x02050000 72 typedef int index_type;
74 typedef Py_ssize_t index_type;
81 #
if PY_VERSION_HEX > 0x03020000
82 reinterpret_cast<PyObject *> (m_slice.ptr()),
84 reinterpret_cast<PySliceObject *> (m_slice.ptr()),
94 PyErr_SetString (PyExc_ValueError,
"slice step cannot be zero");
95 boost::python::throw_error_already_set ();
98 m_start = std::max (static_cast<index_type> (0), std::min (length, m_start));
99 m_stop = std::max (static_cast<index_type> (0), std::min (length, m_stop));
100 m_direction = (m_step > 0) ? 1 : -1;
106 index_type start()
const {
return m_start; }
107 index_type step()
const {
return m_step; }
108 index_type stop()
const {
return m_stop; }
110 index_type size()
const {
return (m_stop - m_start) / m_step; }
112 bool in_range (index_type index)
113 {
return ((m_stop - index) * m_direction) > 0; }
120 index_type m_direction;
124 #if !defined (BOOST_NO_MEMBER_TEMPLATES) 126 boost::python::indexing::slice::slice (T
const &ref)
127 : boost::python::object (ref)
129 if (!PySlice_Check (this->ptr()))
132 PyExc_TypeError,
"slice constructor: passed a non-slice object");
134 boost::python::throw_error_already_set();
139 namespace boost {
namespace python {
namespace converter {
143 : pytype_object_manager_traits<
144 &PySlice_Type, ::boost::python::indexing::slice>
149 #endif // BOOST_PYTHON_INDEXING_SLICE_HPP Definition: python_CEGUI.h:11