From 03c956b84ae0dac4e872a70a68d135f28d4a3767 Mon Sep 17 00:00:00 2001 From: nobody Date: Sat, 20 Aug 2005 22:18:16 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'start'. [SVN r2692] --- .../indexing/detail2/python_iterator.cpp | 168 ------------------ .../python/suite/indexing/detail2/slice.cpp | 65 ------- 2 files changed, 233 deletions(-) delete mode 100755 include/boost/python/suite/indexing/detail2/python_iterator.cpp delete mode 100755 include/boost/python/suite/indexing/detail2/slice.cpp diff --git a/include/boost/python/suite/indexing/detail2/python_iterator.cpp b/include/boost/python/suite/indexing/detail2/python_iterator.cpp deleted file mode 100755 index 015171a4..00000000 --- a/include/boost/python/suite/indexing/detail2/python_iterator.cpp +++ /dev/null @@ -1,168 +0,0 @@ -// -*- mode:c++ -*- -// -// Module python_iterator.cpp -// -// Copyright (c) 2003 Raoul M. Gough -// -// Use, modification and distribution is 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) -// -// History -// ======= -// 2003/ 9/10 rmg File creation -// -// $Id$ -// - -#include - -//////////////////////////////////////////////////////////////////////////// -// python_iterator factory -/////////////////////////////////////////////////////////////////////////// - -std::auto_ptr -boost::python::indexing::make_iterator (boost::python::object temp) -{ - std::auto_ptr result; - - try - { - result.reset (new python_iter_iterator (temp)); - } - - catch (boost::python::error_already_set const &) - { - PyErr_Clear (); - - try - { - result.reset (new python_getitem_iterator (temp)); - } - - catch (boost::python::error_already_set const &) - { - PyErr_Clear (); - } - } - - return result; -} - -//////////////////////////////////////////////////////////////////////////// -// Base class (virtual) destructor -/////////////////////////////////////////////////////////////////////////// - -boost::python::indexing::python_iterator::~python_iterator () -{ -} - -//////////////////////////////////////////////////////////////////////////// -// python_getitem_iterator constructor -/////////////////////////////////////////////////////////////////////////// - -boost::python::indexing::python_getitem_iterator -::python_getitem_iterator (boost::python::object obj) - : mGetitemMethod (obj.attr ("__getitem__")) - , mIndex (0) - , mCurrent() -{ -} - -//////////////////////////////////////////////////////////////////////////// -// Get our next item (if any) -/////////////////////////////////////////////////////////////////////////// - -bool boost::python::indexing::python_getitem_iterator::next () -{ - bool result = true; // Assume success - - try - { - mCurrent = mGetitemMethod (mIndex); - ++mIndex; - } - - catch (boost::python::error_already_set const &) - { - if (PyErr_ExceptionMatches (PyExc_IndexError)) - { - // Eat this exception - PyErr_Clear (); - mCurrent = boost::python::object (); - result = false; - } - - else - { - // Pass it up the line - throw; - } - } - - return result; -} - -//////////////////////////////////////////////////////////////////////////// -// Return our current item -/////////////////////////////////////////////////////////////////////////// - -boost::python::object -boost::python::indexing::python_getitem_iterator::current () const -{ - return mCurrent; -} - -//////////////////////////////////////////////////////////////////////////// -// python_iter_iterator constructor -/////////////////////////////////////////////////////////////////////////// - -boost::python::indexing::python_iter_iterator -::python_iter_iterator (boost::python::object obj) - : mNextMethod (obj.attr ("__iter__")().attr ("next")) - , mCurrent() -{ -} - -//////////////////////////////////////////////////////////////////////////// -// Get our next item (if any) -/////////////////////////////////////////////////////////////////////////// - -bool boost::python::indexing::python_iter_iterator::next () -{ - bool result = true; // Assume success - - try - { - mCurrent = mNextMethod (); - } - - catch (boost::python::error_already_set const &) - { - if (PyErr_ExceptionMatches (PyExc_StopIteration)) - { - // Eat this exception - PyErr_Clear (); - mCurrent = boost::python::object (); - result = false; - } - - else - { - // Pass it up the line - throw; - } - } - - return result; -} - -//////////////////////////////////////////////////////////////////////////// -// Return our current item -/////////////////////////////////////////////////////////////////////////// - -boost::python::object -boost::python::indexing::python_iter_iterator::current () const -{ - return mCurrent; -} diff --git a/include/boost/python/suite/indexing/detail2/slice.cpp b/include/boost/python/suite/indexing/detail2/slice.cpp deleted file mode 100755 index cfd740bb..00000000 --- a/include/boost/python/suite/indexing/detail2/slice.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// -*- mode:c++ -*- -// -// Module slice.cpp -// -// Copyright (c) 2003 Raoul M. Gough -// -// Use, modification and distribution is 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) -// -// History -// ======= -// 2003/ 9/10 rmg File creation -// -// $Id$ -// - -#include - -///////////////////////////////////////////////////////////////////////////// -// Check that setLength has been called, and throw otherwise -///////////////////////////////////////////////////////////////////////////// - -void boost::python::indexing::slice::validate () const -{ - if (mDirection == 0) - { - PyErr_SetString (PyExc_RuntimeError - , "slice access attempted before setLength called"); - boost::python::throw_error_already_set(); - } -} - -///////////////////////////////////////////////////////////////////////////// -// Set up our member variables for a sequence of a given length -///////////////////////////////////////////////////////////////////////////// - -void boost::python::indexing::slice::setLength (int sequenceLength) -{ - PySlice_GetIndices ((PySliceObject *) this->ptr() - , sequenceLength - , &mStart - , &mStop - , &mStep); - - if (mStep == 0) - { - // Can happen with Python prior to 2.3 - PyErr_SetString (PyExc_ValueError, "slice step cannot be zero"); - boost::python::throw_error_already_set (); - } - - mStart = std::max (0, std::min (sequenceLength, mStart)); - mStop = std::max (0, std::min (sequenceLength, mStop)); - mDirection = (mStep > 0) ? 1 : -1; -} - -///////////////////////////////////////////////////////////////////////////// -// Check if an index is within the range of this slice -///////////////////////////////////////////////////////////////////////////// - -bool boost::python::indexing::slice::inRange (int index) -{ - return ((mStop - index) * mDirection) > 0; -}