os/ossrv/ossrv_pub/boost_apis/boost/python/object_items.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright David Abrahams 2002.
sl@0
     2
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     3
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     4
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
#ifndef OBJECT_ITEMS_DWA2002615_HPP
sl@0
     6
# define OBJECT_ITEMS_DWA2002615_HPP
sl@0
     7
sl@0
     8
# include <boost/python/detail/prefix.hpp>
sl@0
     9
sl@0
    10
# include <boost/python/proxy.hpp>
sl@0
    11
# include <boost/python/object_core.hpp>
sl@0
    12
# include <boost/python/object_protocol.hpp>
sl@0
    13
sl@0
    14
namespace boost { namespace python { namespace api {
sl@0
    15
sl@0
    16
struct const_item_policies
sl@0
    17
{
sl@0
    18
    typedef object key_type;
sl@0
    19
    static object get(object const& target, object const& key);
sl@0
    20
};
sl@0
    21
  
sl@0
    22
struct item_policies : const_item_policies
sl@0
    23
{
sl@0
    24
    static object const& set(object const& target, object const& key, object const& value);
sl@0
    25
    static void del(object const& target, object const& key);
sl@0
    26
};
sl@0
    27
sl@0
    28
//
sl@0
    29
// implementation
sl@0
    30
//
sl@0
    31
template <class U>
sl@0
    32
inline object_item
sl@0
    33
object_operators<U>::operator[](object_cref key)
sl@0
    34
{
sl@0
    35
    object_cref2 x = *static_cast<U*>(this);
sl@0
    36
    return object_item(x, key);
sl@0
    37
}
sl@0
    38
sl@0
    39
template <class U>
sl@0
    40
inline const_object_item
sl@0
    41
object_operators<U>::operator[](object_cref key) const
sl@0
    42
{
sl@0
    43
    object_cref2 x = *static_cast<U const*>(this);
sl@0
    44
    return const_object_item(x, key);
sl@0
    45
}
sl@0
    46
sl@0
    47
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
sl@0
    48
template <class U>
sl@0
    49
template <class T>
sl@0
    50
inline const_object_item
sl@0
    51
object_operators<U>::operator[](T const& key) const
sl@0
    52
{
sl@0
    53
    return (*this)[object(key)];
sl@0
    54
}
sl@0
    55
sl@0
    56
template <class U>
sl@0
    57
template <class T>
sl@0
    58
inline object_item
sl@0
    59
object_operators<U>::operator[](T const& key)
sl@0
    60
{
sl@0
    61
    return (*this)[object(key)];
sl@0
    62
}
sl@0
    63
# endif 
sl@0
    64
sl@0
    65
sl@0
    66
inline object const_item_policies::get(object const& target, object const& key)
sl@0
    67
{
sl@0
    68
    return getitem(target, key);
sl@0
    69
}
sl@0
    70
sl@0
    71
inline object const& item_policies::set(
sl@0
    72
    object const& target
sl@0
    73
    , object const& key
sl@0
    74
    , object const& value)
sl@0
    75
{
sl@0
    76
    setitem(target, key, value);
sl@0
    77
    return value;
sl@0
    78
}
sl@0
    79
sl@0
    80
inline void item_policies::del(
sl@0
    81
    object const& target
sl@0
    82
    , object const& key)
sl@0
    83
{
sl@0
    84
    delitem(target, key);
sl@0
    85
}
sl@0
    86
sl@0
    87
}}} // namespace boost::python::api
sl@0
    88
sl@0
    89
#endif // OBJECT_ITEMS_DWA2002615_HPP