mirror of
https://github.com/boostorg/python.git
synced 2026-01-27 19:12:16 +00:00
Add (and use) index_type typedef
[SVN r20376]
This commit is contained in:
@@ -39,24 +39,26 @@ namespace boost { namespace python { namespace indexing {
|
||||
// This class provides a convenient interface to Python slice
|
||||
// objects that contain integer bound and stride values.
|
||||
|
||||
integer_slice (slice const &, int sequenceLength);
|
||||
typedef int index_type;
|
||||
|
||||
integer_slice (slice const &, index_type sequenceLength);
|
||||
// integer_slice must know how big the container is so it can
|
||||
// adjust for negative indexes, etc...
|
||||
|
||||
int start() const { return mStart; }
|
||||
int step() const { return mStep; }
|
||||
int stop() const { return mStop; }
|
||||
index_type start() const { return mStart; }
|
||||
index_type step() const { return mStep; }
|
||||
index_type stop() const { return mStop; }
|
||||
|
||||
int size() const { return (mStop - mStart) / mStep; }
|
||||
index_type size() const { return (mStop - mStart) / mStep; }
|
||||
|
||||
bool in_range (int index);
|
||||
bool in_range (index_type index);
|
||||
|
||||
private:
|
||||
slice mSlice;
|
||||
int mStart;
|
||||
int mStep;
|
||||
int mStop;
|
||||
int mDirection;
|
||||
index_type mStart;
|
||||
index_type mStep;
|
||||
index_type mStop;
|
||||
index_type mDirection;
|
||||
};
|
||||
} } }
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ boost::python::indexing::slice::slice (slice const ©)
|
||||
// integer_slice constructor
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boost::python::indexing::integer_slice::integer_slice (slice const &sl
|
||||
, int sequenceLength)
|
||||
boost::python::indexing::integer_slice
|
||||
::integer_slice (slice const &sl, index_type sequenceLength)
|
||||
: mSlice (sl)
|
||||
// Leave int members uninitialized
|
||||
// Leave index members uninitialized
|
||||
{
|
||||
PySlice_GetIndices (reinterpret_cast<PySliceObject *> (mSlice.ptr())
|
||||
, sequenceLength
|
||||
@@ -58,7 +58,7 @@ boost::python::indexing::integer_slice::integer_slice (slice const &sl
|
||||
// Check if an index is within the range of this integer_slice
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool boost::python::indexing::integer_slice::in_range (int index)
|
||||
bool boost::python::indexing::integer_slice::in_range (index_type index)
|
||||
{
|
||||
return ((mStop - index) * mDirection) > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user