Revision: 1457
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1457&view=rev
Author: roman_yakovenko
Date: 2008-11-27 20:28:46 +0000 (Thu, 27 Nov 2008)
Log Message:
-----------
making indexing suite v2 functionality to be header only
Modified Paths:
--------------
pyplusplus_dev/indexing_suite_v2/indexing/python_iterator.hpp
pyplusplus_dev/indexing_suite_v2/indexing/slice.hpp
pyplusplus_dev/indexing_suite_v2/readme.txt
Modified: pyplusplus_dev/indexing_suite_v2/indexing/python_iterator.hpp
===================================================================
--- pyplusplus_dev/indexing_suite_v2/indexing/python_iterator.hpp 2008-11-26 22:03:00 UTC (rev 1456)
+++ pyplusplus_dev/indexing_suite_v2/indexing/python_iterator.hpp 2008-11-27 20:28:46 UTC (rev 1457)
@@ -16,23 +16,58 @@
//
// $Id: python_iterator.hpp,v 1.1.2.5 2003/11/24 16:35:09 raoulgough Exp $
//
+// 2008 November 27 Roman Yakovenko
+// implementation of the member functions was moved from cpp to header.
+// this was done to simplify "installation" procedure.
#ifndef BOOST_PYTHON_INDEXING_PYTHON_ITERATOR_HPP
#define BOOST_PYTHON_INDEXING_PYTHON_ITERATOR_HPP
#include <boost/python/object.hpp>
+#include <boost/python/handle.hpp>
namespace boost { namespace python { namespace indexing {
struct BOOST_PYTHON_DECL python_iterator
{
- python_iterator (boost::python::object);
+ python_iterator (boost::python::object obj)
+ : m_iter_obj (handle<> (PyObject_GetIter (obj.ptr()))),
+ m_next_method (m_iter_obj.attr ("next")),
+ m_current()
+ {
+ }
+
// Sets a python type exception and calls throw_error_already_set if
// the passed object is not iterable via PyObject_GetIter
- bool next ();
+ bool next ()
+ {
+ bool result = true; // Assume success
+
+ try
+ {
+ m_current = m_next_method ();
+ }
+ catch (boost::python::error_already_set const &)
+ {
+ if (PyErr_ExceptionMatches (PyExc_StopIteration))
+ {
+ // Eat this exception
+ PyErr_Clear ();
+ m_current = boost::python::object (); // No current object
+ result = false; // Report failure via return value only
+ }
+ else
+ {
+ // Pass it up the line
+ throw;
+ }
+ }
+ return result;
+ }
// Get the next item from the iterator, returning true for success
- boost::python::object current() const;
+ boost::python::object current() const
+ { return m_current; }
// Callable only after a successful next()
private:
Modified: pyplusplus_dev/indexing_suite_v2/indexing/slice.hpp
===================================================================
--- pyplusplus_dev/indexing_suite_v2/indexing/slice.hpp 2008-11-26 22:03:00 UTC (rev 1456)
+++ pyplusplus_dev/indexing_suite_v2/indexing/slice.hpp 2008-11-27 20:28:46 UTC (rev 1457)
@@ -12,6 +12,9 @@
//
// $Id: slice.hpp,v 1.1.2.10 2003/11/24 14:28:31 raoulgough Exp $
//
+// 2008 November 27 Roman Yakovenko
+// implementation of the member functions was moved from cpp to header.
+// this was done to simplify "installation" procedure.
#ifndef BOOST_PYTHON_INDEXING_SLICE_HPP
#define BOOST_PYTHON_INDEXING_SLICE_HPP
@@ -19,6 +22,7 @@
#include <boost/python/object.hpp>
#include <boost/python/errors.hpp>
#include <boost/python/converter/pytype_object_mgr_traits.hpp>
+#include <algorithm>
namespace boost { namespace python { namespace indexing {
struct BOOST_PYTHON_DECL slice : public boost::python::object
@@ -31,16 +35,29 @@
// MSVC6 doesn't seem to be able to invoke the templated
// constructor, so provide explicit overloads to match the
// (currently) known boost::python::object constructors
- explicit slice (::boost::python::handle<> const&);
- explicit slice (::boost::python::detail::borrowed_reference);
- explicit slice (::boost::python::detail::new_reference);
- explicit slice (::boost::python::detail::new_non_null_reference);
+ explicit slice (::boost::python::handle<> const& p)
+ : object (p)
+ {}
+
+ explicit slice (::boost::python::detail::borrowed_reference p)
+ : object (p)
+ {}
+
+ explicit slice (::boost::python::detail::new_reference p)
+ : object (p)
+ {}
+
+ explicit slice (::boost::python::detail::new_non_null_reference p)
+ : object (p)
+ {}
#else
// Better compilers make life easier
template<typename T> inline slice (T const &ref);
#endif
- slice (slice const &); // Copy constructor
+ slice (slice const & copy) // Copy constructor
+ : object (copy)
+ {}
};
struct BOOST_PYTHON_DECL integer_slice
@@ -54,7 +71,28 @@
typedef Py_ssize_t index_type;
#endif
- integer_slice (slice const &, index_type length);
+ integer_slice (slice const & sl, index_type length)
+ : m_slice (sl) // Leave index members uninitialized
+ {
+ PySlice_GetIndices(
+ reinterpret_cast<PySliceObject *> (m_slice.ptr()),
+ length,
+ &m_start,
+ &m_stop,
+ &m_step);
+
+ if (m_step == 0)
+ {
+ // Can happen with Python prior to 2.3
+ PyErr_SetString (PyExc_ValueError, "slice step cannot be zero");
+ boost::python::throw_error_already_set ();
+ }
+
+ m_start = std::max (static_cast<index_type> (0), std::min (length, m_start));
+ m_stop = std::max (static_cast<index_type> (0), std::min (length, m_stop));
+ m_direction = (m_step > 0) ? 1 : -1;
+ }
+
// integer_slice must know how big the container is so it can
// adjust for negative indexes, etc...
@@ -64,7 +102,8 @@
index_type size() const { return (m_stop - m_start) / m_step; }
- bool in_range (index_type index);
+ bool in_range (index_type index)
+ { return ((m_stop - index) * m_direction) > 0; }
private:
slice m_slice;
Modified: pyplusplus_dev/indexing_suite_v2/readme.txt
===================================================================
--- pyplusplus_dev/indexing_suite_v2/readme.txt 2008-11-26 22:03:00 UTC (rev 1456)
+++ pyplusplus_dev/indexing_suite_v2/readme.txt 2008-11-27 20:28:46 UTC (rev 1457)
@@ -1,3 +1,10 @@
This directory contains indexing suite version developed by Raoul Gough.
-Almost every directory contains "readme.txt" file. Those files contain
-installation instructions.
\ No newline at end of file
+
+Installation instructions: copy "indexing" directory to "boost/python/suite" one.
+
+Changes from original version
+* bug fixes
+* support for 64Bit platforms was added
+* std::map and std::multimap containers got iteration functionality
+* the suite was made to be "header only"
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|