sl@0: // Copyright David Abrahams 2002. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: #ifndef OBJECT_SLICES_DWA2002615_HPP sl@0: # define OBJECT_SLICES_DWA2002615_HPP sl@0: sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: namespace boost { namespace python { namespace api { sl@0: sl@0: struct const_slice_policies sl@0: { sl@0: typedef std::pair, handle<> > key_type; sl@0: static object get(object const& target, key_type const& key); sl@0: }; sl@0: sl@0: struct slice_policies : const_slice_policies sl@0: { sl@0: static object const& set(object const& target, key_type const& key, object const& value); sl@0: static void del(object const& target, key_type const& key); sl@0: }; sl@0: sl@0: // sl@0: // implementation sl@0: // sl@0: template sl@0: object_slice sl@0: object_operators::slice(object_cref start, object_cref finish) sl@0: { sl@0: object_cref2 x = *static_cast(this); sl@0: return object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr()))); sl@0: } sl@0: sl@0: template sl@0: const_object_slice sl@0: object_operators::slice(object_cref start, object_cref finish) const sl@0: { sl@0: object_cref2 x = *static_cast(this); sl@0: return const_object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr()))); sl@0: } sl@0: sl@0: template sl@0: object_slice sl@0: object_operators::slice(slice_nil, object_cref finish) sl@0: { sl@0: object_cref2 x = *static_cast(this); sl@0: return object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr()))); sl@0: } sl@0: sl@0: template sl@0: const_object_slice sl@0: object_operators::slice(slice_nil, object_cref finish) const sl@0: { sl@0: object_cref2 x = *static_cast(this); sl@0: return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr()))); sl@0: } sl@0: sl@0: template sl@0: object_slice sl@0: object_operators::slice(slice_nil, slice_nil) sl@0: { sl@0: object_cref2 x = *static_cast(this); sl@0: return object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0))); sl@0: } sl@0: sl@0: template sl@0: const_object_slice sl@0: object_operators::slice(slice_nil, slice_nil) const sl@0: { sl@0: object_cref2 x = *static_cast(this); sl@0: return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0))); sl@0: } sl@0: sl@0: template sl@0: object_slice sl@0: object_operators::slice(object_cref start, slice_nil) sl@0: { sl@0: object_cref2 x = *static_cast(this); sl@0: return object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0))); sl@0: } sl@0: sl@0: template sl@0: const_object_slice sl@0: object_operators::slice(object_cref start, slice_nil) const sl@0: { sl@0: object_cref2 x = *static_cast(this); sl@0: return const_object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0))); sl@0: } sl@0: # if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 sl@0: template sl@0: template sl@0: inline const_object_slice sl@0: object_operators::slice(T const& start, V const& end) const sl@0: { sl@0: return this->slice( sl@0: typename slice_bound::type(start) sl@0: , typename slice_bound::type(end)); sl@0: } sl@0: sl@0: template sl@0: template sl@0: inline object_slice sl@0: object_operators::slice(T const& start, V const& end) sl@0: { sl@0: return this->slice( sl@0: typename slice_bound::type(start) sl@0: , typename slice_bound::type(end)); sl@0: } sl@0: # endif sl@0: sl@0: sl@0: inline object const_slice_policies::get(object const& target, key_type const& key) sl@0: { sl@0: return getslice(target, key.first, key.second); sl@0: } sl@0: sl@0: inline object const& slice_policies::set( sl@0: object const& target sl@0: , key_type const& key sl@0: , object const& value) sl@0: { sl@0: setslice(target, key.first, key.second, value); sl@0: return value; sl@0: } sl@0: sl@0: inline void slice_policies::del( sl@0: object const& target sl@0: , key_type const& key) sl@0: { sl@0: delslice(target, key.first, key.second); sl@0: } sl@0: sl@0: }}} // namespace boost::python::api sl@0: sl@0: #endif // OBJECT_SLICES_DWA2002615_HPP