/
usr
/
include
/
boost
/
python
/
/usr/include/boost/python
mkdir
upload
Name
Size
Mode
Actions
converter/
-
0755
rm
detail/
-
0755
rm
numpy/
-
0755
rm
object/
-
0755
rm
suite/
-
0755
rm
args.hpp
4194
0644
edit
dl
rm
args_fwd.hpp
1186
0644
edit
dl
rm
arg_from_python.hpp
2000
0644
edit
dl
rm
back_reference.hpp
1463
0644
edit
dl
rm
bases.hpp
1481
0644
edit
dl
rm
base_type_traits.hpp
878
0644
edit
dl
rm
borrowed.hpp
568
0644
edit
dl
rm
call.hpp
2749
0644
edit
dl
rm
call_method.hpp
2859
0644
edit
dl
rm
cast.hpp
2954
0644
edit
dl
rm
class.hpp
17866
0644
edit
dl
rm
class_fwd.hpp
772
0644
edit
dl
rm
copy_const_reference.hpp
1101
0644
edit
dl
rm
copy_non_const_reference.hpp
1141
0644
edit
dl
rm
data_members.hpp
9593
0644
edit
dl
rm
def.hpp
3187
0644
edit
dl
rm
default_call_policies.hpp
2279
0644
edit
dl
rm
def_visitor.hpp
2483
0644
edit
dl
rm
dict.hpp
3866
0644
edit
dl
rm
docstring_options.hpp
3505
0644
edit
dl
rm
enum.hpp
2999
0644
edit
dl
rm
errors.hpp
1397
0644
edit
dl
rm
exception_translator.hpp
939
0644
edit
dl
rm
exec.hpp
1756
0644
edit
dl
rm
extract.hpp
5988
0644
edit
dl
rm
handle.hpp
4503
0644
edit
dl
rm
handle_fwd.hpp
455
0644
edit
dl
rm
has_back_reference.hpp
654
0644
edit
dl
rm
implicit.hpp
1111
0644
edit
dl
rm
import.hpp
476
0644
edit
dl
rm
init.hpp
11490
0644
edit
dl
rm
instance_holder.hpp
2063
0644
edit
dl
rm
iterator.hpp
4308
0644
edit
dl
rm
list.hpp
3611
0644
edit
dl
rm
long.hpp
1637
0644
edit
dl
rm
lvalue_from_pytype.hpp
3614
0644
edit
dl
rm
make_constructor.hpp
8579
0644
edit
dl
rm
make_function.hpp
4482
0644
edit
dl
rm
manage_new_object.hpp
1087
0644
edit
dl
rm
module.hpp
425
0644
edit
dl
rm
module_init.hpp
2173
0644
edit
dl
rm
numpy.hpp
1120
0644
edit
dl
rm
object.hpp
851
0644
edit
dl
rm
object_attributes.hpp
3019
0644
edit
dl
rm
object_call.hpp
810
0644
edit
dl
rm
object_core.hpp
13329
0644
edit
dl
rm
object_fwd.hpp
462
0644
edit
dl
rm
object_items.hpp
1974
0644
edit
dl
rm
object_operators.hpp
4494
0644
edit
dl
rm
object_protocol.hpp
2730
0644
edit
dl
rm
object_protocol_core.hpp
2080
0644
edit
dl
rm
object_slices.hpp
4090
0644
edit
dl
rm
opaque_pointer_converter.hpp
5929
0644
edit
dl
rm
operators.hpp
14278
0644
edit
dl
rm
other.hpp
901
0644
edit
dl
rm
overloads.hpp
437
0644
edit
dl
rm
override.hpp
3538
0644
edit
dl
rm
pointee.hpp
892
0644
edit
dl
rm
proxy.hpp
2653
0644
edit
dl
rm
ptr.hpp
1239
0644
edit
dl
rm
pure_virtual.hpp
3655
0644
edit
dl
rm
raw_function.hpp
1483
0644
edit
dl
rm
refcount.hpp
960
0644
edit
dl
rm
reference_existing_object.hpp
1310
0644
edit
dl
rm
register_ptr_to_python.hpp
769
0644
edit
dl
rm
return_arg.hpp
2799
0644
edit
dl
rm
return_by_value.hpp
724
0644
edit
dl
rm
return_internal_reference.hpp
1285
0644
edit
dl
rm
return_opaque_pointer.hpp
1290
0644
edit
dl
rm
return_value_policy.hpp
675
0644
edit
dl
rm
scope.hpp
1878
0644
edit
dl
rm
self.hpp
889
0644
edit
dl
rm
signature.hpp
7579
0644
edit
dl
rm
slice.hpp
10643
0644
edit
dl
rm
slice_nil.hpp
912
0644
edit
dl
rm
ssize_t.hpp
735
0644
edit
dl
rm
stl_iterator.hpp
1325
0644
edit
dl
rm
str.hpp
10765
0644
edit
dl
rm
tag.hpp
538
0644
edit
dl
rm
to_python_converter.hpp
2431
0644
edit
dl
rm
to_python_indirect.hpp
2973
0644
edit
dl
rm
to_python_value.hpp
5574
0644
edit
dl
rm
tuple.hpp
1758
0644
edit
dl
rm
type_id.hpp
5262
0644
edit
dl
rm
with_custodian_and_ward.hpp
3546
0644
edit
dl
rm
wrapper.hpp
1023
0644
edit
dl
rm
Edit:
/usr/include/boost/python/slice.hpp
(10643B)
#ifndef BOOST_PYTHON_SLICE_JDB20040105_HPP #define BOOST_PYTHON_SLICE_JDB20040105_HPP // Copyright (c) 2004 Jonathan Brandmeyer // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include <boost/python/detail/prefix.hpp> #include <boost/config.hpp> #include <boost/python/object.hpp> #include <boost/python/extract.hpp> #include <boost/python/converter/pytype_object_mgr_traits.hpp> #include <boost/iterator/iterator_traits.hpp> #include <iterator> #include <algorithm> namespace boost { namespace python { namespace detail { class BOOST_PYTHON_DECL slice_base : public object { public: // Get the Python objects associated with the slice. In principle, these // may be any arbitrary Python type, but in practice they are usually // integers. If one or more parameter is ommited in the Python expression // that created this slice, than that parameter is None here, and compares // equal to a default-constructed boost::python::object. // If a user-defined type wishes to support slicing, then support for the // special meaning associated with negative indices is up to the user. object start() const; object stop() const; object step() const; protected: explicit slice_base(PyObject*, PyObject*, PyObject*); BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(slice_base, object) }; } class slice : public detail::slice_base { typedef detail::slice_base base; public: // Equivalent to slice(::) slice() : base(0,0,0) {} // Each argument must be slice_nil, or implicitly convertable to object. // They should normally be integers. template<typename Integer1, typename Integer2> slice( Integer1 start, Integer2 stop) : base( object(start).ptr(), object(stop).ptr(), 0 ) {} template<typename Integer1, typename Integer2, typename Integer3> slice( Integer1 start, Integer2 stop, Integer3 stride) : base( object(start).ptr(), object(stop).ptr(), object(stride).ptr() ) {} // The following algorithm is intended to automate the process of // determining a slice range when you want to fully support negative // indices and non-singular step sizes. Its functionallity is simmilar to // PySlice_GetIndicesEx() in the Python/C API, but tailored for C++ users. // This template returns a slice::range struct that, when used in the // following iterative loop, will traverse a slice of the function's // arguments. // while (start != end) { // do_foo(...); // std::advance( start, step); // } // do_foo(...); // repeat exactly once more. // Arguments: a [begin, end) pair of STL-conforming random-access iterators. // Return: slice::range, where start and stop define a _closed_ interval // that covers at most [begin, end-1] of the provided arguments, and a step // that is non-zero. // Throws: error_already_set() if any of the indices are neither None nor // integers, or the slice has a step value of zero. // std::invalid_argument if the resulting range would be empty. Normally, // you should catch this exception and return an empty sequence of the // appropriate type. // Performance: constant time for random-access iterators. // Rationale: // closed-interval: If an open interval were used, then for a non-singular // value for step, the required state for the end iterator could be // beyond the one-past-the-end postion of the specified range. While // probably harmless, the behavior of STL-conforming iterators is // undefined in this case. // exceptions on zero-length range: It is impossible to define a closed // interval over an empty range, so some other form of error checking // would have to be used by the user to prevent undefined behavior. In // the case where the user fails to catch the exception, it will simply // be translated to Python by the default exception handling mechanisms. template<typename RandomAccessIterator> struct range { RandomAccessIterator start; RandomAccessIterator stop; typename iterator_difference<RandomAccessIterator>::type step; }; template<typename RandomAccessIterator> slice::range<RandomAccessIterator> get_indices( const RandomAccessIterator& begin, const RandomAccessIterator& end) const { // This is based loosely on PySlice_GetIndicesEx(), but it has been // carefully crafted to ensure that these iterators never fall out of // the range of the container. slice::range<RandomAccessIterator> ret; typedef typename iterator_difference<RandomAccessIterator>::type difference_type; difference_type max_dist = std::distance(begin, end); object slice_start = this->start(); object slice_stop = this->stop(); object slice_step = this->step(); // Extract the step. if (slice_step == object()) { ret.step = 1; } else { ret.step = extract<long>( slice_step); if (ret.step == 0) { PyErr_SetString( PyExc_IndexError, "step size cannot be zero."); throw_error_already_set(); } } // Setup the start iterator. if (slice_start == object()) { if (ret.step < 0) { ret.start = end; --ret.start; } else ret.start = begin; } else { difference_type i = extract<long>( slice_start); if (i >= max_dist && ret.step > 0) throw std::invalid_argument( "Zero-length slice"); if (i >= 0) { ret.start = begin; BOOST_USING_STD_MIN(); std::advance( ret.start, min BOOST_PREVENT_MACRO_SUBSTITUTION(i, max_dist-1)); } else { if (i < -max_dist && ret.step < 0) throw std::invalid_argument( "Zero-length slice"); ret.start = end; // Advance start (towards begin) not farther than begin. std::advance( ret.start, (-i < max_dist) ? i : -max_dist ); } } // Set up the stop iterator. This one is a little trickier since slices // define a [) range, and we are returning a [] range. if (slice_stop == object()) { if (ret.step < 0) { ret.stop = begin; } else { ret.stop = end; std::advance( ret.stop, -1); } } else { difference_type i = extract<long>(slice_stop); // First, branch on which direction we are going with this. if (ret.step < 0) { if (i+1 >= max_dist || i == -1) throw std::invalid_argument( "Zero-length slice"); if (i >= 0) { ret.stop = begin; std::advance( ret.stop, i+1); } else { // i is negative, but more negative than -1. ret.stop = end; std::advance( ret.stop, (-i < max_dist) ? i : -max_dist); } } else { // stepping forward if (i == 0 || -i >= max_dist) throw std::invalid_argument( "Zero-length slice"); if (i > 0) { ret.stop = begin; std::advance( ret.stop, (std::min)( i-1, max_dist-1)); } else { // i is negative, but not more negative than -max_dist ret.stop = end; std::advance( ret.stop, i-1); } } } // Now the fun part, handling the possibilites surrounding step. // At this point, step has been initialized, ret.stop, and ret.step // represent the widest possible range that could be traveled // (inclusive), and final_dist is the maximum distance covered by the // slice. typename iterator_difference<RandomAccessIterator>::type final_dist = std::distance( ret.start, ret.stop); // First case, if both ret.start and ret.stop are equal, then step // is irrelevant and we can return here. if (final_dist == 0) return ret; // Second, if there is a sign mismatch, than the resulting range and // step size conflict: std::advance( ret.start, ret.step) goes away from // ret.stop. if ((final_dist > 0) != (ret.step > 0)) throw std::invalid_argument( "Zero-length slice."); // Finally, if the last step puts us past the end, we move ret.stop // towards ret.start in the amount of the remainder. // I don't remember all of the oolies surrounding negative modulii, // so I am handling each of these cases separately. if (final_dist < 0) { difference_type remainder = -final_dist % -ret.step; std::advance( ret.stop, remainder); } else { difference_type remainder = final_dist % ret.step; std::advance( ret.stop, -remainder); } return ret; } // Incorrect spelling. DO NOT USE. Only here for backward compatibility. // Corrected 2011-06-14. template<typename RandomAccessIterator> slice::range<RandomAccessIterator> get_indicies( const RandomAccessIterator& begin, const RandomAccessIterator& end) const { return get_indices(begin, end); } public: // This declaration, in conjunction with the specialization of // object_manager_traits<> below, allows C++ functions accepting slice // arguments to be called from from Python. These constructors should never // be used in client code. BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(slice, detail::slice_base) }; namespace converter { template<> struct object_manager_traits<slice> : pytype_object_manager_traits<&PySlice_Type, slice> { }; } // !namesapce converter } } // !namespace ::boost::python #endif // !defined BOOST_PYTHON_SLICE_JDB20040105_HPP
Save
cmd:
run