os/ossrv/ossrv_pub/boost_apis/boost/python/object_slices.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/object_slices.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,142 @@
     1.4 +// Copyright David Abrahams 2002.
     1.5 +// Distributed under the Boost Software License, Version 1.0. (See
     1.6 +// accompanying file LICENSE_1_0.txt or copy at
     1.7 +// http://www.boost.org/LICENSE_1_0.txt)
     1.8 +#ifndef OBJECT_SLICES_DWA2002615_HPP
     1.9 +# define OBJECT_SLICES_DWA2002615_HPP
    1.10 +
    1.11 +# include <boost/python/detail/prefix.hpp>
    1.12 +
    1.13 +# include <boost/python/proxy.hpp>
    1.14 +# include <boost/python/object_core.hpp>
    1.15 +# include <boost/python/object_protocol.hpp>
    1.16 +# include <boost/python/handle.hpp>
    1.17 +# include <utility>
    1.18 +
    1.19 +namespace boost { namespace python { namespace api {
    1.20 +
    1.21 +struct const_slice_policies
    1.22 +{
    1.23 +    typedef std::pair<handle<>, handle<> > key_type;
    1.24 +    static object get(object const& target, key_type const& key);
    1.25 +};
    1.26 +  
    1.27 +struct slice_policies : const_slice_policies
    1.28 +{
    1.29 +    static object const& set(object const& target, key_type const& key, object const& value);
    1.30 +    static void del(object const& target, key_type const& key);
    1.31 +};
    1.32 +
    1.33 +//
    1.34 +// implementation
    1.35 +//
    1.36 +template <class U>
    1.37 +object_slice
    1.38 +object_operators<U>::slice(object_cref start, object_cref finish)
    1.39 +{
    1.40 +    object_cref2 x = *static_cast<U*>(this);
    1.41 +    return object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
    1.42 +}
    1.43 +
    1.44 +template <class U>
    1.45 +const_object_slice
    1.46 +object_operators<U>::slice(object_cref start, object_cref finish) const
    1.47 +{
    1.48 +    object_cref2 x = *static_cast<U const*>(this);
    1.49 +    return const_object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
    1.50 +}
    1.51 +
    1.52 +template <class U>
    1.53 +object_slice
    1.54 +object_operators<U>::slice(slice_nil, object_cref finish)
    1.55 +{
    1.56 +    object_cref2 x = *static_cast<U*>(this);
    1.57 +    return object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
    1.58 +}
    1.59 +
    1.60 +template <class U>
    1.61 +const_object_slice
    1.62 +object_operators<U>::slice(slice_nil, object_cref finish) const
    1.63 +{
    1.64 +    object_cref2 x = *static_cast<U const*>(this);
    1.65 +    return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
    1.66 +}
    1.67 +
    1.68 +template <class U>
    1.69 +object_slice
    1.70 +object_operators<U>::slice(slice_nil, slice_nil)
    1.71 +{
    1.72 +    object_cref2 x = *static_cast<U*>(this);
    1.73 +    return object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
    1.74 +}
    1.75 +
    1.76 +template <class U>
    1.77 +const_object_slice
    1.78 +object_operators<U>::slice(slice_nil, slice_nil) const
    1.79 +{
    1.80 +    object_cref2 x = *static_cast<U const*>(this);
    1.81 +    return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
    1.82 +}
    1.83 +
    1.84 +template <class U>
    1.85 +object_slice
    1.86 +object_operators<U>::slice(object_cref start, slice_nil)
    1.87 +{
    1.88 +    object_cref2 x = *static_cast<U*>(this);
    1.89 +    return object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
    1.90 +}
    1.91 +
    1.92 +template <class U>
    1.93 +const_object_slice
    1.94 +object_operators<U>::slice(object_cref start, slice_nil) const
    1.95 +{
    1.96 +    object_cref2 x = *static_cast<U const*>(this);
    1.97 +    return const_object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
    1.98 +}
    1.99 +# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
   1.100 +template <class U>
   1.101 +template <class T, class V>
   1.102 +inline const_object_slice
   1.103 +object_operators<U>::slice(T const& start, V const& end) const
   1.104 +{
   1.105 +    return this->slice(
   1.106 +        typename slice_bound<T>::type(start)
   1.107 +        , typename slice_bound<V>::type(end));
   1.108 +}
   1.109 +
   1.110 +template <class U>
   1.111 +template <class T, class V>
   1.112 +inline object_slice
   1.113 +object_operators<U>::slice(T const& start, V const& end)
   1.114 +{
   1.115 +    return this->slice(
   1.116 +        typename slice_bound<T>::type(start)
   1.117 +        , typename slice_bound<V>::type(end));
   1.118 +}
   1.119 +# endif 
   1.120 +
   1.121 +
   1.122 +inline object const_slice_policies::get(object const& target, key_type const& key)
   1.123 +{
   1.124 +    return getslice(target, key.first, key.second);
   1.125 +}
   1.126 +
   1.127 +inline object const& slice_policies::set(
   1.128 +    object const& target
   1.129 +    , key_type const& key
   1.130 +    , object const& value)
   1.131 +{
   1.132 +    setslice(target, key.first, key.second, value);
   1.133 +    return value;
   1.134 +}
   1.135 +
   1.136 +inline void slice_policies::del(
   1.137 +    object const& target
   1.138 +    , key_type const& key)
   1.139 +{
   1.140 +    delslice(target, key.first, key.second);
   1.141 +}
   1.142 +
   1.143 +}}} // namespace boost::python::api
   1.144 +
   1.145 +#endif // OBJECT_SLICES_DWA2002615_HPP