[pygccxml-commit] SF.net SVN: pygccxml:[1595] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2009-01-19 22:29:16
|
Revision: 1595 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1595&view=rev Author: roman_yakovenko Date: 2009-01-19 21:57:33 +0000 (Mon, 19 Jan 2009) Log Message: ----------- embedding indexing suite v2 Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_repository/__init__.py pyplusplus_dev/pyplusplus/file_writers/writer.py Added Paths: ----------- pyplusplus_dev/indexing_suite_v2/update_code_repository.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/ pyplusplus_dev/pyplusplus/code_repository/indexing_suite/__init__.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/algorithms_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_proxy_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_suite_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_traits_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/deque_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/element_proxy_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/element_proxy_traits_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/int_slice_helper_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/iterator_range_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/iterator_traits_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/list_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/map_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/methods_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/multimap_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/pair_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/proxy_iterator_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/python_iterator_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/set_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/shared_proxy_impl_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/slice_handler_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/slice_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/suite_utils_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/value_traits_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/vector_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/visitor_header.py pyplusplus_dev/pyplusplus/code_repository/indexing_suite/workaround_header.py Added: pyplusplus_dev/indexing_suite_v2/update_code_repository.py =================================================================== --- pyplusplus_dev/indexing_suite_v2/update_code_repository.py (rev 0) +++ pyplusplus_dev/indexing_suite_v2/update_code_repository.py 2009-01-19 21:57:33 UTC (rev 1595) @@ -0,0 +1,79 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under 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) + +"""updates code repository""" + +import os +import sys + +header_tmpl = \ +'''# Copyright 2004-2008 Roman Yakovenko. +# Distributed under 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) + +""" +This file contains indexing suite v2 code +""" + +file_name = "%(file_path)s" + +code = \ +"""%(code)s + +""" +''' + +init_code = [ +'''# Copyright 2004-2008 Roman Yakovenko. +# Distributed under 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) + +""" +code repository for Indexing Suite V2 - std containers wrappers +""" + +all = [] +'''] + +pyplusplus_dev_root = os.path.dirname( os.path.dirname( os.path.abspath( __file__ ) ) ) +source_dir = os.path.join( pyplusplus_dev_root, 'indexing_suite_v2', 'indexing_suite' ) +target_dir = os.path.join( pyplusplus_dev_root, 'pyplusplus', 'code_repository', 'indexing_suite' ) + +if not os.path.exists( target_dir ): + os.mkdir( target_dir ) + +for f in os.listdir( source_dir ): + name, ext = os.path.splitext( f ) + if ext != '.hpp': + print 'file "%s" was skipped' % f + continue + else: + print 'converting file "%s"' % f + file_path = 'indexing_suite/' + f + code = file( os.path.join( source_dir, f ), 'r' ).read() + py_name = name + '_header' + py_file = file( os.path.join( target_dir, py_name + '.py' ), 'w+' ) + py_file.write( header_tmpl % dict( file_path=file_path, code=code ) ) + py_file.close() + init_code.append( 'import %s' % py_name ) + init_code.append( 'all.append( %s )' % py_name ) + init_code.append( '' ) + +init_code.append( 'headers = map( lambda f: f.file_name, all )' ) + +print 'creating __init__.py file' + +init_file = file( os.path.join( target_dir, '__init__.py' ), 'w+' ) +init_file.write( '\n'.join( init_code ) ) +init_file.close() + + + + + + + Modified: pyplusplus_dev/pyplusplus/code_repository/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/__init__.py 2009-01-19 21:55:39 UTC (rev 1594) +++ pyplusplus_dev/pyplusplus/code_repository/__init__.py 2009-01-19 21:57:33 UTC (rev 1595) @@ -18,8 +18,9 @@ import named_tuple import convenience import return_range +import ctypes_utils import call_policies -import ctypes_utils +import indexing_suite import ctypes_integration all = [ array_1 @@ -31,5 +32,15 @@ , ctypes_utils , ctypes_integration ] +all.extend( indexing_suite.all ) + headers = map( lambda f: f.file_name, all ) +def i_depend_on_them( fname ): + """returns list of files, the file fname depends on""" + if fname in indexing_suite.headers: + result = indexing_suite.all[:] + del result[ indexing_suite.headers.index( fname ) ] + return result + else: + return [] Added: pyplusplus_dev/pyplusplus/code_repository/indexing_suite/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/indexing_suite/__init__.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_repository/indexing_suite/__init__.py 2009-01-19 21:57:33 UTC (rev 1595) @@ -0,0 +1,91 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under 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) + +""" +code repository for Indexing Suite V2 - std containers wrappers +""" + +all = [] + +import algorithms_header +all.append( algorithms_header ) + +import container_proxy_header +all.append( container_proxy_header ) + +import container_suite_header +all.append( container_suite_header ) + +import container_traits_header +all.append( container_traits_header ) + +import deque_header +all.append( deque_header ) + +import element_proxy_header +all.append( element_proxy_header ) + +import element_proxy_traits_header +all.append( element_proxy_traits_header ) + +import int_slice_helper_header +all.append( int_slice_helper_header ) + +import iterator_range_header +all.append( iterator_range_header ) + +import iterator_traits_header +all.append( iterator_traits_header ) + +import list_header +all.append( list_header ) + +import map_header +all.append( map_header ) + +import methods_header +all.append( methods_header ) + +import multimap_header +all.append( multimap_header ) + +import pair_header +all.append( pair_header ) + +import proxy_iterator_header +all.append( proxy_iterator_header ) + +import python_iterator_header +all.append( python_iterator_header ) + +import set_header +all.append( set_header ) + +import shared_proxy_impl_header +all.append( shared_proxy_impl_header ) + +import slice_header +all.append( slice_header ) + +import slice_handler_header +all.append( slice_handler_header ) + +import suite_utils_header +all.append( suite_utils_header ) + +import value_traits_header +all.append( value_traits_header ) + +import vector_header +all.append( vector_header ) + +import visitor_header +all.append( visitor_header ) + +import workaround_header +all.append( workaround_header ) + +headers = map( lambda f: f.file_name, all ) + Added: pyplusplus_dev/pyplusplus/code_repository/indexing_suite/algorithms_header.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/indexing_suite/algorithms_header.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_repository/indexing_suite/algorithms_header.py 2009-01-19 21:57:33 UTC (rev 1595) @@ -0,0 +1,578 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under 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) + +""" +This file contains indexing suite v2 code +""" + +file_name = "indexing_suite/algorithms.hpp" + +code = """// Header file algorithms.hpp +// +// Uniform interface layer for all containers. +// +// 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/11 rmg File creation from suite_utils.hpp +// 2003/10/28 rmg Split container-specific versions into separate headers +// 2006/10/25 Roman Adding keys function to assoc_algorithms class +// 2008/12/08 Roman Change indexing suite layout +// +// $Id: algorithms.hpp,v 1.1.2.15 2004/02/08 18:57:42 raoulgough Exp $ +// + +#ifndef BOOST_PYTHON_INDEXING_ALGORITHMS_HPP +#define BOOST_PYTHON_INDEXING_ALGORITHMS_HPP + +#include <indexing_suite/suite_utils.hpp> + +#include <boost/type_traits.hpp> +#include <boost/python/errors.hpp> +#include <indexing_suite/int_slice_helper.hpp> +#include <indexing_suite/slice.hpp> +#include <boost/mpl/if.hpp> +#include <boost/limits.hpp> +#include <algorithm> +#include <functional> +#include <stdexcept> +#include <string> +#include <set> + +namespace boost { namespace python { namespace indexing { + template<typename ContainerTraits, typename Ovr = detail::no_override> + class default_algorithms + { + typedef default_algorithms<ContainerTraits, Ovr> self_type; + typedef typename detail::maybe_override<self_type, Ovr> + ::type most_derived; + + public: + typedef ContainerTraits container_traits; + + // Import typedefs from the container_traits for convenience + typedef typename ContainerTraits::container container; + typedef typename ContainerTraits::iterator iterator; + typedef typename ContainerTraits::reference reference; + typedef typename ContainerTraits::size_type size_type; + typedef typename ContainerTraits::value_type value_type; + typedef typename ContainerTraits::value_param value_param; + typedef typename ContainerTraits::index_param index_param; + typedef typename ContainerTraits::key_param key_param; + + // Defer selection of supported_methods to the ContainerTraits + // template argument. This makes sense because default_algorithms + // derives all of its other information from this argument, and + // can't decide which of the static member functions will + // instantiate successfully for the container. Obviously a + // custom-written Algorithms implementation could choose to + // provide the supported_methods directly. + + BOOST_STATIC_CONSTANT( + method_set_type, + supported_methods = ContainerTraits::supported_methods); + + static size_type size (container &); + static iterator find (container &, key_param); + static size_type get_index (container &, key_param); + static size_type count (container &, key_param); + static bool contains (container &, key_param); + static void reverse (container &); + static reference get (container &, index_param); + static void assign (container &, index_param, value_param); + static void insert (container &, index_param, value_param); + static void erase_one (container &, index_param); + static void erase_range(container &, index_param, index_param); + static void push_back (container &, value_param); + static void sort (container &); + // static void sort (container &, PyObject *); + + static iterator begin (container &c) { return c.begin(); } + static iterator end (container &c) { return c.end(); } + + // Reasonable defaults for slice handling + typedef int_slice_helper<self_type, integer_slice> slice_helper; + + static slice_helper make_slice_helper (container &c, slice const &); + + // Default visit_container_class + template<typename PythonClass, typename Policy> + static void visit_container_class( + PythonClass &pyClass, Policy const &policy) + { + container_traits::visit_container_class (pyClass, policy); + } + +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) + // MSVC6 and 7.0 seem to complain about most_derived::bounds_check + // for an instantiation of list_algorithms. + public: +#else + private: +#endif + static size_type bounds_check( + container &, index_param, char const *msg, + bool one_past = false, + bool truncate = false); + // Throws std::out_of_range if necessary. If one_past is set, then + // indexes up to container.size() *inclusive* are allowed. If + // truncate is set, then out of bounds values are reset to the + // nearest in-bound value (and if none exists, throws an + // exception). If truncate is *not* set, then negative values index + // from the upper bound backwards and are bounds-checked. + }; + + ///////////////////////////////////////////////////////////////////////// + // Base class for associative containers + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr = detail::no_override> + class assoc_algorithms + : public default_algorithms + <ContainerTraits, + BOOST_DEDUCED_TYPENAME detail::maybe_override + <assoc_algorithms<ContainerTraits, Ovr>, Ovr> + ::type> + { + typedef assoc_algorithms<ContainerTraits, Ovr> self_type; + typedef typename detail::maybe_override<self_type, Ovr> + ::type most_derived; + typedef default_algorithms<ContainerTraits, most_derived> Parent; + + public: + typedef typename Parent::iterator iterator; + typedef typename Parent::size_type size_type; + typedef typename Parent::container container; + typedef typename Parent::reference reference; + typedef typename Parent::key_param key_param; + typedef typename Parent::value_param value_param; + typedef typename Parent::index_param index_param; + + static reference get (container &, index_param); + + // Use member functions for the following (hiding base class versions) + static void erase_one (container &, key_param); + static iterator find (container &, key_param); + static size_type count (container &, key_param); + static bool contains (container &, key_param); + + // Default visit_container_class + template<typename PythonClass, typename Policy> + static void visit_container_class( PythonClass &pyClass, Policy const &policy) + { + ContainerTraits::visit_container_class (pyClass, policy); + } + + + protected: + static iterator find_or_throw (container &, index_param); + }; + + ///////////////////////////////////////////////////////////////////////// + // Get the size of a container + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::size_type + default_algorithms<ContainerTraits, Ovr>::size (container &c) + { + return c.size(); + } + + ///////////////////////////////////////////////////////////////////////// + // Range check an index and throw out_of_range if necessary + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::size_type + default_algorithms<ContainerTraits, Ovr>::bounds_check( + container &c, + index_param ix, + char const *msg, + bool one_past, + bool truncate) + { + size_type bound = most_derived::size(c) + (one_past ? 1 : 0); + size_type result; + + if (truncate) + { + if (ix < 0) + { + result = 0; + } + + else + { + result = ix; + + if ((result >= bound) && (bound > 0)) + { + result = bound - 1; + } + } + } + + else if (ix < 0) + { + if (size_type(-ix) > bound) + { + throw std::out_of_range (msg); + } + + result = bound + ix; + } + + else + { + result = ix; + } + + if (result >= bound) + { + throw std::out_of_range (msg); + } + + return result; + } + + ///////////////////////////////////////////////////////////////////////// + // Find an element in a container (std algorithm version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::iterator + default_algorithms<ContainerTraits, Ovr>::find( + container &c, key_param key) + { + typedef typename container_traits::value_traits_type vtraits; + typedef typename vtraits::equal_to comparison; + + return std::find_if( + most_derived::begin(c), + most_derived::end(c), + std::bind1st (comparison(), key)); + } + + ///////////////////////////////////////////////////////////////////////// + // Find an element and return its index (std algorithm version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::size_type + default_algorithms<ContainerTraits, Ovr>::get_index( + container &c, key_param key) + { + iterator found (most_derived::find (c, key)); + + if (found == most_derived::end(c)) + { + PyErr_SetString( + PyExc_ValueError, "get_index: element not found"); + + boost::python::throw_error_already_set (); + } + + iterator start (most_derived::begin (c)); + return std::distance (start, found); + } + + ///////////////////////////////////////////////////////////////////////// + // Count occurances of an element in a container (std algorithm version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::size_type + default_algorithms<ContainerTraits, Ovr>::count( + container &c, key_param key) + { + typedef typename container_traits::value_traits_type vtraits; + typedef typename vtraits::equal_to comparison; + + return std::count_if( + most_derived::begin(c), + most_derived::end(c), + std::bind1st (comparison(), key)); + } + + ///////////////////////////////////////////////////////////////////////// + // Check whether a container contains the given element (std algo ver) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + bool + default_algorithms<ContainerTraits, Ovr>::contains( + container &c, key_param key) + { + return most_derived::find (c, key) != most_derived::end(c); + } + + ///////////////////////////////////////////////////////////////////////// + // Index into a container (generic version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::reference + default_algorithms<ContainerTraits, Ovr>::get( + container &c, index_param ix) + { + return c[most_derived::bounds_check (c, ix, "get")]; + } + + ///////////////////////////////////////////////////////////////////////// + // Assign a value at a particular index (generic version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void + default_algorithms<ContainerTraits, Ovr>::assign( + container &c, index_param ix, value_param val) + { + c[most_derived::bounds_check (c, ix, "assign")] = val; + } + + ///////////////////////////////////////////////////////////////////////// + // Insert at end of a container (generic version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void + default_algorithms<ContainerTraits, Ovr>::push_back( + container &c, value_param v) + { + c.push_back (v); + } + + ///////////////////////////////////////////////////////////////////////// + // Insert at an index in the container (generic version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void + default_algorithms<ContainerTraits, Ovr>::insert( + container &c, index_param i, value_param v) + { + iterator insert_pos (most_derived::begin(c)); + + // Index may range up to c.size() inclusive to allow inserting at end + std::advance( + insert_pos, most_derived::bounds_check (c, i, "insert", true, true)); + + c.insert (insert_pos, v); + } + + ///////////////////////////////////////////////////////////////////////// + // Erase between given indexes in the container (generic version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void + default_algorithms<ContainerTraits, Ovr>::erase_range( + container &c, index_param from, index_param to) + { + iterator start (most_derived::begin(c)); + iterator finish (most_derived::begin(c)); + + // Start index must be properly in bounds + std::advance + (start, most_derived::bounds_check (c, from, "erase_range (from)")); + + // End index is one-past-the-end, so may range up to c.size() inclusive + std::advance + (finish, most_derived::bounds_check (c, to, "erase_range (to)", true)); + + c.erase (start, finish); + } + + ///////////////////////////////////////////////////////////////////////// + // Erase one element at the given index in the container (generic version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void + default_algorithms<ContainerTraits, Ovr>::erase_one( + container &c, index_param ix) + { + iterator iter (most_derived::begin(c)); + std::advance (iter, most_derived::bounds_check (c, ix, "erase_one")); + c.erase (iter); + } + + ///////////////////////////////////////////////////////////////////////// + // Reverse the contents of a container (std algorithm version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void default_algorithms<ContainerTraits, Ovr>::reverse (container &c) + { + std::reverse (most_derived::begin(c), most_derived::end(c)); + } + + ///////////////////////////////////////////////////////////////////////// + // Sort the contents of a container (std algorithm version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void default_algorithms<ContainerTraits, Ovr>::sort (container &c) + { + typedef typename container_traits::value_traits_type vtraits; + typedef typename vtraits::less comparison; + std::sort (most_derived::begin(c), most_derived::end(c), comparison()); + } + + ///////////////////////////////////////////////////////////////////////// + // slice_helper factory function (default version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME default_algorithms<ContainerTraits, Ovr>::slice_helper + default_algorithms<ContainerTraits, Ovr> + ::make_slice_helper (container &c, slice const &sl) + { + return slice_helper (c, integer_slice (sl, most_derived::size (c))); + } + + ///////////////////////////////////////////////////////////////////////// + // Index into a container (associative version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME assoc_algorithms<ContainerTraits, Ovr>::reference + assoc_algorithms<ContainerTraits, Ovr>::get (container &c, index_param ix) + { + return *most_derived::find_or_throw (c, ix); + } + + ///////////////////////////////////////////////////////////////////////// + // Erase elements with the given key (associative version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + void + assoc_algorithms<ContainerTraits, Ovr>::erase_one( + container &c, key_param key) + { + if (c.erase (key) == 0) + { + PyErr_SetString( + PyExc_ValueError, "Container does not hold value to be erased"); + + boost::python::throw_error_already_set (); + } + } + + ///////////////////////////////////////////////////////////////////////// + // Find an element in an associative container + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME assoc_algorithms<ContainerTraits, Ovr>::iterator + assoc_algorithms<ContainerTraits, Ovr> + ::find (container &c, key_param key) + { + return c.find (key); + } + + ///////////////////////////////////////////////////////////////////////// + // Find an element in an associative container + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + bool + assoc_algorithms<ContainerTraits, Ovr>::contains( + container &c, key_param key) + { + return most_derived::find (c, key) != most_derived::end(c); + } + + ///////////////////////////////////////////////////////////////////////// + // Find an element in an associative container - throw an exception if + // not found + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME assoc_algorithms<ContainerTraits, Ovr>::iterator + assoc_algorithms<ContainerTraits, Ovr>::find_or_throw( + container &c, index_param ix) + { + iterator iter = most_derived::find (c, ix); + + if (iter == most_derived::end(c)) + { + PyErr_SetString( + PyExc_ValueError, "associative container: key not found"); + + boost::python::throw_error_already_set (); + } + + return iter; + } + + ///////////////////////////////////////////////////////////////////////// + // Count occurances of an element in a container (associative version) + ///////////////////////////////////////////////////////////////////////// + + template<typename ContainerTraits, typename Ovr> + BOOST_DEDUCED_TYPENAME assoc_algorithms<ContainerTraits, Ovr>::size_type + assoc_algorithms<ContainerTraits, Ovr>::count( + container &c, key_param key) + { + return c.count (key); + } + + ///////////////////////////////////////////////////////////////////////// + // Some meta-information to select algorithms for const and + // non-const qualified containers. All algorithms_selector specializations + // include two publically accessible typedefs, called + // mutable_algorithms and const_algorithms. This saves having to + // have separate partial specializations of algorithms for + // const and non-const containers. Client code should probably + // specialize algorithms directly. + ///////////////////////////////////////////////////////////////////////// + + namespace detail { + template<typename Container> class algorithms_selector +# if defined(BOOST_MPL_MSVC_ETI_BUG) + { + // Bogus types to prevent compile errors due to ETI + typedef algorithms_selector<Container> mutable_algorithms; + typedef algorithms_selector<Container> const_algorithms; + } +# endif + ; + } + + ///////////////////////////////////////////////////////////////////////// + // Algorithms selection for mutable containers + ///////////////////////////////////////////////////////////////////////// + + template<class Container> + struct algorithms + : public detail::algorithms_selector<Container>::mutable_algorithms + { + }; + +# if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + ///////////////////////////////////////////////////////////////////////// + // Algorithms selection for const-qualified containers + ///////////////////////////////////////////////////////////////////////// + + template<class Container> + struct algorithms<Container const> + : public detail::algorithms_selector<Container>::const_algorithms + { + }; +# endif +} } } + +#endif // BOOST_PYTHON_INDEXING_ALGORITHMS_HPP + + +""" Added: pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_proxy_header.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_proxy_header.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_proxy_header.py 2009-01-19 21:57:33 UTC (rev 1595) @@ -0,0 +1,752 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under 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) + +""" +This file contains indexing suite v2 code +""" + +file_name = "indexing_suite/container_proxy.hpp" + +code = """// 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) +// +// Header file container_proxy.hpp +// +// A container-wrapper that provides Python-style reference semantics +// for values stored in vector-like containers via element proxies. +// +// Class invariant: +// size() == m_proxies.size() +// for 0 <= i < size() +// m_proxies[i].get() != 0 +// m_proxies[i]->owner() == this +// m_proxies[i]->index() == i +// m_proxies[i]->m_element_ptr.get() == 0 +// +// History +// ======= +// 2003/ 8/26 rmg File creation +// 2003/10/23 rmg Change pointer container from map to sequence +// 2008/12/08 Roman Change indexing suite layout +// +// $Id: container_proxy.hpp,v 1.1.2.28 2004/02/08 18:57:42 raoulgough Exp $ +// + +#ifndef BOOST_PYTHON_INDEXING_CONTAINER_PROXY_HPP +#define BOOST_PYTHON_INDEXING_CONTAINER_PROXY_HPP + +#include <indexing_suite/proxy_iterator.hpp> +#include <indexing_suite/shared_proxy_impl.hpp> +#include <indexing_suite/element_proxy.hpp> +#include <indexing_suite/element_proxy_traits.hpp> +#include <indexing_suite/workaround.hpp> +#include <indexing_suite/methods.hpp> + +#include <vector> +#include <cassert> +#include <boost/shared_ptr.hpp> +#include <boost/mpl/apply.hpp> +#include <boost/iterator/iterator_traits.hpp> +#include <indexing_suite/container_traits.hpp> +#include <indexing_suite/container_suite.hpp> +#include <indexing_suite/algorithms.hpp> + +namespace boost { namespace python { namespace indexing { + + template<typename T> struct identity { + typedef T held_type; + + static T & get(T & obj) { return obj; } + static T const & get(T const & obj) { return obj; } + + static T create () { return T(); } + static T copy (T const ©) { return copy; } + static void assign (T &to, T const &from) { to = from; } + static void pre_destruction (T &) { } + static void swap (T &one, T &two) { std::swap (one, two); } + }; + + template<typename P> struct deref { + typedef P held_type; + + typedef typename boost::iterator_value<P>::type value; + + static value & get (P & ptr) { return *ptr; } + static value const & get (P const & ptr) { return *ptr; } + + static P create () { return P(); } + static P copy (P const ©) { return copy; } + static void assign (P &to, P const &from) { to = from; } + static void pre_destruction (P &) { } + static void swap (P &one, P &two) { std::swap (one, two); } + }; + + struct vector_generator { + // Generates vector type for any element type with default allocator + template<typename Element> struct apply { + typedef std::vector<Element> type; + }; + }; + +#if BOOST_WORKAROUND (BOOST_MSVC, == 1200) + // Early template instantiation (ETI) workaround + namespace detail { + template<typename Container> struct msvc6_iterator { + typedef Container::iterator type; + }; + + template<> struct msvc6_iterator<int> { + typedef int *type; + }; + } +#endif + + template<class Container, + class Holder = identity<Container>, + class Generator = vector_generator> + class container_proxy + { + typedef container_proxy<Container, Holder, Generator> self_type; + typedef typename Container::iterator raw_iterator; + typedef ::boost::detail::iterator_traits<raw_iterator> raw_iterator_traits; + +#if !defined (BOOST_NO_MEMBER_TEMPLATE_FRIENDS) + template<class C> friend class shared_proxy_impl; + template<class C, typename E, typename T, typename S, typename I> + friend class proxy_iterator; +#endif + + public: + typedef typename Holder::held_type held_type; + + typedef typename Container::size_type size_type; + typedef typename Container::difference_type difference_type; + + typedef shared_proxy_impl<self_type> shared_proxy; + + typedef typename Container::value_type raw_value_type; + + typedef element_proxy<self_type> value_type; + typedef value_type reference; // Already has ref. semantics + + typedef const_element_proxy<self_type> const_value_type; + typedef const_value_type const_reference; // Ref. semantics + + typedef proxy_iterator <self_type, value_type, raw_iterator_traits, + size_type, raw_iterator> iterator; + typedef iterator const_iterator; // No const_iterator yet implemented + + public: + // Constructors + template<typename Iter> container_proxy (Iter start, Iter finish) + // Define inline for MSVC6 compatibility + : m_held_obj (Holder::create()), + m_proxies () + { + insert (begin(), start, finish); + } + + container_proxy (); + explicit container_proxy (held_type const &h); + + container_proxy (container_proxy const &); + container_proxy &operator= (container_proxy const &); + ~container_proxy (); + + Container const &raw_container() const; // OK to expose const reference + + reference at (size_type index); + const_reference at (size_type index) const; + + reference operator[] (size_type index) { return at(index); } + const_reference operator[] (size_type index) const { return at(index); } + + size_type size () const { return raw_container().size(); } + size_type capacity () const { return raw_container().capacity(); } + void reserve (size_type s); + + public: + iterator begin() { return iterator (this, static_cast<size_type>(0)); } + iterator end() { return iterator (this, raw_container().size()); } + + iterator erase (iterator); + iterator erase (iterator, iterator); + iterator insert (iterator, raw_value_type const &); + + template<typename Iter> void insert (iterator iter, Iter from, Iter to) + // Define here for MSVC6 compatibility + { + // Forward insertion to the right overloaded version + typedef typename BOOST_ITERATOR_CATEGORY<Iter>::type category; + insert (iter, from, to, category()); + } + + void push_back (raw_value_type const ©) { insert (end(), copy); } + + value_type pop_back () { + value_type result = at (size() - 1); + erase (end() - 1); + return result; + } + + public: + // These functions are useful only when client code has direct + // non-const acccess to the raw container (e.g. via an indirect + // holder supplied to our constructor). Any code that directly + // modifies the contents of the raw container (by replacing, + // inserting or erasing elements) must notify the container_proxy. + + void detach_proxy (size_type index); + void detach_proxies (size_type from, size_type to); + // Call before overwriting element(s) in the raw container + + void prepare_erase (size_type from, size_type to); + // Call before erasing elements directly from the raw container + + void notify_insertion (size_type from, size_type to); + // Call after inserting elements directly into the raw container + + public: + // Convenient replacement of elements (automatic proxy detachment) + void replace (size_type index, raw_value_type const &); + // template<typename Iter> void replace (size_type index, Iter, Iter); + + void swap_elements (size_type index1, size_type index2); + + bool is_valid () const; // Check the class invariant (for testing purposes) + + private: + // Overloads for insertions with/without useful std::distance + template<typename Iter> + void insert (iterator iter, Iter from, Iter to, std::forward_iterator_tag) + // Define here for MSVC6 compatibility + { + assert (iter.ptr == this); + size_type count = std::distance (from, to); + + // Add empty proxy pointers for the new value(s) (could throw) + m_proxies.insert (m_proxies.begin() + iter.index, count, pointer_impl()); + + try + { + // Insert the new element(s) into the real container (could throw) + raw_container().insert( + raw_container().begin() + iter.index, + from, + to); + + try + { + // Create new proxies for the new elements (could throw) + write_proxies (iter.index, iter.index + count); + } + + catch (...) + { + raw_container().erase( + raw_container().begin() + iter.index, + raw_container().begin() + iter.index + count); + + throw; + } + } + + catch (...) + { + m_proxies.erase( + m_proxies.begin() + iter.index, + m_proxies.begin() + iter.index + count); + + throw; + } + + // Adjust any proxies after the inserted elements (nothrow) + adjust_proxies( + m_proxies.begin() + iter.index + count, + m_proxies.end(), + static_cast<difference_type> (count)); + } + + template<typename Iter> + void insert (iterator iter, Iter from, Iter to, std::input_iterator_tag) + // Define here for MSVC6 compatibility + { + // insert overload for iterators where we *can't* get distance() + // so just insert elements one at a time + while (from != to) + { + iter = insert (iter, *from++) + 1; + } + } + + private: + typedef boost::shared_ptr<shared_proxy> pointer_impl; + + typedef typename mpl::apply1<Generator, pointer_impl>::type + pointer_container; + +#if BOOST_WORKAROUND (BOOST_MSVC, == 1200) + typedef detail::msvc6_iterator<pointer_container>::type pointer_iterator; +#else + typedef typename pointer_container::iterator pointer_iterator; +#endif + +#if defined (BOOST_NO_MEMBER_TEMPLATE_FRIENDS) + // Proxies need mutable access, and can't be friends with MSVC6 + public: +#endif + Container &raw_container(); + + private: + void adjust_proxies (pointer_iterator, pointer_iterator, difference_type); + void write_proxies (size_type, size_type); + bool clear_proxy (pointer_impl &); // detach and do not reset + void clear_proxies (size_type, size_type); // detach and do not reset + void claim_all_proxies (); // Makes all proxies point at this object + + private: + held_type m_held_obj; + pointer_container m_proxies; + }; + + template<class Container, class Holder, class Generator> + container_proxy<Container, Holder, Generator> + ::container_proxy () + : m_held_obj (Holder::create()), + m_proxies () + { + // Container is empty - no further processing + } + + template<class Container, class Holder, class Generator> + container_proxy<Container, Holder, Generator> + ::container_proxy (held_type const &held) + : m_held_obj (Holder::copy (held)), + m_proxies (size()) + { + write_proxies (0, size()); + } + + template<class Container, class Holder, class Generator> + container_proxy<Container, Holder, Generator> + ::container_proxy (container_proxy const ©) + : m_held_obj (Holder::copy (copy.m_held_obj)), + m_proxies (size()) + { + write_proxies (0, size()); // Create our own proxies for the copied values + } + + template<class Container, class Holder, class Generator> + container_proxy<Container, Holder, Generator> & + container_proxy<Container, Holder, Generator> + ::operator= (container_proxy const ©) + { + container_proxy<Container, Holder, Generator> temp (copy); + // This could throw, but none of the remaining operations can + + Holder::swap (m_held_obj, temp.m_held_obj); + std::swap (m_proxies, temp.m_proxies); + + claim_all_proxies (); + temp.claim_all_proxies (); // Prepare for detach + + return *this; + // temp destruction detaches any proxies that used to belong to us + } + + template<class Container, class Holder, class Generator> + container_proxy<Container, Holder, Generator> + ::~container_proxy () + { + // Copy original values into any proxies being shared by external pointers + clear_proxies (0, size()); + Holder::pre_destruction (m_held_obj); + } + + template<class Container, class Holder, class Generator> + Container & + container_proxy<Container, Holder, Generator> + ::raw_container () + { + return Holder::get (m_held_obj); + } + + template<class Container, class Holder, class Generator> + Container const & + container_proxy<Container, Holder, Generator> + ::raw_container () const + { + return Holder::get (m_held_obj); + } + + template<class Container, class Holder, class Generator> + void container_proxy<Container, Holder, Generator>::reserve (size_type size) + { + raw_container().reserve (size); + m_proxies.reserve (size); + } + + template<class Container, class Holder, class Generator> + BOOST_DEDUCED_TYPENAME container_proxy<Container, Holder, Generator>::reference + container_proxy<Container, Holder, Generator> + ::at (size_type index) + { + pointer_impl const &ptr = m_proxies.BOOST_PYTHON_INDEXING_AT (index); + assert (ptr->owner() == this); + assert (ptr->index() == index); + return reference (ptr); + } + + template<class Container, class Holder, class Generator> + BOOST_DEDUCED_TYPENAME container_proxy<Container, Holder, Generator>::const_reference + container_proxy<Container, Holder, Generator> + ::at (size_type index) const + { + pointer_impl const &ptr = m_proxies.BOOST_PYTHON_INDEXING_AT (index); + assert (ptr->owner() == this); + assert (ptr->index() == index); + return const_reference (ptr); + } + + template<class Container, class Holder, class Generator> + void + container_proxy<Container, Holder, Generator> + ::replace (size_type index, raw_value_type const ©) + { + detach_proxy (index); + raw_container().BOOST_PYTHON_INDEXING_AT (index) = copy; + write_proxies (index, index + 1); + } + + template<class Container, class Holder, class Generator> + void + container_proxy<Container, Holder, Generator> + ::swap_elements (size_type index1, size_type index2) + { + pointer_impl &ptr1 = m_proxies[index1]; + pointer_impl &ptr2 = m_proxies[index2]; + + assert (ptr1->owner() == this); + assert (ptr2->owner() == this); + assert (ptr1->index() == index1); + assert (ptr2->index() == index2); + + // Swap produces the diagrammed transformation. Any external + // pointers that refer to proxy1 or proxy2 will end up still + // pointing to their original (now relocated) values. + // + // .. ptr1 .. ptr2 .. .. ptr1 .. ptr2 .. (m_proxies) + // | | \ / + // | | \/ + // | | /\. + // V V / \. + // proxy1 proxy2 --> proxy1 proxy2 + // | | \ / + // | | \/ + // | | /\. + // V V / \. + // .. v1 ... v2 .. .. v2 .. v1 .. (raw_container) + + std::swap (ptr1->m_index, ptr2->m_index); + std::swap (ptr1, ptr2); + std::swap (raw_container()[index1], raw_container()[index2]); + + assert (m_proxies[index1]->index() == index1); + assert (m_proxies[index2]->index() == index2); + } + + template<class Container, class Holder, class Generator> + BOOST_DEDUCED_TYPENAME container_proxy<Container, Holder, Generator>::iterator + container_proxy<Container, Holder, Generator>::erase (iterator iter) + { + return erase (iter, iter + 1); + } + + template<class Container, class Holder, class Generator> + BOOST_DEDUCED_TYPENAME container_proxy<Container, Holder, Generator>::iterator + container_proxy<Container, Holder, Generator>::erase( + iterator from, iterator to) + { + assert (from.ptr == this); + assert (to.ptr == this); + + // Detach and remove the proxies for the about-to-be-erased elements + prepare_erase (from.index, to.index); + + // Erase the elements from the real container + raw_iterator result + = raw_container().erase( + raw_container().begin() + from.index, + raw_container().begin() + to.index); + + return iterator (this, result); + } + + template<class Container, class Holder, class Generator> + BOOST_DEDUCED_TYPENAME container_proxy<Container, Holder, Generator>::iterator + container_proxy<Container, Holder, Generator>::insert( + iterator iter, raw_value_type const ©) + { + // Use the iterator-based version by treating the value as an + // array of size one (see section 5.7/4 of the C++98 standard) + insert (iter, ©, (©) + 1, std::random_access_iterator_tag()); + + return iter; + } + + template<class Container, class Holder, class Generator> + bool container_proxy<Container, Holder, Generator>::clear_proxy( + pointer_impl &ptr) + { + // Warning - this can break the class invariant. Use only when the + // pointer is about to be overwritten or removed from m_proxies + + assert (ptr->owner() == this); + + if (!ptr.unique()) + { + ptr->detach (); // Cause proxy to copy element value + return true; + } + + else + { + // If the pointer isn't shared, don't bother causing a copy of + // the container element, since the proxy is about to be + // deleted or reused. + return false; + } + } + + template<class Container, class Holder, class Generator> + void container_proxy<Container, Holder, Generator>::clear_proxies( + size_type from_index, size_type to_index) + { + while (from_index != to_index) + { + clear_proxy (m_proxies[from_index]); + ++from_index; + } + } + + template<class Container, class Holder, class Generator> + void container_proxy<Container, Holder, Generator> + ::detach_proxy (size_type index) + { + pointer_impl &ptr = m_proxies[index]; + + assert (ptr->index() == index); + + if (clear_proxy (ptr)) + { + // To maintain class invariant + ptr.reset (new shared_proxy (this, index)); + } + } + + template<class Container, class Holder, class Generator> + void container_proxy<Container, Holder, Generator>::detach_proxies( + size_type from_index, size_type to_index) + { + while (from_index != to_index) + { + detach_proxy (from_index); + ++from_index; + } + } + + template<class Container, class Holder, class Generator> + void container_proxy<Container, Holder, Generator> + ::prepare_erase (size_type from_index, size_type to_index) + { + difference_type deleting = to_index - from_index; + pointer_iterator erase_begin = m_proxies.begin() + from_index; + pointer_iterator erase_end = m_proxies.begin() + to_index; + + // Adjust the indexes of any trailing proxies + adjust_proxies (erase_end, m_proxies.end(), -deleting); + + // Detach any proxies without updating our pointers to them + clear_proxies (from_index, to_index); + + // Remove the pointers + m_proxies.erase (erase_begin, erase_end); + } + + template<class Container, class Holder, class Generator> + void container_proxy<Container, Holder, Generator>::notify_insertion( + size_type from_index, size_type to_index) + { + size_type count = to_index - from_index; + + m_proxies.insert( + m_proxies.begin() + from_index, count, pointer_impl()); + + try + { + write_proxies (from_index, to_index); // Could throw + } + + catch (...) + { + m_proxies.erase( + m_proxies.begin() + from_index, + m_proxies.begin() + to_index); + + throw; + } + + // Adjust any proxies after the inserted elements (nothrow) + adjust_proxies( + m_proxies.begin() + to_index, + m_proxies.end(), + static_cast<difference_type> (count)); + } + + template<class Container, class Holder, class Generator> + void container_proxy<Container, Holder, Generator>::adjust_proxies( + pointer_iterator from, + pointer_iterator to, + difference_type offset) + { + while (from != to) + { + (*from)->m_index += offset; + ++from; + } + } + + template<class Container, class Holder, class Generator> + void container_proxy<Container, Holder, Generator>::write_proxies( + size_type from, size_type to) + { + // (over)write proxy pointers in the given range. Re-uses existing + // shared_proxy objects where possible. Does not call detach_proxy + // since it is assumed that the original values could have already + // been modified and copying them now would be wrong. + + while (from != to) + { + pointer_impl &ptr = m_proxies[from]; + + if ((ptr.get() == 0) || (!ptr.unique())) + { + // Either no proxy yet allocated here, or there is one + // but it is being shared by an external pointer. + ptr.reset (new shared_proxy (this, from)); + } + + else + { + // Re-use the existing object since we have the only pointer to it + assert (ptr->owner() == this); + ptr->m_index = from; + } + + ++from; + } + } + + template<class Container, class Holder, class Generator> + void container_proxy<Container, Holder, Generator>::claim_all_proxies () + { + for (pointer_iterator iter = m_proxies.begin(); + iter != m_proxies.end(); + ++iter) + { + (*iter)->m_owner_ptr = this; + } + } + + template<class Container, class Holder, class Generator> + bool container_proxy<Container, Holder, Generator>::is_valid () const + { + bool ok = size() == m_proxies.size(); // Sizes must match + + for (size_type count = 0; ok && (count < size()); ++count) + { + pointer_impl const &ptr = m_proxies[count]; + + ok = ptr.get() && (ptr->owner() == this) && (ptr->index() == count) + && !ptr->m_element_ptr.get(); + } + + return ok; + } + + ///////////////////////////////////////////////////////////////////////// + // ContainerTraits implementation for container_proxy instances + ///////////////////////////////////////////////////////////////////////// + + template<typename Container> + struct container_proxy_traits : random_access_sequence_traits<Container> + { + typedef Container container; + typedef typename container::raw_value_type value_type; // insert, ... + typedef typename container::raw_value_type key_type; // find, count, ... + typedef typename container::reference reference; // return values + + typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <value_type>::param_type + value_param; + typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <key_type>::param_type + key_param; + +#if defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + // value_traits for the reference type (i.e. our element_proxy + // instance) supplies a custom visit_container_class. Compilers + // without partial specialization need help here. + + typedef element_proxy_traits<Container> value_traits_type; + + // Hide base class visit_container_class, which would call the + // unspecialized value_traits version + template<typename PythonClass, typename Policy> + static void visit_container_class( + PythonClass &pyClass, Policy const &policy) + { + value_traits_type::visit_container_class (pyClass, policy); + } +#endif + }; + +#if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + namespace detail { + /////////////////////////////////////////////////////////////////////// + // algorithms support for container_proxy instances + /////////////////////////////////////////////////////////////////////// + + template <typename RawContainer, typename Holder, typename Generator> + class algorithms_selector<container_proxy<RawContainer, Holder, Generator> > + { + typedef container_proxy<RawContainer, Holder, Generator> Container; + + typedef container_proxy_traits<Container> mutable_traits; + typedef container_proxy_traits<Container const> const_traits; + + public: + typedef default_algorithms<mutable_traits> mutable_algorithms; + typedef default_algorithms<const_traits> const_algorithms; + }; + } +#endif + template< + class Container, + method_set_type MethodMask = all_methods, + class Traits = container_proxy_traits<Container> + > + struct container_proxy_suite + : container_suite<Container, MethodMask, default_algorithms<Traits> > + { + }; + +} } } + +#endif // BOOST_PYTHON_INDEXING_CONTAINER_PROXY_HPP + + +""" Added: pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_suite_header.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_suite_header.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_suite_header.py 2009-01-19 21:57:33 UTC (rev 1595) @@ -0,0 +1,68 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under 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) + +""" +This file contains indexing suite v2 code +""" + +file_name = "indexing_suite/container_suite.hpp" + +code = """// 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) +// +// Header file container_suite.hpp +// +// Top-level interface to the container suite. +// +// History +// ======= +// 2003/ 8/23 rmg File creation +// 2003/ 9/ 8 rmg Extracted trait facilities into container_traits.hpp +// 2008/12/08 Roman Change indexing suite layout +// +// $Id: container_suite.hpp,v 1.1.2.7 2004/02/08 18:57:42 raoulgough Exp $ +// + +#ifndef BOOST_PYTHON_INDEXING_CONTAINER_SUITE_HPP +#define BOOST_PYTHON_INDEXING_CONTAINER_SUITE_HPP + +#include <indexing_suite/methods.hpp> +#include <indexing_suite/algorithms.hpp> +#include <indexing_suite/visitor.hpp> + +#include <boost/python/return_by_value.hpp> +#include <boost/python/return_value_policy.hpp> + +namespace boost { namespace python { namespace indexing { + typedef boost::python::return_value_policy<boost::python::return_by_value> + default_container_policies; + + template< + class Container, + method_set_type MethodMask = all_methods, // All supported by algorithms + class Algorithms + = algorithms<Container> + > + struct container_suite + : public visitor<Algorithms, default_container_policies, MethodMask> + { + typedef Algorithms algorithms; + + template<typename Policy> + static visitor<Algorithms, Policy, MethodMask> + with_policies (Policy const &policy) + { + return visitor <Algorithms, Policy, MethodMask> (policy); + } + }; +} } } + +#endif // BOOST_PYTHON_INDEXING_CONTAINER_SUITE_HPP + + +""" Added: pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_traits_header.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_traits_header.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_repository/indexing_suite/container_traits_header.py 2009-01-19 21:57:33 UTC (rev 1595) @@ -0,0 +1,174 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under 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) + +""" +This file contains indexing suite v2 code +""" + +file_name = "indexing_suite/container_traits.hpp" + +code = """// 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) +// +// Header file container_traits.hpp +// +// Traits information about entire containers for use in determining +// what Python methods to provide. +// +// History +// ======= +// 2003/ 8/23 rmg File creation as container_suite.hpp +// 2003/ 9/ 8 rmg Renamed container_traits.hpp +// 2003/10/28 rmg Split container-specific versions into separate headers +// 2004/ 1/28 rmg Convert to bitset-based feature selection +// 2008/12/08 Roman Change indexing suite layout +// +// $Id: container_traits.hpp,v 1.1.2.15 2004/02/08 18:57:42 raoulgough Exp $ +// + +#ifndef BOOST_PYTHON_INDEXING_CONTAINER_TRAITS_HPP +#define BOOST_PYTHON_INDEXING_CONTAINER_TRAITS_HPP + +#include <indexing_suite/suite_utils.hpp> +#include <indexing_suite/methods.hpp> +#include <indexing_suite/value_traits.hpp> + +#include <boost/type_traits.hpp> +#include <boost/call_traits.hpp> +#include <boost/mpl/if.hpp> +#include <boost/type_traits/ice.hpp> +#include <boost/iterator/iterator_traits.hpp> + +namespace boost { namespace python { namespace indexing { +#if BOOST_WORKAROUND (BOOST_MSVC, <= 1200) + // MSVC6 has problems with get_signature if parameter types have + // top-level const qualification (e.g. int const). Unfortunately, + // this is exactly what happens with boost::call_traits, so we + // substitute a really dumb version of it instead. + + template<typename T> struct broken_call_traits { + typedef T const & param_type; + }; +# define BOOST_PYTHON_INDEXING_CALL_TRAITS broken_cal... [truncated message content] |